Add meiliserach server support

Fix GalleryMetadata contains escaped html data
This commit is contained in:
2023-06-14 11:07:25 +08:00
parent d78276fc62
commit 0a6dc6ad2b
14 changed files with 450 additions and 29 deletions

32
db.ts
View File

@@ -1,5 +1,6 @@
import { DB } from "sqlite/mod.ts";
import { SemVer } from "std/semver/mod.ts";
import { unescape } from "std/html/mod.ts";
import { join, resolve } from "std/path/mod.ts";
import { SqliteError } from "sqlite/mod.ts";
import { Status } from "sqlite/src/constants.ts";
@@ -155,7 +156,7 @@ export class EhDb {
#lock_file: string | undefined;
#dblock_file: string | undefined;
#_tags: Map<string, number> | undefined;
readonly version = new SemVer("1.0.0-5");
readonly version = new SemVer("1.0.0-6");
constructor(base_path: string) {
const db_path = join(base_path, "data.db");
sure_dir_sync(base_path);
@@ -225,6 +226,29 @@ export class EhDb {
if (v.compare("1.0.0-5") === -1) {
this.db.execute("ALTER TABLE task DROP pn;");
}
if (v.compare("1.0.0-6") === -1) {
let offset = 0;
let tasks = this.convert_gmeta(
this.db.queryEntries<GMetaRaw>(
"SELECT * FROM gmeta LIMIT 20 OFFSET 0;",
),
);
while (tasks.length) {
tasks.forEach((t) => {
t.title = unescape(t.title);
t.title_jpn = unescape(t.title_jpn);
t.uploader = unescape(t.uploader);
this.add_gmeta(t);
});
offset += tasks.length;
tasks = this.convert_gmeta(
this.db.queryEntries<GMetaRaw>(
"SELECT * FROM gmeta LIMIT 20 OFFSET ?;",
[offset],
),
);
}
}
this.#write_version();
if (need_optimize) this.optimize();
}
@@ -487,6 +511,12 @@ export class EhDb {
[gid, token],
));
}
get_gids(offset = 0, limit = 20) {
return this.db.query<[number]>(
"SELECT gid FROM gmeta LIMIT ? OFFSET ?;",
[limit, offset],
).map((n) => n[0]);
}
get_gmeta_by_gid(gid: number) {
const s = this.convert_gmeta(
this.db.queryEntries<GMetaRaw>(