Skip to content

Commit b456136

Browse files
committed
fix: fix regex
1 parent f12b374 commit b456136

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,25 @@ function downloadFile(url, filePath) {
6262
server.stdout.on('data', (data) => {
6363
const output = data.toString();
6464

65-
// 使用正则表达式匹配包含 404 错误的行并提取路径
66-
const match = output.match(/GET\s+([^\s]+)\s+Error\s+\(404\)/);
65+
// 定义正则表达式,支持任意文件后缀
66+
const regex = /"GET (\/.*?\.[a-zA-Z0-9]+)" Error \(404\):/g;
6767

68-
if (match) {
69-
const missingFile = match[1].replace(/"/g, ''); // 移除引号
70-
console.log('Missing file:', missingFile);
68+
// 使用正则表达式匹配包含 404 错误的行并提取路径
69+
const matches = [...output.matchAll(regex)];
70+
if (matches.length > 0) {
71+
matches.forEach((match) => {
72+
const missingFile = match[1].replace(/"/g, ''); // 移除引号
73+
console.log('Missing file:', missingFile);
7174

72-
// 构建完整的本地文件路径(从项目根目录开始)
73-
const localPath = path.join(process.cwd(), missingFile);
75+
// 构建完整的本地文件路径(从项目根目录开始)
76+
const localPath = path.join(process.cwd(), missingFile);
7477

75-
// 使用命令行传入的baseUrl构建下载URL
76-
const downloadUrl = `${baseUrl}${missingFile}`;
78+
// 使用命令行传入的baseUrl构建下载URL
79+
const downloadUrl = `${baseUrl}${missingFile}`;
7780

78-
// 下载文件
79-
downloadFile(downloadUrl, localPath);
81+
// 下载文件
82+
downloadFile(downloadUrl, localPath);
83+
});
8084
}
8185
});
8286

@@ -88,4 +92,4 @@ server.stderr.on('data', (data) => {
8892
// 监听进程结束
8993
server.on('close', (code) => {
9094
console.log(`http-server process exited with code ${code}`);
91-
});
95+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "resource-save-script",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"main": "index.js",
55
"author": "",
66
"license": "ISC",

0 commit comments

Comments
 (0)