fix: don't wait for thumbnail generation if already cached
This commit is contained in:
parent
e7e819ff5c
commit
28d526ab74
@ -109,7 +109,7 @@ func HandleThumb(c *fiber.Ctx) error {
|
||||
}
|
||||
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
||||
pathSlice := strings.Split(req, "/")
|
||||
pathSlice = pathSlice[1:len(pathSlice)]
|
||||
pathSlice = pathSlice[1:]
|
||||
pathBase, ok := config.Config.ServeDirs[pathSlice[0]]
|
||||
if ok {
|
||||
pathSlice[0] = pathBase
|
||||
@ -121,12 +121,12 @@ func HandleThumb(c *fiber.Ctx) error {
|
||||
thumbnail.GetThumbnail(c, completePath)
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
return c.Status(fiber.StatusNotFound).SendString("Sorry can't find that!")
|
||||
} else {
|
||||
} /* else {
|
||||
// Schrodinger: file may or may not exist. See err for details.
|
||||
|
||||
// Therefore, do *NOT* use !os.IsNotExist(err) to test for file existence
|
||||
|
||||
}
|
||||
} */
|
||||
} else {
|
||||
return c.Status(fiber.StatusNotFound).SendString("Sorry can't find that!")
|
||||
}
|
||||
|
@ -63,16 +63,15 @@ func Free() {
|
||||
}
|
||||
|
||||
func GetThumbnail(c *fiber.Ctx, completePath string) {
|
||||
WaitForAvailable()
|
||||
c.Set(fiber.HeaderContentType, "image")
|
||||
thumbnailCacheMutex.RLock()
|
||||
bytesThumb, ok := thumbnailCache[completePath]
|
||||
thumbnailCacheMutex.RUnlock()
|
||||
if ok {
|
||||
c.Write(bytesThumb)
|
||||
Free()
|
||||
return
|
||||
}
|
||||
WaitForAvailable()
|
||||
|
||||
fileExt := filepath.Ext(completePath)
|
||||
if !slices.Contains(SupportedFileTypes, fileExt) {
|
||||
|
Loading…
Reference in New Issue
Block a user