Skip to content

Commit 495c47c

Browse files
authored
Merge pull request #1 from itshenrywu/main
Switch download and extraction process from ZIP to RAR using 7z
2 parents bc05b7a + 9932dc4 commit 495c47c

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/assets/zipcode.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { JSDOM } = require("jsdom");
22
const fs = require("fs");
3-
const extract = require("extract-zip");
43
const path = require("path");
54
const { execSync } = require("child_process");
65
(async () => {
@@ -10,37 +9,30 @@ const { execSync } = require("child_process");
109
let text = await response.text();
1110
let dom = new JSDOM(text);
1211
let links = dom.window.document.querySelectorAll(
13-
`#dl_link_2735 a[title^="3+3郵遞區號應用系統"][href$=".zip"]`
12+
`#dl_link_2735 [href$=".rar"]`
1413
);
1514
// download all links
1615
const tempDir = path.resolve("./temp");
1716
fs.mkdirSync(tempDir, { recursive: true });
18-
let zipPath;
1917
for (let link of [...links]) {
20-
console.log(`download link: ${link}`);
21-
let url = link.href;
22-
let response = await fetch(url);
18+
console.log(`download link: ${link.href}`);
19+
let response = await fetch(link.href);
2320
let file = await response.arrayBuffer();
24-
let filename = url.split("/").pop();
25-
zipPath = path.join("./temp", decodeURIComponent(filename));
26-
fs.writeFileSync(zipPath, Buffer.from(file));
27-
28-
await extract(zipPath, {
29-
dir: tempDir,
30-
});
31-
// delete original zip file
32-
fs.unlinkSync(zipPath);
21+
let filename = link.href.split("/").pop();
22+
let filePath = path.join(tempDir, decodeURIComponent(filename));
23+
fs.writeFileSync(filePath, Buffer.from(file));
3324
}
34-
// cat test.zip* > ~/test.zip
35-
execSync(`cat ${tempDir}/* > ${path.join(tempDir, "installer.zip")}`);
36-
execSync(`unzip ${path.join(tempDir, `installer.zip`)} -d ${tempDir}`);
3725

38-
// find rename .exe file
26+
const rarFiles = fs.readdirSync(tempDir).filter(file => file.endsWith('.rar'));
27+
const firstRarFile = rarFiles.find(file => file.includes('part1')) || rarFiles[0];
28+
execSync(`7z x "${path.join(tempDir, firstRarFile)}" -o"${tempDir}/"`, {stdio: 'inherit'});
29+
30+
// find and rename .exe file
3931
const files = fs.readdirSync(tempDir);
4032
const exeFile = files.find((file) => file.endsWith(".exe"));
4133
fs.renameSync(
4234
path.join(tempDir, exeFile),
4335
path.join(tempDir, "installer.exe")
4436
);
4537
console.log("installer.exe saved to ./temp/installer.exe");
46-
})();
38+
})();

0 commit comments

Comments
 (0)