Gallery list api support category filter

This commit is contained in:
2024-08-10 16:13:28 +08:00
parent 0fa3a72111
commit 695eed54ad
2 changed files with 20 additions and 2 deletions

12
db.ts
View File

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

View File

@@ -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,
),
);
}