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.

73 lines
1.7 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. ShortURL string `json:"short_url"`
  16. }
  17. type MetaJSONBackend struct {
  18. storage backends.MetaStorageBackend
  19. }
  20. func (m MetaJSONBackend) Put(key string, metadata *backends.Metadata) error {
  21. mjson := MetadataJSON{}
  22. mjson.DeleteKey = metadata.DeleteKey
  23. mjson.Mimetype = metadata.Mimetype
  24. mjson.ArchiveFiles = metadata.ArchiveFiles
  25. mjson.Sha256sum = metadata.Sha256sum
  26. mjson.Expiry = metadata.Expiry.Unix()
  27. mjson.Size = metadata.Size
  28. mjson.ShortURL = metadata.ShortURL
  29. byt, err := json.Marshal(mjson)
  30. if err != nil {
  31. return err
  32. }
  33. if _, err := m.storage.Put(key, bytes.NewBuffer(byt)); err != nil {
  34. return err
  35. }
  36. return nil
  37. }
  38. func (m MetaJSONBackend) Get(key string) (metadata backends.Metadata, err error) {
  39. b, err := m.storage.Get(key)
  40. if err != nil {
  41. return metadata, backends.BadMetadata
  42. }
  43. mjson := MetadataJSON{}
  44. err = json.Unmarshal(b, &mjson)
  45. if err != nil {
  46. return metadata, backends.BadMetadata
  47. }
  48. metadata.DeleteKey = mjson.DeleteKey
  49. metadata.Mimetype = mjson.Mimetype
  50. metadata.ArchiveFiles = mjson.ArchiveFiles
  51. metadata.Sha256sum = mjson.Sha256sum
  52. metadata.Expiry = time.Unix(mjson.Expiry, 0)
  53. metadata.Size = mjson.Size
  54. metadata.ShortURL = mjson.ShortURL
  55. return
  56. }
  57. func NewMetaJSONBackend(storage backends.MetaStorageBackend) MetaJSONBackend {
  58. return MetaJSONBackend{storage: storage}
  59. }