mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-05 18:03:10 +03:00
Handle expired shares
This commit is contained in:
parent
d0dceae094
commit
d4c1d2ece4
@ -36,6 +36,9 @@ func (s *shareService) Load(ctx context.Context, id string) (*model.Share, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
share := entity.(*model.Share)
|
share := entity.(*model.Share)
|
||||||
|
if !share.ExpiresAt.IsZero() && share.ExpiresAt.Before(time.Now()) {
|
||||||
|
return nil, model.ErrNotAvailable
|
||||||
|
}
|
||||||
share.LastVisitedAt = time.Now()
|
share.LastVisitedAt = time.Now()
|
||||||
share.VisitCount++
|
share.VisitCount++
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@ func (p *Router) handleShares(w http.ResponseWriter, r *http.Request) {
|
|||||||
// If it is not, consider it a share ID
|
// If it is not, consider it a share ID
|
||||||
s, err := p.share.Load(r.Context(), id)
|
s, err := p.share.Load(r.Context(), id)
|
||||||
switch {
|
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):
|
case errors.Is(err, model.ErrNotFound):
|
||||||
log.Error(r, "Share not found", "id", id, err)
|
log.Error(r, "Share not found", "id", id, err)
|
||||||
http.Error(w, "Share not found", http.StatusNotFound)
|
http.Error(w, "Share not found", http.StatusNotFound)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user