feat: 批量解压缩

main
LCJ-MinYa 1 year ago
parent fd21ca5e77
commit a5ff1ceec4

1003
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -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