diff --git a/pug/album_grid.pug b/pug/album_grid.pug index 2744267..4431d36 100644 --- a/pug/album_grid.pug +++ b/pug/album_grid.pug @@ -9,6 +9,9 @@ block view img(loading="lazy" src=item.item_art_url width=210 height=210) p.fs-body3.mb8= item.item_title .d-flex.fw-wrap.g4 + if item.why + a.s-tag.s-tag__xs(title=item.why).fc-orange-400(href=and({filter_field: "why", filter: "reviewed"})) + != icons.get("star-solid", 16) a.s-tag.s-tag__xs(href=and({arrange: "track", filter_field: "item_id", filter: item.item_id, filter_fuzzy: null})) span.s-tag--sponsor!= icons.get("music-note", 16) = item.track_count diff --git a/routes/app.js b/routes/app.js index 70e82ab..b95161b 100644 --- a/routes/app.js +++ b/routes/app.js @@ -66,7 +66,7 @@ const schema = { query: z.object({ arrange: z.enum(["album", "artist", "label", "tag", "track"]), shape: z.enum(["grid", "list"]), - filter_field: z.enum(["band_name", "band_url", "item_id", "tag"]).optional(), + filter_field: z.enum(["band_name", "band_url", "item_id", "tag", "why"]).optional(), filter: z.string().optional(), filter_fuzzy: z.enum(["true"]).optional() }), @@ -81,6 +81,7 @@ router.get("/:account/", defineEventHandler({ try { var {account} = await getValidatedRouterParams(event, schema.params.parse) var {arrange, shape, filter, filter_field, filter_fuzzy} = await getValidatedQuery(event, schema.query.parse) + if (filter_field === "why" && arrange !== "album") throw new Error("filter not compatible with arrangement") } catch (e) { return sendRedirect(event, "?arrange=album&shape=grid", 302) } @@ -95,14 +96,19 @@ router.get("/:account/", defineEventHandler({ let whereClause = "" if (filter_field && filter) { let operator = "=" - if (filter_field === "band_url" || filter_fuzzy) { + if (filter_field === "why") { + operator = "!=" + params.push("") + sql = sql.replace("{ORDER}", "ORDER BY purchased DESC") + } else if (filter_field === "band_url" || filter_fuzzy) { operator = "LIKE" params.push(`%${filter}%`) + sql = sql.replace("{ORDER}", "ORDER BY item_title COLLATE NOCASE") } else { params.push(filter) + sql = sql.replace("{ORDER}", "ORDER BY item_title COLLATE NOCASE") } whereClause = `AND ${filter_field} ${operator} ?` - sql = sql.replace("{ORDER}", "ORDER BY item_title COLLATE NOCASE") } else { sql = sql.replace("{ORDER}", "ORDER BY purchased DESC") }