mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Update MPVPage
This commit is contained in:
37
db.ts
37
db.ts
@@ -59,16 +59,6 @@ export type PMeta = {
|
||||
name: string;
|
||||
width: number;
|
||||
height: number;
|
||||
is_original: boolean;
|
||||
};
|
||||
export type PMetaRaw = {
|
||||
gid: number;
|
||||
index: number;
|
||||
token: string;
|
||||
name: string;
|
||||
width: number;
|
||||
height: number;
|
||||
is_original: number;
|
||||
};
|
||||
const ALL_TABLES = ["version", "task", "gmeta", "pmeta"];
|
||||
const VERSION_TABLE = `CREATE TABLE version (
|
||||
@@ -109,7 +99,6 @@ const PMETA_TABLE = `CREATE TABLE pmeta (
|
||||
name TEXT,
|
||||
width INT,
|
||||
height INT,
|
||||
is_original BOOLEAN,
|
||||
PRIMARY KEY (gid, token)
|
||||
);`;
|
||||
|
||||
@@ -201,7 +190,7 @@ export class EhDb {
|
||||
}
|
||||
add_pmeta(pmeta: PMeta) {
|
||||
this.db.queryEntries(
|
||||
"INSERT OR REPLACE INTO pmeta VALUES (:gid, :index, :token, :name, :width, :height, :is_original)",
|
||||
"INSERT OR REPLACE INTO pmeta VALUES (:gid, :index, :token, :name, :width, :height)",
|
||||
pmeta,
|
||||
);
|
||||
}
|
||||
@@ -268,14 +257,6 @@ export class EhDb {
|
||||
return t;
|
||||
});
|
||||
}
|
||||
convert_pmeta(m: PMetaRaw[]): PMeta[] {
|
||||
return m.map((m) => {
|
||||
const b = m.is_original !== 0;
|
||||
const t = <PMeta> <unknown> m;
|
||||
t.is_original = b;
|
||||
return t;
|
||||
});
|
||||
}
|
||||
delete_task(task: Task) {
|
||||
return this.transaction(() => {
|
||||
this.db.query("DELETE FROM task WHERE id = ?;", [task.id]);
|
||||
@@ -299,20 +280,16 @@ export class EhDb {
|
||||
return s.length ? s[0] : undefined;
|
||||
}
|
||||
get_pmeta_by_index(gid: number, index: number) {
|
||||
const s = this.convert_pmeta(
|
||||
this.db.queryEntries<PMetaRaw>(
|
||||
'SELECT * FROM pmeta WHERE gid = ? AND "index" = ?;',
|
||||
[gid, index],
|
||||
),
|
||||
const s = this.db.queryEntries<PMeta>(
|
||||
'SELECT * FROM pmeta WHERE gid = ? AND "index" = ?;',
|
||||
[gid, index],
|
||||
);
|
||||
return s.length ? s[0] : undefined;
|
||||
}
|
||||
get_pmeta_by_token(gid: number, token: string) {
|
||||
const s = this.convert_pmeta(
|
||||
this.db.queryEntries<PMetaRaw>(
|
||||
"SELECT * FROM pmeta WHERE gid = ? AND token = ?;",
|
||||
[gid, token],
|
||||
),
|
||||
const s = this.db.queryEntries<PMeta>(
|
||||
"SELECT * FROM pmeta WHERE gid = ? AND token = ?;",
|
||||
[gid, token],
|
||||
);
|
||||
return s.length ? s[0] : undefined;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ Deno.test("DbTest", async () => {
|
||||
name: "a.png",
|
||||
width: 1280,
|
||||
height: 720,
|
||||
is_original: true,
|
||||
};
|
||||
db.add_pmeta(pmeta);
|
||||
assertEquals(pmeta, db.get_pmeta_by_token(pmeta.gid, pmeta.token));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DOMParser } from "deno_dom/deno-dom-wasm-noinit.ts";
|
||||
import { Client } from "../client.ts";
|
||||
import { initDOMParser } from "../utils.ts";
|
||||
import { PMeta } from "../db.ts";
|
||||
|
||||
export type MPVRawImage = {
|
||||
/**Image name*/
|
||||
@@ -139,6 +140,18 @@ class MPVImage {
|
||||
this.redirected_url = await this.#mpv.client.redirect(url);
|
||||
return await this.#load_image(this.redirected_url || url);
|
||||
}
|
||||
to_pmeta(): PMeta | undefined {
|
||||
if (!this.data) return undefined;
|
||||
const gid = this.#mpv.gid;
|
||||
const index = this.index;
|
||||
const token = this.page_token;
|
||||
const name = this.name;
|
||||
const width = this.origin_xres;
|
||||
if (width === undefined) return undefined;
|
||||
const height = this.origin_yres;
|
||||
if (height === undefined) return undefined;
|
||||
return { gid, index, token, name, width, height };
|
||||
}
|
||||
}
|
||||
|
||||
class MPVPage {
|
||||
|
||||
Reference in New Issue
Block a user