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