fix: don't wait for thumbnail generation if already cached

This commit is contained in:
Louis Dalibard 2024-06-10 22:21:27 +02:00
parent e7e819ff5c
commit 28d526ab74
2 changed files with 4 additions and 5 deletions

View File

@ -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!")
}

View File

@ -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) {