fix: save recipe images to recipe-images/ subdirectory
Build and Deploy / build-and-deploy (push) Successful in 1m49s
Build and Deploy / build-and-deploy (push) Successful in 1m49s
Previously images were saved directly in the recipe directory alongside .cook files. Now they go into <recipes-dir>/recipe-images/, keeping the recipe directory clean and making the purpose of the file clear from its path.
This commit is contained in:
+5
-2
@@ -678,10 +678,13 @@ uploadImageHandler recipeDir _state request respond =
|
|||||||
(\c -> if isAlphaNum c || c == '.' || c == '-' || c == '_' then c else '_')
|
(\c -> if isAlphaNum c || c == '.' || c == '-' || c == '_' then c else '_')
|
||||||
(T.unpack basename <> if null ext then ".jpg" else ext)
|
(T.unpack basename <> if null ext then ".jpg" else ext)
|
||||||
imageFilename = T.pack safeName
|
imageFilename = T.pack safeName
|
||||||
filepath = recipeDir </> safeName
|
imagesDir = recipeDir </> "recipe-images"
|
||||||
|
filepath = imagesDir </> safeName
|
||||||
case decode (TE.encodeUtf8 fileB64) of
|
case decode (TE.encodeUtf8 fileB64) of
|
||||||
Left err -> respond (jsonError ("Base64 decode failed: " <> T.pack err))
|
Left err -> respond (jsonError ("Base64 decode failed: " <> T.pack err))
|
||||||
Right content -> do
|
Right content -> do
|
||||||
|
-- Ensure the recipe-images directory exists
|
||||||
|
createDirectoryIfMissing True imagesDir
|
||||||
-- Save the image file
|
-- Save the image file
|
||||||
BS.writeFile filepath content
|
BS.writeFile filepath content
|
||||||
putStrLn $ "[roux] saved recipe image to " <> filepath
|
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"]
|
if ext `notElem` [".jpg", ".jpeg", ".png", ".gif", ".webp"]
|
||||||
then respond notFound
|
then respond notFound
|
||||||
else do
|
else do
|
||||||
let filepath = recipeDir </> filename
|
let filepath = recipeDir </> "recipe-images" </> filename
|
||||||
exists <- doesFileExist filepath
|
exists <- doesFileExist filepath
|
||||||
if not exists
|
if not exists
|
||||||
then respond notFound
|
then respond notFound
|
||||||
|
|||||||
Reference in New Issue
Block a user