This commit is contained in:
2023-06-23 12:20:37 +08:00
parent fe4562887c
commit 6438e47aaa
4 changed files with 44 additions and 4 deletions

8
db.ts
View File

@@ -1,5 +1,9 @@
import { DB } from "sqlite/mod.ts";
import { compare as compare_ver, parse as parse_ver } from "std/semver/mod.ts";
import {
compare as compare_ver,
format as format_ver,
parse as parse_ver,
} 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";
@@ -401,7 +405,7 @@ export class EhDb {
this.db.transaction(() => {
this.db.query("INSERT OR REPLACE INTO version VALUES (?, ?);", [
"eh",
this.version.toString(),
format_ver(this.version),
]);
});
}

View File

@@ -55,7 +55,9 @@ export class MeiliSearchServer {
}
#gallery_update(e: Event) {
const ev = e as CustomEvent<number>;
this.updateGallery(ev.detail);
this.updateGallery(ev.detail).catch((e) => {
console.log(e);
});
}
async #updateGMetaSettings() {
if (this.#gmeta) {

View File

@@ -1,6 +1,7 @@
import { DOMParser, Element } from "deno_dom/deno-dom-wasm-noinit.ts";
import { Client } from "../client.ts";
import { initDOMParser, parse_bool } from "../utils.ts";
import { initDOMParser, map, parse_bool } from "../utils.ts";
import { parseUrl, UrlType } from "../url.ts";
class GalleryPage {
dom;
@@ -11,6 +12,7 @@ class GalleryPage {
#meta_script: string | undefined = undefined;
#gid: number | undefined = undefined;
#token: string | undefined = undefined;
#new_version: Array<{ gid: number; token: string }> | undefined = undefined;
constructor(html: string, client: Client) {
const dom = (new DOMParser()).parseFromString(html, "text/html");
if (!dom) {
@@ -86,6 +88,24 @@ class GalleryPage {
if (!ele) throw Error("Failed to find gallery's name.");
return ele.innerText;
}
get new_version() {
if (this.#new_version === undefined) {
const eles = this.doc.querySelectorAll("#gnd > a");
const d = <{ gid: number; token: string }[]> map(eles, (e) => {
const b = e as Element;
const u = b.getAttribute("href");
if (!u) return null;
const d = parseUrl(u);
if (d?.type === UrlType.Gallery) {
return { gid: d.gid, token: d.token };
} else {
return null;
}
}).filter((d) => d !== null);
this.#new_version = d;
return d;
} else return this.#new_version;
}
get japanese_name() {
return this.doc.getElementById("gj")?.innerText;
}

View File

@@ -36,4 +36,18 @@ Deno.test({
assertEquals(re.language, "Chinese");
assertEquals(re.gid, 2552611);
assertEquals(re.token, "3132307627");
assertEquals(re.new_version.length, 0);
});
Deno.test({
name: "GalleryPage_test2",
permissions: API_PERMISSION,
}, async () => {
const cfg = await load_settings("./config.json");
const client = new Client(cfg);
const re = await client.fetchGalleryPage(2209409, "8c8b2b1fc3");
assertEquals(re.name, "[Fanbox] houk1se1 (2022.03.08 - 2022.05.01)");
assertEquals(re.japanese_name, "");
assertEquals(re.length, 42);
assertEquals(re.new_version[0], { gid: 2223198, token: "2a5788135e" });
});