Add searching by reviewed

This commit is contained in:
Cadence Ember 2025-04-03 15:27:00 +13:00
parent c4e67c119e
commit cba0552ed0
2 changed files with 12 additions and 3 deletions

View file

@ -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")
}