From 299a9324f6ab0532c9a3b15a3f07283a45a9d779 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 8 Jan 2020 14:06:37 +0000 Subject: [PATCH 1/2] Update dependency file-type to v13 --- package.json | 2 +- yarn.lock | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index fdf8dceb..9f3dfe32 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "cheerio": "1.0.0-rc.3", "commander": "4.1.0", "express": "4.17.1", - "file-type": "12.4.2", + "file-type": "13.0.2", "filenamify": "4.1.0", "fs-extra": "8.1.0", "got": "10.2.1", diff --git a/yarn.lock b/yarn.lock index dc11e6af..bed13534 100644 --- a/yarn.lock +++ b/yarn.lock @@ -769,6 +769,11 @@ dependencies: defer-to-connect "^1.1.1" +"@tokenizer/token@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@tokenizer/token/-/token-0.1.0.tgz#9ee92540c56ca02e997d65dd14645cf9438c3dcf" + integrity sha512-fXk7a5R+aE8bfDRbfT+xRG2evSatjbljGGSUflfQmqw555My8II/EWly2GmcHaqXF5HCMitBEfSNhCRZCrLGGg== + "@types/cacheable-request@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.1.tgz#5d22f3dded1fd3a84c0bbeb5039a7419c2c91976" @@ -3477,10 +3482,15 @@ file-entry-cache@^5.0.1: dependencies: flat-cache "^2.0.1" -file-type@12.4.2: - version "12.4.2" - resolved "https://registry.yarnpkg.com/file-type/-/file-type-12.4.2.tgz#a344ea5664a1d01447ee7fb1b635f72feb6169d9" - integrity sha512-UssQP5ZgIOKelfsaB5CuGAL+Y+q7EmONuiwF3N5HAH0t27rvrttgi6Ra9k/+DVaY9UF6+ybxu5pOXLUdA8N7Vg== +file-type@13.0.2: + version "13.0.2" + resolved "https://registry.yarnpkg.com/file-type/-/file-type-13.0.2.tgz#99baeffc3989e4fdb189534700b6b494e114da74" + integrity sha512-7ZgM94zayCOwYUxUzsyI32TCd4cX1VepB75cqJR3DAnm4WS/lZKxc4LyhbBhCK71XPhZWKvLHD2voVcWeOv0MA== + dependencies: + readable-web-to-node-stream "^2.0.0" + strtok3 "^5.0.1" + token-types "^2.0.0" + typedarray-to-buffer "^3.1.5" file-uri-to-path@1.0.0: version "1.0.0" @@ -4268,7 +4278,7 @@ icss-utils@^4.0.0, icss-utils@^4.1.1: dependencies: postcss "^7.0.14" -ieee754@^1.1.4: +ieee754@^1.1.13, ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" integrity sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg== @@ -6434,6 +6444,11 @@ pbkdf2@^3.0.3: safe-buffer "^5.0.1" sha.js "^2.4.8" +peek-readable@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/peek-readable/-/peek-readable-3.1.0.tgz#250b08b7de09db8573d7fd8ea475215bbff14348" + integrity sha512-KGuODSTV6hcgdZvDrIDBUkN0utcAVj1LL7FfGbM0viKTtCHmtZcuEJ+lGqsp0fTFkGqesdtemV2yUSMeyy3ddA== + performance-now@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" @@ -7516,6 +7531,11 @@ readable-stream@^3.1.1: string_decoder "^1.1.1" util-deprecate "^1.0.1" +readable-web-to-node-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz#751e632f466552ac0d5c440cc01470352f93c4b7" + integrity sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA== + readdirp@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.2.1.tgz#0e87622a3325aa33e892285caf8b4e846529a525" @@ -8542,6 +8562,15 @@ strip-outer@^1.0.1: dependencies: escape-string-regexp "^1.0.2" +strtok3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/strtok3/-/strtok3-5.0.1.tgz#f89e09fa024dff82e39c160faf8d8706c24e7d21" + integrity sha512-AWliiIjyb87onqO8pM+1Hozm+PPcR4YYIWbFUT5OKQ+tOMwgdT8HwJd/IS8v3/gKdAtE5aE2p3FhcWqryuZPLQ== + dependencies: + "@tokenizer/token" "^0.1.0" + debug "^4.1.1" + peek-readable "^3.1.0" + style-search@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/style-search/-/style-search-0.1.0.tgz#7958c793e47e32e07d2b5cafe5c0bf8e12e77902" @@ -8865,6 +8894,14 @@ toidentifier@1.0.0: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== +token-types@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/token-types/-/token-types-2.0.0.tgz#b23618af744818299c6fbf125e0fdad98bab7e85" + integrity sha512-WWvu8sGK8/ZmGusekZJJ5NM6rRVTTDO7/bahz4NGiSDb/XsmdYBn6a1N/bymUHuWYTWeuLUg98wUzvE4jPdCZw== + dependencies: + "@tokenizer/token" "^0.1.0" + ieee754 "^1.1.13" + toposort@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330" From 41e3762e577fa128de425161577973c86f038a2f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 8 Jan 2020 16:11:01 +0200 Subject: [PATCH 2/2] Update file-type api usage --- src/plugins/uploader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/uploader.js b/src/plugins/uploader.js index 19642c57..ad4070e4 100644 --- a/src/plugins/uploader.js +++ b/src/plugins/uploader.js @@ -54,7 +54,7 @@ class Uploader { express.post("/uploads/new/:token", Uploader.routeUploadFile); } - static routeGetFile(req, res) { + static async routeGetFile(req, res) { const name = req.params.name; const nameRegex = /^[0-9a-f]{16}$/; @@ -66,7 +66,7 @@ class Uploader { const folder = name.substring(0, 2); const uploadPath = Helper.getFileUploadPath(); const filePath = path.join(uploadPath, folder, name); - const detectedMimeType = Uploader.getFileType(filePath); + const detectedMimeType = await Uploader.getFileType(filePath); // doesn't exist if (detectedMimeType === null) { @@ -232,12 +232,12 @@ class Uploader { // Returns null if an error occurred (e.g. file not found) // Returns a string with the type otherwise - static getFileType(filePath) { + static async getFileType(filePath) { try { const buffer = readChunk.sync(filePath, 0, fileType.minimumBytes); // returns {ext, mime} if found, null if not. - const file = fileType(buffer); + const file = await fileType.fromBuffer(buffer); // if a file type was detected correctly, return it if (file) {