mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-19 01:14:38 +08:00
add /api/file/random
This commit is contained in:
8
db.ts
8
db.ts
@@ -602,6 +602,14 @@ export class EhDb {
|
||||
);
|
||||
return s.length ? s[0] : undefined;
|
||||
}
|
||||
get_random_file() {
|
||||
const s = this.convert_file(
|
||||
this.db.queryEntries<EhFileRaw>(
|
||||
"SELECT * FROM file ORDER BY RANDOM() LIMIT 1;",
|
||||
),
|
||||
);
|
||||
return s.length ? s[0] : undefined;
|
||||
}
|
||||
get_tasks() {
|
||||
return this.transaction(() =>
|
||||
this.db.queryEntries<Task>("SELECT * FROM task;")
|
||||
|
||||
14
fresh.gen.ts
14
fresh.gen.ts
@@ -9,9 +9,10 @@ import * as $2 from "./routes/api/deploy_id.ts";
|
||||
import * as $3 from "./routes/api/exit.ts";
|
||||
import * as $4 from "./routes/api/export/gallery/zip/[gid].ts";
|
||||
import * as $5 from "./routes/api/file/[id].ts";
|
||||
import * as $6 from "./routes/api/gallery/[gid].ts";
|
||||
import * as $7 from "./routes/api/task.ts";
|
||||
import * as $8 from "./routes/index.tsx";
|
||||
import * as $6 from "./routes/api/file/random.ts";
|
||||
import * as $7 from "./routes/api/gallery/[gid].ts";
|
||||
import * as $8 from "./routes/api/task.ts";
|
||||
import * as $9 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";
|
||||
@@ -24,9 +25,10 @@ const manifest = {
|
||||
"./routes/api/exit.ts": $3,
|
||||
"./routes/api/export/gallery/zip/[gid].ts": $4,
|
||||
"./routes/api/file/[id].ts": $5,
|
||||
"./routes/api/gallery/[gid].ts": $6,
|
||||
"./routes/api/task.ts": $7,
|
||||
"./routes/index.tsx": $8,
|
||||
"./routes/api/file/random.ts": $6,
|
||||
"./routes/api/gallery/[gid].ts": $7,
|
||||
"./routes/api/task.ts": $8,
|
||||
"./routes/index.tsx": $9,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Container.tsx": $$0,
|
||||
|
||||
12
routes/api/file/random.ts
Normal file
12
routes/api/file/random.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { get_task_manager } from "../../../server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, _ctx) {
|
||||
const m = get_task_manager();
|
||||
const f = m.db.get_random_file();
|
||||
if (!f) return new Response("File not found.", { status: 404 });
|
||||
const u = new URL(req.url);
|
||||
return Response.redirect(`${u.origin}/api/file/${f.id}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user