dk-frontend-skills 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/core.js +30 -0
package/package.json
CHANGED
package/scripts/core.js
CHANGED
|
@@ -206,6 +206,21 @@ function getUserSkills(claudeDest) {
|
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* 校验文件是否为有效的 gzip 格式(magic number: 0x1F 0x8B)
|
|
211
|
+
*/
|
|
212
|
+
function isValidGzip(filePath) {
|
|
213
|
+
try {
|
|
214
|
+
const fd = fs.openSync(filePath, "r");
|
|
215
|
+
const buf = Buffer.alloc(2);
|
|
216
|
+
fs.readSync(fd, buf, 0, 2, 0);
|
|
217
|
+
fs.closeSync(fd);
|
|
218
|
+
return buf[0] === 0x1f && buf[1] === 0x8b;
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
209
224
|
/**
|
|
210
225
|
* 从远程下载文件到本地临时路径
|
|
211
226
|
*/
|
|
@@ -215,6 +230,15 @@ async function downloadFile(url, destPath, onProgress) {
|
|
|
215
230
|
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
216
231
|
}
|
|
217
232
|
|
|
233
|
+
// 检查 Content-Type,如果不是 gzip 大概率是 404 页面
|
|
234
|
+
const contentType = response.headers.get("content-type") || "";
|
|
235
|
+
if (!contentType.includes("gzip") && !contentType.includes("octet-stream") && !contentType.includes("binary")) {
|
|
236
|
+
const text = await response.clone().text();
|
|
237
|
+
if (text.includes("<!doctype") || text.includes("<html")) {
|
|
238
|
+
throw new Error("下载链接无效,请检查 GitHub Release 是否存在");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
218
242
|
const total = parseInt(response.headers.get("content-length") || "0", 10);
|
|
219
243
|
let downloaded = 0;
|
|
220
244
|
|
|
@@ -232,6 +256,12 @@ async function downloadFile(url, destPath, onProgress) {
|
|
|
232
256
|
} finally {
|
|
233
257
|
writer.close();
|
|
234
258
|
}
|
|
259
|
+
|
|
260
|
+
// 下载完后校验 gzip 格式
|
|
261
|
+
if (fs.existsSync(destPath) && !isValidGzip(destPath)) {
|
|
262
|
+
fs.rmSync(destPath, { force: true });
|
|
263
|
+
throw new Error("下载的文件不是有效的压缩包,可能是 GitHub Release 尚未创建或链接错误");
|
|
264
|
+
}
|
|
235
265
|
}
|
|
236
266
|
|
|
237
267
|
module.exports = {
|