From 695eed54adaa2d6c8004e411903ba1b0c6b01f6d Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 10 Aug 2024 16:13:28 +0800 Subject: [PATCH] Gallery list api support category filter --- db.ts | 12 +++++++++++- routes/api/gallery/list.ts | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/db.ts b/db.ts index 5f8fbcd..6eb94b5 100644 --- a/db.ts +++ b/db.ts @@ -1076,7 +1076,8 @@ export class EhDb { fields = "*", sort_by_gid: boolean | null = null, uploader: string | null = null, - tag: string | null, + tag: string | null = null, + category: string | null = null, ) { const sort_sql = sort_by_gid !== null ? ` ORDER BY gmeta.gid ${sort_by_gid ? "ASC" : "DESC"}` @@ -1099,6 +1100,10 @@ export class EhDb { where_sqls.push("uploader = ?"); args.push(uploader); } + if (category) { + where_sqls.push("category = ?"); + args.push(category); + } const where_sql = where_sqls.length ? ` WHERE ${where_sqls.join(" AND ")}` : ""; @@ -1118,6 +1123,7 @@ export class EhDb { sort_by_gid: boolean | null = null, uploader: string | null = null, tag: string | null = null, + category: string | null = null, ) { const sort_sql = sort_by_gid !== null ? ` ORDER BY gmeta.gid ${sort_by_gid ? "ASC" : "DESC"}` @@ -1139,6 +1145,10 @@ export class EhDb { where_sqls.push("uploader = ?"); args.push(uploader); } + if (category) { + where_sqls.push("category = ?"); + args.push(category); + } const where_sql = where_sqls.length ? ` WHERE ${where_sqls.join(" AND ")}` : ""; diff --git a/routes/api/gallery/list.ts b/routes/api/gallery/list.ts index 3871c5c..8567b8a 100644 --- a/routes/api/gallery/list.ts +++ b/routes/api/gallery/list.ts @@ -43,6 +43,7 @@ export const handler: Handlers = { ); const uploader = u.searchParams.get("uploader"); const tag = u.searchParams.get("tag"); + const category = u.searchParams.get("category"); if (fields !== "*") { const fs = fields.split(","); const ok = fs.every((d) => { @@ -53,7 +54,13 @@ export const handler: Handlers = { } if (all) { return return_data( - t.db.get_gmetas_all(fields, sort_by_gid, uploader, tag), + t.db.get_gmetas_all( + fields, + sort_by_gid, + uploader, + tag, + category, + ), ); } else { return return_data( @@ -64,6 +71,7 @@ export const handler: Handlers = { sort_by_gid, uploader, tag, + category, ), ); }