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 getCachedPath = (filePath: string) => {
|
||||||
const srv = REPOSITORIES.find((s) => {
|
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) {
|
if (fs.existsSync(fPath) ? fs.statSync(fPath).size : 0) {
|
||||||
console.log(`📦 [${s.code}]`, filePath);
|
console.log(`📦 [${s.name}]`, filePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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) => {
|
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.mkdirSync(outputDir, { recursive: true });
|
||||||
}
|
}
|
||||||
fs.renameSync(tmpPath, path.join(outputDir, fileName));
|
fs.renameSync(tmpPath, path.join(outputDir, fileName));
|
||||||
return resolve(srv.code);
|
return resolve(srv.name);
|
||||||
} else {
|
} else {
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ const downloadFile = async (url: string, res: any) => {
|
||||||
for await (const srv of REPOSITORIES) {
|
for await (const srv of REPOSITORIES) {
|
||||||
const fileName = url.split('/').pop() || '';
|
const fileName = url.split('/').pop() || '';
|
||||||
const outputDir = path
|
const outputDir = path
|
||||||
.join(cacheBaseDir, srv.code, url)
|
.join(cacheBaseDir, srv.name, url)
|
||||||
.replace(fileName, '');
|
.replace(fileName, '');
|
||||||
const downloadedFrom = await download(url, outputDir, srv);
|
const downloadedFrom = await download(url, outputDir, srv);
|
||||||
if (downloadedFrom) {
|
if (downloadedFrom) {
|
||||||
|
|
2
types.ts
2
types.ts
|
@ -5,7 +5,7 @@ type TProxy = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type TServer = {
|
type TServer = {
|
||||||
code: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
fileTypes?: string[];
|
fileTypes?: string[];
|
||||||
proxy?: string;
|
proxy?: string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue