From 28d526ab74fcb0f07ee5bd2652f85b743fdaeed2 Mon Sep 17 00:00:00 2001 From: Louis Dalibard Date: Mon, 10 Jun 2024 22:21:27 +0200 Subject: [PATCH] fix: don't wait for thumbnail generation if already cached --- route/route.go | 6 +++--- thumbnail/thumbnail.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/route/route.go b/route/route.go index ec5014e..af32439 100644 --- a/route/route.go +++ b/route/route.go @@ -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!") } diff --git a/thumbnail/thumbnail.go b/thumbnail/thumbnail.go index 3f2c7a0..b5e5379 100644 --- a/thumbnail/thumbnail.go +++ b/thumbnail/thumbnail.go @@ -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) {