From 69cafa68323789196320f107ddf719ff9ef058f2 Mon Sep 17 00:00:00 2001 From: Hassan Yousefi Date: Mon, 4 Sep 2023 14:20:23 +0330 Subject: [PATCH] fix get cached path error --- index.ts | 10 +++++----- types.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 670d37f..2e6e516 100644 --- a/index.ts +++ b/index.ts @@ -29,14 +29,14 @@ if (!fs.existsSync(path.resolve(cacheBaseDir, '_tmp_'))) { const getCachedPath = (filePath: string) => { const srv = REPOSITORIES.find((s) => { - const fPath = path.join(cacheBaseDir, s.code, filePath); + const fPath = path.join(cacheBaseDir, s.name, filePath); if (fs.existsSync(fPath) ? fs.statSync(fPath).size : 0) { - console.log(`📦 [${s.code}]`, filePath); + console.log(`📦 [${s.name}]`, filePath); return true; } return false; }); - return srv ? path.join(cacheBaseDir, srv.code, filePath) : null; + return srv ? path.join(cacheBaseDir, srv.name, filePath) : null; }; const download = async (url: string, outputDir: string, srv: TServer) => { @@ -63,7 +63,7 @@ const download = async (url: string, outputDir: string, srv: TServer) => { fs.mkdirSync(outputDir, { recursive: true }); } fs.renameSync(tmpPath, path.join(outputDir, fileName)); - return resolve(srv.code); + return resolve(srv.name); } else { return resolve(null); } @@ -79,7 +79,7 @@ const downloadFile = async (url: string, res: any) => { for await (const srv of REPOSITORIES) { const fileName = url.split('/').pop() || ''; const outputDir = path - .join(cacheBaseDir, srv.code, url) + .join(cacheBaseDir, srv.name, url) .replace(fileName, ''); const downloadedFrom = await download(url, outputDir, srv); if (downloadedFrom) { diff --git a/types.ts b/types.ts index 5ea2e29..b4b80b3 100644 --- a/types.ts +++ b/types.ts @@ -5,7 +5,7 @@ type TProxy = { }; type TServer = { - code: string; + name: string; url: string; fileTypes?: string[]; proxy?: string;