generated from ztimson/template
Better pathing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/zim-utils",
|
"name": "@ztimson/zim-utils",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"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",
|
||||||
|
|||||||
@@ -73,8 +73,10 @@ export class ZimManager {
|
|||||||
/** Resolves a file path or catalog `name` to a local file path. */
|
/** Resolves a file path or catalog `name` to a local file path. */
|
||||||
async #resolveFile(fileOrName) {
|
async #resolveFile(fileOrName) {
|
||||||
if (fs.existsSync(fileOrName)) return fileOrName;
|
if (fs.existsSync(fileOrName)) return fileOrName;
|
||||||
|
const joined = path.join(this.#dir, fileOrName);
|
||||||
|
if (fs.existsSync(joined)) return joined;
|
||||||
const local = await this.list();
|
const local = await this.list();
|
||||||
const match = local.find(l => l.meta?.name === fileOrName);
|
const match = local.find(l => l.meta?.name === fileOrName || path.basename(l.file) === fileOrName);
|
||||||
if (!match) throw new Error(`ZIM not found locally: ${fileOrName}`);
|
if (!match) throw new Error(`ZIM not found locally: ${fileOrName}`);
|
||||||
return match.file;
|
return match.file;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user