mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Fix gallery can not obtain two same pictures
This commit is contained in:
15
db.ts
15
db.ts
@@ -124,7 +124,7 @@ const PMETA_TABLE = `CREATE TABLE pmeta (
|
|||||||
name TEXT,
|
name TEXT,
|
||||||
width INT,
|
width INT,
|
||||||
height INT,
|
height INT,
|
||||||
PRIMARY KEY (gid, token)
|
PRIMARY KEY (gid, "index")
|
||||||
);`;
|
);`;
|
||||||
const TAG_TABLE = `CREATE TABLE tag (
|
const TAG_TABLE = `CREATE TABLE tag (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -156,7 +156,7 @@ export class EhDb {
|
|||||||
#lock_file: string | undefined;
|
#lock_file: string | undefined;
|
||||||
#dblock_file: string | undefined;
|
#dblock_file: string | undefined;
|
||||||
#_tags: Map<string, number> | undefined;
|
#_tags: Map<string, number> | undefined;
|
||||||
readonly version = new SemVer("1.0.0-3");
|
readonly version = new SemVer("1.0.0-4");
|
||||||
constructor(base_path: string) {
|
constructor(base_path: string) {
|
||||||
const db_path = join(base_path, "data.db");
|
const db_path = join(base_path, "data.db");
|
||||||
sure_dir_sync(base_path);
|
sure_dir_sync(base_path);
|
||||||
@@ -198,6 +198,7 @@ export class EhDb {
|
|||||||
const v = this.#read_version();
|
const v = this.#read_version();
|
||||||
if (!v) return false;
|
if (!v) return false;
|
||||||
if (v.compare(this.version) === -1) {
|
if (v.compare(this.version) === -1) {
|
||||||
|
let need_optimize = false;
|
||||||
if (v.compare("1.0.0-1") === -1) {
|
if (v.compare("1.0.0-1") === -1) {
|
||||||
this.db.execute("ALTER TABLE tag ADD translated TEXT;");
|
this.db.execute("ALTER TABLE tag ADD translated TEXT;");
|
||||||
this.db.execute("ALTER TABLE tag ADD intro TEXT;");
|
this.db.execute("ALTER TABLE tag ADD intro TEXT;");
|
||||||
@@ -213,7 +214,17 @@ export class EhDb {
|
|||||||
if (v.compare("1.0.0-3") === -1) {
|
if (v.compare("1.0.0-3") === -1) {
|
||||||
this.db.execute("ALTER TABLE task ADD details TEXT;");
|
this.db.execute("ALTER TABLE task ADD details TEXT;");
|
||||||
}
|
}
|
||||||
|
if (v.compare("1.0.0-4") === -1) {
|
||||||
|
this.db.execute("ALTER TABLE pmeta RENAME TO pmeta_origin;");
|
||||||
|
this.db.execute(PMETA_TABLE);
|
||||||
|
this.db.execute(
|
||||||
|
'INSERT INTO pmeta (gid, "index", token, name, width, height) SELECT gid, "index", token, name, width, height FROM pmeta_origin;',
|
||||||
|
);
|
||||||
|
this.db.execute("DROP TABLE pmeta_origin;");
|
||||||
|
need_optimize = true;
|
||||||
|
}
|
||||||
this.#write_version();
|
this.#write_version();
|
||||||
|
if (need_optimize) this.optimize();
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
ALL_TABLES.length !== this.#exist_table.size ||
|
ALL_TABLES.length !== this.#exist_table.size ||
|
||||||
|
|||||||
@@ -95,6 +95,19 @@ export async function download_task(
|
|||||||
(t.is_original || !cfg.download_original_img) &&
|
(t.is_original || !cfg.download_original_img) &&
|
||||||
(await exists(t.path))
|
(await exists(t.path))
|
||||||
) {
|
) {
|
||||||
|
const p = db.get_pmeta_by_index(task.gid, i.index);
|
||||||
|
if (!p) {
|
||||||
|
const op = db.get_pmeta_by_token(
|
||||||
|
task.gid,
|
||||||
|
i.page_token,
|
||||||
|
);
|
||||||
|
if (op) {
|
||||||
|
op.index = i.index;
|
||||||
|
op.name = i.name;
|
||||||
|
db.add_pmeta(op);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log("Already download page", i.index);
|
console.log("Already download page", i.index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user