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.

69 lines
1.4 KiB

  1. package main
  2. import (
  3. "time"
  4. "github.com/andreimarcu/linx-server/expiry"
  5. "github.com/dustin/go-humanize"
  6. )
  7. var defaultExpiryList = []uint64{
  8. 60,
  9. 300,
  10. 3600,
  11. 86400,
  12. 604800,
  13. 2419200,
  14. 31536000,
  15. }
  16. type ExpirationTime struct {
  17. Seconds uint64
  18. Human string
  19. }
  20. // Determine if the given filename is expired
  21. func isFileExpired(filename string) (bool, error) {
  22. metadata, err := storageBackend.Head(filename)
  23. if err != nil {
  24. return false, err
  25. }
  26. return expiry.IsTsExpired(metadata.Expiry), nil
  27. }
  28. // Return a list of expiration times and their humanized versions
  29. func listExpirationTimes() []ExpirationTime {
  30. epoch := time.Now()
  31. actualExpiryInList := false
  32. var expiryList []ExpirationTime
  33. for _, expiryEntry := range defaultExpiryList {
  34. if Config.maxExpiry == 0 || expiryEntry <= Config.maxExpiry {
  35. if expiryEntry == Config.maxExpiry {
  36. actualExpiryInList = true
  37. }
  38. duration := time.Duration(expiryEntry) * time.Second
  39. expiryList = append(expiryList, ExpirationTime{
  40. Seconds: expiryEntry,
  41. Human: humanize.RelTime(epoch, epoch.Add(duration), "", ""),
  42. })
  43. }
  44. }
  45. if Config.maxExpiry == 0 {
  46. expiryList = append(expiryList, ExpirationTime{
  47. 0,
  48. "never",
  49. })
  50. } else if actualExpiryInList == false {
  51. duration := time.Duration(Config.maxExpiry) * time.Second
  52. expiryList = append(expiryList, ExpirationTime{
  53. Config.maxExpiry,
  54. humanize.RelTime(epoch, epoch.Add(duration), "", ""),
  55. })
  56. }
  57. return expiryList
  58. }