feat: 批量解压缩

main
LCJ-MinYa 1 year ago
parent fd21ca5e77
commit a5ff1ceec4

51
package-lock.json generated

@ -9,7 +9,9 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"sharp": "^0.33.5"
"adm-zip": "^0.5.16",
"sharp": "^0.33.5",
"text-to-svg": "^3.1.5"
}
},
"node_modules/@emnapi/runtime": {
@ -363,6 +365,14 @@
"url": "https://opencollective.com/libvips"
}
},
"node_modules/adm-zip": {
"version": "0.5.16",
"resolved": "https://registry.npmmirror.com/adm-zip/-/adm-zip-0.5.16.tgz",
"integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==",
"engines": {
"node": ">=12.0"
}
},
"node_modules/color": {
"version": "4.2.3",
"resolved": "https://registry.npmmirror.com/color/-/color-4.2.3.tgz",
@ -400,6 +410,11 @@
"simple-swizzle": "^0.2.2"
}
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
},
"node_modules/detect-libc": {
"version": "2.0.3",
"resolved": "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.0.3.tgz",
@ -413,6 +428,18 @@
"resolved": "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.3.2.tgz",
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
},
"node_modules/opentype.js": {
"version": "0.11.0",
"resolved": "https://registry.npmmirror.com/opentype.js/-/opentype.js-0.11.0.tgz",
"integrity": "sha512-Z9NkAyQi/iEKQYzCSa7/VJSqVIs33wknw8Z8po+DzuRUAqivJ+hJZ94mveg3xIeKwLreJdWTMyEO7x1K13l41Q==",
"dependencies": {
"string.prototype.codepointat": "^0.2.1",
"tiny-inflate": "^1.0.2"
},
"bin": {
"ot": "bin/ot"
}
},
"node_modules/semver": {
"version": "7.6.3",
"resolved": "https://registry.npmmirror.com/semver/-/semver-7.6.3.tgz",
@ -470,6 +497,28 @@
"is-arrayish": "^0.3.1"
}
},
"node_modules/string.prototype.codepointat": {
"version": "0.2.1",
"resolved": "https://registry.npmmirror.com/string.prototype.codepointat/-/string.prototype.codepointat-0.2.1.tgz",
"integrity": "sha512-2cBVCj6I4IOvEnjgO/hWqXjqBGsY+zwPmHl12Srk9IXSZ56Jwwmy+66XO5Iut/oQVR7t5ihYdLB0GMa4alEUcg=="
},
"node_modules/text-to-svg": {
"version": "3.1.5",
"resolved": "https://registry.npmmirror.com/text-to-svg/-/text-to-svg-3.1.5.tgz",
"integrity": "sha512-mbeGhMz9MAFaGaZGE8n4Mh/iQV/UkVnYJXhXFrv0eWkcNTgflhpHR2a8nr2ci3NU4FekIHJYKh0N0qdc6yUpfA==",
"dependencies": {
"commander": "^2.11.0",
"opentype.js": "0.11.0"
},
"bin": {
"text-to-svg": "bin/text-to-svg"
}
},
"node_modules/tiny-inflate": {
"version": "1.0.3",
"resolved": "https://registry.npmmirror.com/tiny-inflate/-/tiny-inflate-1.0.3.tgz",
"integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw=="
},
"node_modules/tslib": {
"version": "2.7.0",
"resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.7.0.tgz",

@ -12,12 +12,14 @@
"bg": "node ./src/product_main_img_bg.js",
"reduce": "node ./src/reduce_img_size.js",
"ad": "node ./src/ad_img_merge.js",
"unzip": "node ./src/batch_un_zip.js",
"pptToImg": "npm run ppt && npm run merge && npm run water && npm run cover && npm run bg",
"pyToImg": "npm run merge && npm run water && npm run cover && npm run bg"
},
"author": "",
"license": "ISC",
"dependencies": {
"adm-zip": "^0.5.16",
"sharp": "^0.33.5",
"text-to-svg": "^3.1.5"
}

@ -64,7 +64,7 @@ async function handle_ad_img() {
return numA - numB; // 按数字排序
});
const desktopPath = getDesktopPath();
const desktopPath = `${getDesktopPath()}/adImg`;
for (let i = 0; i < sortImagePaths.length; i += exportAdImg.column) {
// 获取当前分组
const chunkImagePaths = sortImagePaths.slice(i, i + exportAdImg.column);

@ -0,0 +1,36 @@
const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
const { getInputDir } = require('../utils/index');
//工作目录文件夹路径
const inputDir = getInputDir();
if (!inputDir) {
console.log('未执行批量解压功能,工作目录不存在');
return;
}
//解压后输出文件夹
const outputDir = `${inputDir}/unzip`;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
async function unzip() {
// 读取源文件夹中的所有文件,并获取文件类型
const entries = fs.readdirSync(inputDir, { withFileTypes: true });
// 过滤出所有 ZIP 文件
const zipFiles = entries.filter((entry) => entry.isFile() && path.extname(entry.name) === '.zip').map((entry) => entry.name); // 只获取文件名
zipFiles.forEach((zipFile) => {
const zipFilePath = path.join(inputDir, zipFile);
const zip = new AdmZip(zipFilePath);
// 解压到指定输出文件夹
zip.extractAllTo(outputDir, true);
console.log(`已解压: ${zipFile}${outputDir}`);
});
}
unzip();
Loading…
Cancel
Save