From 02a0d975a4ad005c09037b18c627078ffab3608c Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 23 Jun 2023 15:42:49 +0800 Subject: [PATCH] Add /api/files/[token] --- fresh.gen.ts | 22 ++++++++++++---------- routes/api/files/[token].ts | 22 ++++++++++++++++++++++ server/files.ts | 8 ++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 routes/api/files/[token].ts create mode 100644 server/files.ts diff --git a/fresh.gen.ts b/fresh.gen.ts index 8f6e270..44c93ef 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -11,11 +11,12 @@ import * as $5 from "./routes/api/file/[id].ts"; import * as $6 from "./routes/api/file/random.ts"; import * as $7 from "./routes/api/filemeta.ts"; import * as $8 from "./routes/api/filemeta/[token].ts"; -import * as $9 from "./routes/api/gallery/[gid].ts"; -import * as $10 from "./routes/api/status.ts"; -import * as $11 from "./routes/api/task.ts"; -import * as $12 from "./routes/api/thumbnail/[id].ts"; -import * as $13 from "./routes/index.tsx"; +import * as $9 from "./routes/api/files/[token].ts"; +import * as $10 from "./routes/api/gallery/[gid].ts"; +import * as $11 from "./routes/api/status.ts"; +import * as $12 from "./routes/api/task.ts"; +import * as $13 from "./routes/api/thumbnail/[id].ts"; +import * as $14 from "./routes/index.tsx"; import * as $$0 from "./islands/Container.tsx"; import * as $$1 from "./islands/Settings.tsx"; import * as $$2 from "./islands/TaskManager.tsx"; @@ -31,11 +32,12 @@ const manifest = { "./routes/api/file/random.ts": $6, "./routes/api/filemeta.ts": $7, "./routes/api/filemeta/[token].ts": $8, - "./routes/api/gallery/[gid].ts": $9, - "./routes/api/status.ts": $10, - "./routes/api/task.ts": $11, - "./routes/api/thumbnail/[id].ts": $12, - "./routes/index.tsx": $13, + "./routes/api/files/[token].ts": $9, + "./routes/api/gallery/[gid].ts": $10, + "./routes/api/status.ts": $11, + "./routes/api/task.ts": $12, + "./routes/api/thumbnail/[id].ts": $13, + "./routes/index.tsx": $14, }, islands: { "./islands/Container.tsx": $$0, diff --git a/routes/api/files/[token].ts b/routes/api/files/[token].ts new file mode 100644 index 0000000..29551cc --- /dev/null +++ b/routes/api/files/[token].ts @@ -0,0 +1,22 @@ +import { Handlers } from "$fresh/server.ts"; +import { get_task_manager } from "../../../server.ts"; +import { EhFiles } from "../../../server/files.ts"; +import { return_data } from "../../../server/utils.ts"; + +export const handler: Handlers = { + GET(_req, ctx) { + const tokens = ctx.params.token.split(","); + const m = get_task_manager(); + const data: EhFiles = {}; + for (const token of tokens) { + data[token] = m.db.get_files(token).map((d) => { + /**@ts-ignore */ + delete d.path; + /**@ts-ignore */ + delete d.token; + return d; + }); + } + return return_data(data); + }, +}; diff --git a/server/files.ts b/server/files.ts new file mode 100644 index 0000000..429d866 --- /dev/null +++ b/server/files.ts @@ -0,0 +1,8 @@ +export type EhFileBasic = { + id: number; + width: number; + height: number; + is_original: boolean; +}; + +export type EhFiles = Record;