mirror of
https://github.com/hexboy/maven-mirror-tool.git
synced 2025-09-01 18:19:16 +00:00
fix get cached path error
This commit is contained in:
parent
1a70e2a0a1
commit
69cafa6832
2 changed files with 6 additions and 6 deletions
10
index.ts
10
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) {
|
||||
|
|
2
types.ts
2
types.ts
|
@ -5,7 +5,7 @@ type TProxy = {
|
|||
};
|
||||
|
||||
type TServer = {
|
||||
code: string;
|
||||
name: string;
|
||||
url: string;
|
||||
fileTypes?: string[];
|
||||
proxy?: string;
|
||||
|
|
Loading…
Add table
Reference in a new issue