Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. package metajson
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "time"
  6. "github.com/andreimarcu/linx-server/backends"
  7. )
  8. type MetadataJSON struct {
  9. DeleteKey string `json:"delete_key"`
  10. Sha256sum string `json:"sha256sum"`
  11. Mimetype string `json:"mimetype"`
  12. Size int64 `json:"size"`
  13. Expiry int64 `json:"expiry"`
  14. ArchiveFiles []string `json:"archive_files,omitempty"`
  15. }
  16. type MetaJSONBackend struct {
  17. storage backends.MetaStorageBackend
  18. }
  19. func (m MetaJSONBackend) Put(key string, metadata *backends.Metadata) error {
  20. mjson := MetadataJSON{}
  21. mjson.DeleteKey = metadata.DeleteKey
  22. mjson.Mimetype = metadata.Mimetype
  23. mjson.ArchiveFiles = metadata.ArchiveFiles
  24. mjson.Sha256sum = metadata.Sha256sum
  25. mjson.Expiry = metadata.Expiry.Unix()
  26. mjson.Size = metadata.Size
  27. byt, err := json.Marshal(mjson)
  28. if err != nil {
  29. return err
  30. }
  31. if _, err := m.storage.Put(key, bytes.NewBuffer(byt)); err != nil {
  32. return err
  33. }
  34. return nil
  35. }
  36. func (m MetaJSONBackend) Get(key string) (metadata backends.Metadata, err error) {
  37. b, err := m.storage.Get(key)
  38. if err != nil {
  39. return metadata, backends.BadMetadata
  40. }
  41. mjson := MetadataJSON{}
  42. err = json.Unmarshal(b, &mjson)
  43. if err != nil {
  44. return metadata, backends.BadMetadata
  45. }
  46. metadata.DeleteKey = mjson.DeleteKey
  47. metadata.Mimetype = mjson.Mimetype
  48. metadata.ArchiveFiles = mjson.ArchiveFiles
  49. metadata.Sha256sum = mjson.Sha256sum
  50. metadata.Expiry = time.Unix(mjson.Expiry, 0)
  51. metadata.Size = mjson.Size
  52. return
  53. }
  54. func NewMetaJSONBackend(storage backends.MetaStorageBackend) MetaJSONBackend {
  55. return MetaJSONBackend{storage: storage}
  56. }