mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-10 07:38:52 +08:00
Update
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { EhFileMeta } from "../../db.ts";
|
||||
import { get_task_manager } from "../../server.ts";
|
||||
import { get_string, parse_bool } from "../../server/parse_form.ts";
|
||||
import { get_string, parse_bool, parse_int } from "../../server/parse_form.ts";
|
||||
import { return_data, return_error } from "../../server/utils.ts";
|
||||
|
||||
export function get_filemeta(token: string) {
|
||||
@@ -28,6 +28,21 @@ export function put_filemeta(d: EhFileMeta) {
|
||||
return return_data({});
|
||||
}
|
||||
|
||||
export function put_gallery_filemeta(
|
||||
gid: number,
|
||||
is_nsfw: boolean,
|
||||
is_ad: boolean,
|
||||
excludes: Set<string>,
|
||||
) {
|
||||
const m = get_task_manager();
|
||||
const tokens = new Set(m.db.get_pmeta(gid).map((d) => d.token));
|
||||
for (const token of tokens) {
|
||||
if (excludes.has(token)) continue;
|
||||
m.db.add_filemeta({ token, is_nsfw, is_ad });
|
||||
}
|
||||
return return_data({});
|
||||
}
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, _ctx) {
|
||||
const u = new URL(req.url);
|
||||
@@ -52,6 +67,25 @@ export const handler: Handlers = {
|
||||
) {
|
||||
return put_filemeta(b);
|
||||
} else return return_error(3, "Invalid parameters.");
|
||||
} else if (typeof b.gid === "number") {
|
||||
if (
|
||||
typeof b.is_nsfw === "boolean" &&
|
||||
typeof b.is_ad === "boolean"
|
||||
) {
|
||||
const excludes: Set<string> =
|
||||
// @ts-ignore Any
|
||||
Array.isArray(b.excludes) && b.excludes.every((d) =>
|
||||
typeof d === "string"
|
||||
)
|
||||
? new Set(b.excludes)
|
||||
: new Set();
|
||||
return put_gallery_filemeta(
|
||||
b.gid,
|
||||
b.is_nsfw,
|
||||
b.is_ad,
|
||||
excludes,
|
||||
);
|
||||
} else return return_error(3, "Invalid parameters.");
|
||||
}
|
||||
return return_error(5, "Unknown JSON format.");
|
||||
} else if (
|
||||
@@ -65,13 +99,18 @@ export const handler: Handlers = {
|
||||
return return_error(3, "Invalid parameters.");
|
||||
}
|
||||
const token = await get_string(d.get("token"));
|
||||
const gid = await parse_int(d.get("gid"), null);
|
||||
const is_nsfw = await parse_bool(d.get("is_nsfw"), null);
|
||||
const is_ad = await parse_bool(d.get("is_ad"), null);
|
||||
if (is_nsfw === null || is_ad === null) {
|
||||
return return_error(3, "Invalid parameters.");
|
||||
}
|
||||
if (token) {
|
||||
const is_nsfw = await parse_bool(d.get("is_nsfw"), null);
|
||||
const is_ad = await parse_bool(d.get("is_ad"), null);
|
||||
if (is_nsfw === null || is_ad === null) {
|
||||
return return_error(3, "Invalid parameters.");
|
||||
}
|
||||
return put_filemeta({ token, is_nsfw, is_ad });
|
||||
} else if (gid !== null) {
|
||||
const e = await get_string(d.get("excludes"));
|
||||
const excludes = e ? new Set(e.split(",")) : new Set<string>();
|
||||
return put_gallery_filemeta(gid, is_nsfw, is_ad, excludes);
|
||||
}
|
||||
}
|
||||
return return_error(4, "Unknown format.");
|
||||
|
||||
Reference in New Issue
Block a user