From d4c1d2ece450af7a857c3075607652448b951a7e Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 22 Jan 2023 19:52:11 -0500 Subject: [PATCH] Handle expired shares --- core/share.go | 3 +++ server/public/handle_shares.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/share.go b/core/share.go index 883160dfc..222be3526 100644 --- a/core/share.go +++ b/core/share.go @@ -36,6 +36,9 @@ func (s *shareService) Load(ctx context.Context, id string) (*model.Share, error return nil, err } share := entity.(*model.Share) + if !share.ExpiresAt.IsZero() && share.ExpiresAt.Before(time.Now()) { + return nil, model.ErrNotAvailable + } share.LastVisitedAt = time.Now() share.VisitCount++ diff --git a/server/public/handle_shares.go b/server/public/handle_shares.go index 0b74bd8bc..add6e29ad 100644 --- a/server/public/handle_shares.go +++ b/server/public/handle_shares.go @@ -27,6 +27,9 @@ func (p *Router) handleShares(w http.ResponseWriter, r *http.Request) { // If it is not, consider it a share ID s, err := p.share.Load(r.Context(), id) switch { + case errors.Is(err, model.ErrNotAvailable): + log.Error(r, "Share expired", "id", id, err) + http.Error(w, "Share not available anymore", http.StatusGone) case errors.Is(err, model.ErrNotFound): log.Error(r, "Share not found", "id", id, err) http.Error(w, "Share not found", http.StatusNotFound)