Skip to content

Commit

Permalink
ensure databases lacking file_expiration_time values report correct v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
Balk-Z committed Dec 7, 2024
1 parent 4bfd557 commit cedfbf4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion handlers/parse/guest_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GuestLinkLabel(label string) (picoshare.GuestLinkLabel, error) {
}

func GuestFileLifeTime(fileLifeTimeRaw string) (picoshare.FileLifetime, error) {
t, err := time.Parse(expirationTimeFormat, fileLifeTimeRaw) //do the error handling
t, err := time.Parse(expirationTimeFormat, fileLifeTimeRaw)
if err != nil {
return picoshare.FileLifetime{}, ErrExpirationUnrecognizedFormat
}
Expand Down
6 changes: 5 additions & 1 deletion handlers/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func (s Server) guestLinkIndexGet() http.HandlerFunc {
return "Never"
}

return fmt.Sprintf("After %.0f hours", flt.Duration().Hours())
letterS := "s"
if flt.Duration().Hours() < 25 {
letterS = ""
}
return fmt.Sprintf("After %.0f day%s", math.Abs(flt.Duration().Hours()/24), letterS)
},
"isActive": func(gl picoshare.GuestLink) bool {
return gl.IsActive()
Expand Down
4 changes: 2 additions & 2 deletions store/sqlite/guest_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s Store) GetGuestLink(id picoshare.GuestLinkID) (picoshare.GuestLink, erro
guest_links.max_file_uploads AS max_file_uploads,
guest_links.creation_time AS creation_time,
guest_links.url_expiration_time AS url_expiration_time,
guest_links.file_expiration_time AS file_expiration_time,
CASE WHEN guest_links.file_expiration_time IS NULL THEN 'NULL' ELSE guest_links.file_expiration_time END AS file_expiration_time,
SUM(CASE WHEN entries.id IS NOT NULL THEN 1 ELSE 0 END) AS entry_count
FROM
guest_links
Expand All @@ -42,7 +42,7 @@ func (s Store) GetGuestLinks() ([]picoshare.GuestLink, error) {
guest_links.max_file_uploads AS max_file_uploads,
guest_links.creation_time AS creation_time,
guest_links.url_expiration_time AS url_expiration_time,
guest_links.file_expiration_time AS file_expiration_time,
CASE WHEN guest_links.file_expiration_time IS NULL THEN 'NULL' ELSE guest_links.file_expiration_time END AS file_expiration_time,
SUM(CASE WHEN entries.id IS NOT NULL THEN 1 ELSE 0 END) AS entry_count
FROM
guest_links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ RENAME COLUMN expiration_time TO url_expiration_time;

ALTER TABLE guest_links
ADD file_expiration_time TEXT;

UPDATE guest_links
SET file_expiration_time = 'NEVER'
WHERE file_expiration_time IS NULL;
3 changes: 3 additions & 0 deletions store/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func formatTime(t time.Time) string {
}

func parseFileDatetime(s string) (time.Duration, error) {
if s == "NULL" {
return picoshare.FileLifetimeInfinite.Duration(), nil
}
return time.ParseDuration(fmt.Sprintf("%sh", s))
}

Expand Down

0 comments on commit cedfbf4

Please sign in to comment.