Removed outdated zims automatically
Publish Library / Build NPM Project (push) Successful in 5m35s
Publish Library / Tag Version (push) Successful in 32s

This commit is contained in:
2026-09-20 10:55:02 -04:00
parent 11f90c74cb
commit 4b86fe8051
2 changed files with 11 additions and 6 deletions
+9 -4
View File
@@ -24,6 +24,10 @@ export class ZimManager {
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. */
get server() { return this.#server; }
@@ -93,11 +97,12 @@ export class ZimManager {
const {url: finalUrl} = await this.#resolveUrl(href);
const filename = path.basename(new URL(finalUrl).pathname).replace(/\.meta4$/i, '');
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 localMatch = local.find(l => l.name === name) ?? null;
const catalogEntry = await zimCatalogInfo(name, this.#catalogUrl) || {name, updated: null, href: href};
const exact = local.find(l => l.file === filename);
if (exact && !force) return {name: exact.name ?? this.#stripDate(filename), status: 'skipped', reason: 'already downloaded', file: filename};
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);
}