更新缩略图

This commit is contained in:
2026-07-03 00:15:41 +08:00
parent 7bb0531c4b
commit 273892f98f
15 changed files with 416 additions and 61 deletions
+18 -1
View File
@@ -38,7 +38,16 @@ func (h *ImageHandler) Serve(c *gin.Context) {
return
}
public, err := h.imageAccess.IsPublic(c.Request.Context(), rel)
// A thumbnail shares its original's visibility, and old images without a
// stored thumb fall back to the original object.
origRel := rel
if service.IsThumbKey(rel) {
origRel = service.OrigKey(rel)
} else if service.IsLastFrameKey(rel) {
origRel = service.LastFrameOrigKey(rel)
}
public, err := h.imageAccess.IsPublic(c.Request.Context(), origRel)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to authorize image"})
return
@@ -65,6 +74,14 @@ func (h *ImageHandler) Serve(c *gin.Context) {
c.JSON(http.StatusBadGateway, gin.H{"detail": "failed to fetch object"})
return
}
if resp.StatusCode == http.StatusNotFound && origRel != rel {
resp.Body.Close()
resp, err = h.store.Get(c.Request.Context(), origRel, c.GetHeader("Range"))
if err != nil {
c.JSON(http.StatusBadGateway, gin.H{"detail": "failed to fetch object"})
return
}
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
c.JSON(http.StatusNotFound, gin.H{"detail": "not found"})