diff --git a/db.ts b/db.ts index 7abbae9..54789d0 100644 --- a/db.ts +++ b/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 = 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( - 'SELECT * FROM pmeta WHERE gid = ? AND "index" = ?;', - [gid, index], - ), + const s = this.db.queryEntries( + '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( - "SELECT * FROM pmeta WHERE gid = ? AND token = ?;", - [gid, token], - ), + const s = this.db.queryEntries( + "SELECT * FROM pmeta WHERE gid = ? AND token = ?;", + [gid, token], ); return s.length ? s[0] : undefined; } diff --git a/db_test.ts b/db_test.ts index 5aa0766..f987830 100644 --- a/db_test.ts +++ b/db_test.ts @@ -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)); diff --git a/page/MPVPage.ts b/page/MPVPage.ts index b9b2e08..b65e076 100644 --- a/page/MPVPage.ts +++ b/page/MPVPage.ts @@ -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 {