generated from ztimson/template
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e4d2c8ae7 |
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.3.7",
|
"version": "0.3.6",
|
||||||
"description": "Native, dependency-light ZIM archive reader/searcher and Kiwix catalog downloader for Node.js",
|
"description": "Native, dependency-light ZIM archive reader/searcher and Kiwix catalog downloader for Node.js",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
"zstd-codec": "^0.1.5",
|
"zstd-codec": "^0.1.5",
|
||||||
"adm-zip": "^0.5.16"
|
"adm-zip": "^0.5.16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-9
@@ -24,10 +24,6 @@ export class ZimManager {
|
|||||||
this.#server = server ?? new KiwixServer(dir, {port, host, binDir, url});
|
this.#server = server ?? new KiwixServer(dir, {port, host, binDir, url});
|
||||||
}
|
}
|
||||||
|
|
||||||
#stripDate(filename) {
|
|
||||||
return filename.replace(/\.zim$/i, '').replace(/_\d{4}-\d{2}(?:_\d+)?$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The KiwixServer backing this manager - reuse it directly for content/search access, or pass into another ZimManager. */
|
/** The KiwixServer backing this manager - reuse it directly for content/search access, or pass into another ZimManager. */
|
||||||
get server() { return this.#server; }
|
get server() { return this.#server; }
|
||||||
|
|
||||||
@@ -97,12 +93,11 @@ export class ZimManager {
|
|||||||
const {url: finalUrl} = await this.#resolveUrl(href);
|
const {url: finalUrl} = await this.#resolveUrl(href);
|
||||||
const filename = path.basename(new URL(finalUrl).pathname).replace(/\.meta4$/i, '');
|
const filename = path.basename(new URL(finalUrl).pathname).replace(/\.meta4$/i, '');
|
||||||
await fs.promises.mkdir(this.#dir, {recursive: true});
|
await fs.promises.mkdir(this.#dir, {recursive: true});
|
||||||
|
const name = filename.replace(/\.zim$/i, '').replace(/_\d{4}-\d{2}(?:_\d+)?$/, '');
|
||||||
|
|
||||||
const local = await this.list();
|
const local = await this.list();
|
||||||
const exact = local.find(l => l.file === filename);
|
const localMatch = local.find(l => l.name === name) ?? null;
|
||||||
if (exact && !force) return {name: exact.name ?? this.#stripDate(filename), status: 'skipped', reason: 'already downloaded', file: filename};
|
const catalogEntry = await zimCatalogInfo(name, this.#catalogUrl) || {name, updated: null, href: href};
|
||||||
const name = this.#stripDate(filename);
|
|
||||||
const localMatch = local.find(l => this.#stripDate(l.file) === name) ?? null;
|
|
||||||
const catalogEntry = await zimCatalogInfo(name, this.#catalogUrl) || {name, updated: null, href};
|
|
||||||
return this.#update(name, catalogEntry, localMatch, force);
|
return this.#update(name, catalogEntry, localMatch, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user