From 887d97fd20c4ca46b55c83480e1698ae504a3511 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:33:24 -0300 Subject: [PATCH] feat: get mime from library that checks the file binary --- package.json | 2 +- src/main/events/profile/update-profile.ts | 6 +++--- yarn.lock | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 53554bd2..89fb8c42 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "electron-log": "^5.1.4", "electron-updater": "^6.1.8", "fetch-cookie": "^3.0.1", + "file-type": "^19.0.0", "flexsearch": "^0.7.43", "i18next": "^23.11.2", "i18next-browser-languagedetector": "^7.2.1", @@ -61,7 +62,6 @@ "jsdom": "^24.0.0", "lodash-es": "^4.17.21", "lottie-react": "^2.4.0", - "mime": "^4.0.3", "parse-torrent": "^11.0.16", "piscina": "^4.5.1", "ps-list": "^8.1.1", diff --git a/src/main/events/profile/update-profile.ts b/src/main/events/profile/update-profile.ts index ca351629..5a485a99 100644 --- a/src/main/events/profile/update-profile.ts +++ b/src/main/events/profile/update-profile.ts @@ -3,7 +3,7 @@ import { HydraApi } from "@main/services/hydra-api"; import axios from "axios"; import fs from "node:fs"; import path from "node:path"; -import mime from "mime"; +import { fileTypeFromFile } from "file-type"; import { UserProfile } from "@types"; const patchUserProfile = async ( @@ -44,11 +44,11 @@ const updateProfile = async ( .then(async (preSignedResponse) => { const { presignedUrl, profileImageUrl } = preSignedResponse.data; - const mimeType = mime.getType(newProfileImagePath); + const mimeType = await fileTypeFromFile(newProfileImagePath); await axios.put(presignedUrl, fileBuffer, { headers: { - "Content-Type": mimeType, + "Content-Type": mimeType?.mime, }, }); return profileImageUrl; diff --git a/yarn.lock b/yarn.lock index be926a90..b822ab1d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3305,6 +3305,15 @@ file-type@^18.7.0: strtok3 "^7.0.0" token-types "^5.0.1" +file-type@^19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/file-type/-/file-type-19.0.0.tgz#62a6cadc43f73ba38c53e1a174943a75fdafafa9" + integrity sha512-s7cxa7/leUWLiXO78DVVfBVse+milos9FitauDLG1pI7lNaJ2+5lzPnr2N24ym+84HVwJL6hVuGfgVE+ALvU8Q== + dependencies: + readable-web-to-node-stream "^3.0.2" + strtok3 "^7.0.0" + token-types "^5.0.1" + file-uri-to-path@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" @@ -4518,11 +4527,6 @@ mime@^2.5.2: resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367" integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg== -mime@^4.0.3: - version "4.0.3" - resolved "https://registry.yarnpkg.com/mime/-/mime-4.0.3.tgz#cd4a1aa052fc980dfc34f111fe1be9e8b878c5d2" - integrity sha512-KgUb15Oorc0NEKPbvfa0wRU+PItIEZmiv+pyAO2i0oTIVTJhlzMclU7w4RXWQrSOVH5ax/p/CkIO7KI4OyFJTQ== - mimic-fn@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc"