generated from ztimson/template
Create search index cache and return more meta
This commit is contained in:
@@ -45,11 +45,7 @@ export class ZimManager {
|
||||
let reader;
|
||||
try {
|
||||
reader = await new ZimReader(filepath).open();
|
||||
return {
|
||||
name: await reader.metadata('Name'),
|
||||
date: await reader.metadata('Date'),
|
||||
title: await reader.metadata('Title'),
|
||||
};
|
||||
return await reader.metadata();
|
||||
} catch {
|
||||
return null;
|
||||
} finally {
|
||||
@@ -59,7 +55,7 @@ export class ZimManager {
|
||||
|
||||
async #update(name, catalogEntry, localMatch, force) {
|
||||
const remoteDate = catalogEntry.updated ? new Date(catalogEntry.updated) : null;
|
||||
const localDate = localMatch?.meta?.date ? new Date(localMatch.meta.date) : null;
|
||||
const localDate = localMatch?.meta?.updated ?? null;
|
||||
if (!force && localMatch && remoteDate && localDate && remoteDate <= localDate)
|
||||
return {name, status: 'skipped', reason: 'up to date'};
|
||||
if (!catalogEntry.href) return {name, status: 'skipped', reason: 'missing download link'};
|
||||
@@ -67,7 +63,7 @@ export class ZimManager {
|
||||
const filename = path.basename(new URL(catalogEntry.href).pathname).replace(/\.meta4$/i, '');
|
||||
const destPath = path.join(this.#dir, filename);
|
||||
await this.#download(catalogEntry.href, destPath);
|
||||
if (localMatch && localMatch.file !== destPath) await fs.promises.unlink(localMatch.file).catch(() => {});
|
||||
if (localMatch && localMatch.file !== destPath) await new ZimReader(localMatch.file).delete().catch(() => {});
|
||||
return {name, status: 'updated', file: destPath};
|
||||
}
|
||||
|
||||
@@ -88,7 +84,7 @@ export class ZimManager {
|
||||
|
||||
async delete(fileOrName) {
|
||||
const file = await this.#resolveFile(fileOrName);
|
||||
await fs.promises.unlink(file);
|
||||
await new ZimReader(file).delete();
|
||||
return {file, status: 'deleted'};
|
||||
}
|
||||
|
||||
@@ -99,7 +95,7 @@ export class ZimManager {
|
||||
const catalogEntry = await zimCatalog(meta.name, this.#catalog);
|
||||
if (!catalogEntry) return {file, upToDate: null, reason: 'missing from catalog'};
|
||||
const remoteDate = catalogEntry.updated ? new Date(catalogEntry.updated) : null;
|
||||
const localDate = meta.date ? new Date(meta.date) : null;
|
||||
const localDate = meta.updated ?? null;
|
||||
return {file, name: meta.name, upToDate: !!(remoteDate && localDate && remoteDate <= localDate), localDate, remoteDate};
|
||||
}
|
||||
|
||||
@@ -153,7 +149,7 @@ export class ZimManager {
|
||||
}
|
||||
|
||||
/** Fuzzy-searches titles across every local ZIM in the library, merging & re-ranking hits by score. */
|
||||
async search(terms, {limit = 10, htmlOnly = true} = {}) {
|
||||
async search(terms, {limit = 20, htmlOnly = true} = {}) {
|
||||
const local = await this.list();
|
||||
const perZim = await Promise.all(local.map(async ({file, meta}) => {
|
||||
let reader;
|
||||
|
||||
Reference in New Issue
Block a user