Fix gallery can not obtain two same pictures

This commit is contained in:
2023-05-28 21:55:01 +08:00
parent 5d2d911d1a
commit b8d7c8313f
2 changed files with 26 additions and 2 deletions

15
db.ts
View File

@@ -124,7 +124,7 @@ const PMETA_TABLE = `CREATE TABLE pmeta (
name TEXT,
width INT,
height INT,
PRIMARY KEY (gid, token)
PRIMARY KEY (gid, "index")
);`;
const TAG_TABLE = `CREATE TABLE tag (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -156,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-3");
readonly version = new SemVer("1.0.0-4");
constructor(base_path: string) {
const db_path = join(base_path, "data.db");
sure_dir_sync(base_path);
@@ -198,6 +198,7 @@ export class EhDb {
const v = this.#read_version();
if (!v) return false;
if (v.compare(this.version) === -1) {
let need_optimize = false;
if (v.compare("1.0.0-1") === -1) {
this.db.execute("ALTER TABLE tag ADD translated 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) {
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();
if (need_optimize) this.optimize();
}
if (
ALL_TABLES.length !== this.#exist_table.size ||

View File

@@ -95,6 +95,19 @@ export async function download_task(
(t.is_original || !cfg.download_original_img) &&
(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);
return;
}