add /api/file/random

This commit is contained in:
2023-06-19 10:15:11 +08:00
parent 3561c30587
commit 4684e16c82
3 changed files with 28 additions and 6 deletions

8
db.ts
View File

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