From d64129fc9f18f9e6d29c75dddda5d688aaa745f9 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Thu, 21 May 2026 21:06:07 -0400 Subject: [PATCH] fix: save recipe images to recipe-images/ subdirectory Previously images were saved directly in the recipe directory alongside .cook files. Now they go into /recipe-images/, keeping the recipe directory clean and making the purpose of the file clear from its path. --- src/Roux/Server.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Roux/Server.hs b/src/Roux/Server.hs index a5118ee..3ef78e7 100644 --- a/src/Roux/Server.hs +++ b/src/Roux/Server.hs @@ -678,10 +678,13 @@ uploadImageHandler recipeDir _state request respond = (\c -> if isAlphaNum c || c == '.' || c == '-' || c == '_' then c else '_') (T.unpack basename <> if null ext then ".jpg" else ext) imageFilename = T.pack safeName - filepath = recipeDir safeName + imagesDir = recipeDir "recipe-images" + filepath = imagesDir safeName case decode (TE.encodeUtf8 fileB64) of Left err -> respond (jsonError ("Base64 decode failed: " <> T.pack err)) Right content -> do + -- Ensure the recipe-images directory exists + createDirectoryIfMissing True imagesDir -- Save the image file BS.writeFile filepath content putStrLn $ "[roux] saved recipe image to " <> filepath @@ -705,7 +708,7 @@ serveRecipeImage recipeDir filename _request respond = do if ext `notElem` [".jpg", ".jpeg", ".png", ".gif", ".webp"] then respond notFound else do - let filepath = recipeDir filename + let filepath = recipeDir "recipe-images" filename exists <- doesFileExist filepath if not exists then respond notFound