fix: normalize recipe filenames in cook-log (strip .cork ext, lowercase); also fetch with .cork fallback for legacy entries
Build and Deploy / build-and-deploy (push) Failing after 1m25s
Build and Deploy / build-and-deploy (push) Failing after 1m25s
This commit is contained in:
+11
-2
@@ -106,13 +106,22 @@ insertEntry conn filename day mComment = do
|
||||
fromMaybe _ (Just x) = x
|
||||
|
||||
-- | Fetch all entries for a given recipe, newest first.
|
||||
-- Tries both the normalized key and with @.cook@ appended (for legacy entries).
|
||||
fetchEntries :: Connection -> Text -> IO [CookEntry]
|
||||
fetchEntries conn filename =
|
||||
SQL.query
|
||||
fetchEntries conn filename = do
|
||||
entries <- SQL.query
|
||||
conn
|
||||
"SELECT id, recipe_filename, cooked_date, comment, created_at \
|
||||
\ FROM cook_log WHERE recipe_filename = ? ORDER BY cooked_date DESC, id DESC"
|
||||
(Only filename)
|
||||
if null entries
|
||||
then
|
||||
SQL.query
|
||||
conn
|
||||
"SELECT id, recipe_filename, cooked_date, comment, created_at \
|
||||
\ FROM cook_log WHERE recipe_filename = ? ORDER BY cooked_date DESC, id DESC"
|
||||
(Only (filename <> ".cook"))
|
||||
else pure entries
|
||||
|
||||
-- | Fetch all entries across all recipes, newest first.
|
||||
fetchAllEntries :: Connection -> IO [CookEntry]
|
||||
|
||||
+8
-2
@@ -643,7 +643,7 @@ handleRequest state db request respond = do
|
||||
Nothing -> respond notFound
|
||||
-- Cook log JSON endpoint for a specific recipe
|
||||
["cook-log", filename] -> do
|
||||
entries <- CookLog.fetchEntries db filename
|
||||
entries <- CookLog.fetchEntries db (normalizeRecipeKey filename)
|
||||
let body = A.encode entries
|
||||
respond $
|
||||
Wai.responseLBS
|
||||
@@ -666,8 +666,14 @@ handleRequest state db request respond = do
|
||||
_ -> respond notFound
|
||||
|
||||
-- | Handle POST /cook-log/{filename}
|
||||
-- | Normalize a recipe filename to match the recipe index key:
|
||||
-- lowercased, with @.cook@ extension stripped.
|
||||
normalizeRecipeKey :: Text -> Text
|
||||
normalizeRecipeKey = T.pack . map toLower . stripCookExt . T.unpack
|
||||
|
||||
handleCookLogPost :: SQL.Connection -> Text -> Wai.Application
|
||||
handleCookLogPost db filename request respond = do
|
||||
handleCookLogPost db rawFilename request respond = do
|
||||
let filename = normalizeRecipeKey rawFilename
|
||||
body <- readRequestBody request
|
||||
let params = parseFormBody body
|
||||
dateStr = fromMaybe "" (lookup "cooked-date" params)
|
||||
|
||||
Reference in New Issue
Block a user