Skip to content

Commit

Permalink
Merge pull request #990 from npocccties/fix-unzipper
Browse files Browse the repository at this point in the history
fix: node 18.16.0 以降で発生する unzipper の誤動作対策
  • Loading branch information
acutus-fujii authored Aug 1, 2023
2 parents 5823fdb + a62c1b5 commit 11e77e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"strict-uri-encode": "^2.0.0",
"ts-jest": "^29.0.5",
"tsup": "^6.7.0",
"unzipper": "^0.10.11",
"unzipper": "^0.10.14",
"yn": "^5.0.0"
}
}
8 changes: 6 additions & 2 deletions server/utils/book/importBooksUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ImportBooksUtil {
books: BookSchema[];
errors: string[];
timeRequired: number;
tmpdir?: string;
tmpdir: string;
unzippedFiles: string[];

constructor(user: UserSchema, params: BooksImportParams) {
Expand All @@ -49,6 +49,7 @@ class ImportBooksUtil {
this.books = [];
this.errors = [];
this.timeRequired = 0;
this.tmpdir = "";
this.unzippedFiles = [];
}

Expand Down Expand Up @@ -177,7 +178,10 @@ class ImportBooksUtil {

return new Promise((resolve) => {
fs.createReadStream(file)
.pipe(unzipper.Extract({ path: this.tmpdir }))
.pipe(unzipper.Parse())
.on("entry", (entry) => {
entry.pipe(fs.createWriteStream(path.join(this.tmpdir, entry.path)));
})
.on("close", () => {
this.unzippedFiles = recursive(this.tmpdir);
const jsonfiles: string[] = this.unzippedFiles.filter((filename) =>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14999,10 +14999,10 @@ untildify@^2.0.0:
dependencies:
os-homedir "^1.0.0"

unzipper@^0.10.11:
version "0.10.11"
resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.10.11.tgz#0b4991446472cbdb92ee7403909f26c2419c782e"
integrity sha512-+BrAq2oFqWod5IESRjL3S8baohbevGcVA+teAIOYWM3pDVdseogqbzhhvvmiyQrUNKFUnDMtELW3X8ykbyDCJw==
unzipper@^0.10.14:
version "0.10.14"
resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.10.14.tgz#d2b33c977714da0fbc0f82774ad35470a7c962b1"
integrity sha512-ti4wZj+0bQTiX2KmKWuwj7lhV+2n//uXEotUmGuQqrbVZSEGFMbI68+c6JCQ8aAmUWYvtHEz2A8K6wXvueR/6g==
dependencies:
big-integer "^1.6.17"
binary "~0.3.0"
Expand Down

0 comments on commit 11e77e8

Please sign in to comment.