Skip to content

🎧 Your Personal Streaming Service

Handle expired shares

Deluand4c1d2ece450
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)