diff --git a/packages/insomnia-app/app/network/multipart.ts b/packages/insomnia-app/app/network/multipart.ts index 723cbad46..46b2bafbf 100644 --- a/packages/insomnia-app/app/network/multipart.ts +++ b/packages/insomnia-app/app/network/multipart.ts @@ -1,5 +1,5 @@ import fs from 'fs'; -import mimes from 'mime-types'; +import { lookup } from 'mime-types'; import path from 'path'; import type { RequestBodyParameter } from '../models/request'; @@ -63,7 +63,7 @@ export async function buildMultipart(params: RequestBodyParameter[]) { if (param.type === 'file' && param.fileName) { const name = param.name || ''; const fileName = param.fileName; - const contentType = mimes.lookup(fileName) || 'application/octet-stream'; + const contentType = lookup(fileName) || 'application/octet-stream'; addString( 'Content-Disposition: form-data; ' + `name="${name.replace(/"/g, '\\"')}"; ` + diff --git a/packages/insomnia-app/app/ui/components/editors/body/body-editor.tsx b/packages/insomnia-app/app/ui/components/editors/body/body-editor.tsx index 2d3c9b979..3678e27d3 100644 --- a/packages/insomnia-app/app/ui/components/editors/body/body-editor.tsx +++ b/packages/insomnia-app/app/ui/components/editors/body/body-editor.tsx @@ -1,7 +1,7 @@ import { autoBindMethodsForReact } from 'class-autobind-decorator'; import clone from 'clone'; import { SvgIcon } from 'insomnia-components'; -import * as mimes from 'mime-types'; +import { lookup } from 'mime-types'; import React, { PureComponent } from 'react'; import { @@ -92,7 +92,7 @@ export class BodyEditor extends PureComponent { // Update Content-Type header if the user wants const contentType = contentTypeHeader.value; - const newContentType = mimes.lookup(path) || CONTENT_TYPE_FILE; + const newContentType = lookup(path) || CONTENT_TYPE_FILE; if (contentType !== newContentType && path) { contentTypeHeader.value = newContentType; diff --git a/packages/insomnia-app/app/ui/components/panes/response-pane.tsx b/packages/insomnia-app/app/ui/components/panes/response-pane.tsx index bb465f138..da9177f81 100644 --- a/packages/insomnia-app/app/ui/components/panes/response-pane.tsx +++ b/packages/insomnia-app/app/ui/components/panes/response-pane.tsx @@ -4,7 +4,7 @@ import { clipboard } from 'electron'; import fs from 'fs'; import { HotKeyRegistry } from 'insomnia-common'; import { json as jsonPrettify } from 'insomnia-prettify'; -import mime from 'mime-types'; +import { extension as mimeExtension } from 'mime-types'; import React, { PureComponent } from 'react'; import { Tab, TabList, TabPanel, Tabs } from 'react-tabs'; @@ -84,7 +84,7 @@ export class ResponsePane extends PureComponent { } const { contentType } = response; - const extension = mime.extension(contentType) || 'unknown'; + const extension = mimeExtension(contentType) || 'unknown'; const { canceled, filePath: outputPath } = await window.dialog.showSaveDialog({ title: 'Save Response Body', buttonLabel: 'Save', diff --git a/packages/insomnia-app/app/ui/components/viewers/response-multipart-viewer.tsx b/packages/insomnia-app/app/ui/components/viewers/response-multipart-viewer.tsx index b7f9440df..8ce24db07 100644 --- a/packages/insomnia-app/app/ui/components/viewers/response-multipart-viewer.tsx +++ b/packages/insomnia-app/app/ui/components/viewers/response-multipart-viewer.tsx @@ -1,7 +1,7 @@ import { autoBindMethodsForReact } from 'class-autobind-decorator'; import { SaveDialogOptions } from 'electron'; import fs from 'fs'; -import mimes from 'mime-types'; +import { extension as mimeExtension } from 'mime-types'; import moment from 'moment'; import multiparty from 'multiparty'; import path from 'path'; @@ -130,7 +130,7 @@ export class ResponseMultipartViewer extends PureComponent { } const contentType = getContentTypeFromHeaders(part.headers, 'text/plain'); - const extension = mimes.extension(contentType) || '.txt'; + const extension = mimeExtension(contentType) || '.txt'; const lastDir = window.localStorage.getItem('insomnia.lastExportPath'); const dir = lastDir || window.app.getPath('desktop'); const date = moment().format('YYYY-MM-DD'); diff --git a/packages/insomnia-app/app/ui/containers/app.tsx b/packages/insomnia-app/app/ui/containers/app.tsx index 3e9b6e534..706b00201 100644 --- a/packages/insomnia-app/app/ui/containers/app.tsx +++ b/packages/insomnia-app/app/ui/containers/app.tsx @@ -2,7 +2,7 @@ import { autoBindMethodsForReact } from 'class-autobind-decorator'; import { clipboard, ipcRenderer, SaveDialogOptions } from 'electron'; import fs from 'fs'; import HTTPSnippet from 'httpsnippet'; -import * as mime from 'mime-types'; +import { extension as mimeExtension } from 'mime-types'; import * as path from 'path'; import React, { createRef, PureComponent } from 'react'; import { connect } from 'react-redux'; @@ -729,8 +729,8 @@ class App extends PureComponent { responsePatch.statusCode >= 200 && responsePatch.statusCode < 300 ) { - // @ts-expect-error -- TSCONVERSION contentType can be undefined - const extension = mime.extension(responsePatch.contentType) || 'unknown'; + const sanitizedExtension = responsePatch.contentType && mimeExtension(responsePatch.contentType); + const extension = sanitizedExtension || 'unknown'; const name = nameFromHeader || `${request.name.replace(/\s/g, '-').toLowerCase()}.${extension}`; let filename; diff --git a/packages/insomnia-app/package-lock.json b/packages/insomnia-app/package-lock.json index d956b5efe..041e78baf 100644 --- a/packages/insomnia-app/package-lock.json +++ b/packages/insomnia-app/package-lock.json @@ -41,8 +41,8 @@ "jsonlint-mod-fixed": "1.7.7", "jsonpath-plus": "^6.0.1", "jwt-authentication": "^0.4.0", - "marked": "^4.0.12", - "mime-types": "^2.1.18", + "marked": "^4.0.10", + "mime-types": "^2.1.35", "mkdirp": "^0.5.1", "moment": "^2.21.0", "multiparty": "^4.2.1", @@ -108,7 +108,7 @@ "@types/less": "^3.0.2", "@types/license-checker": "^25.0.1", "@types/marked": "^4.0.2", - "@types/mime-types": "^2.1.0", + "@types/mime-types": "^2.1.1", "@types/mkdirp": "^0.5.2", "@types/multiparty": "^0.0.32", "@types/ncp": "^2.0.4", @@ -7115,9 +7115,9 @@ "dev": true }, "node_modules/@types/mime-types": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", - "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.1.tgz", + "integrity": "sha512-vXOTGVSLR2jMw440moWTC7H19iUyLtP3Z1YTj7cSsubOICinjMxFeb/V57v9QdyyPGbbWolUFSSmSiRSn94tFw==", "dev": true }, "node_modules/@types/minimatch": { @@ -21442,19 +21442,19 @@ } }, "node_modules/mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "engines": { "node": ">= 0.6" } }, "node_modules/mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "dependencies": { - "mime-db": "1.44.0" + "mime-db": "1.52.0" }, "engines": { "node": ">= 0.6" @@ -36539,9 +36539,9 @@ "dev": true }, "@types/mime-types": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", - "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.1.tgz", + "integrity": "sha512-vXOTGVSLR2jMw440moWTC7H19iUyLtP3Z1YTj7cSsubOICinjMxFeb/V57v9QdyyPGbbWolUFSSmSiRSn94tFw==", "dev": true }, "@types/minimatch": { @@ -47981,16 +47981,16 @@ "dev": true }, "mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" }, "mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "requires": { - "mime-db": "1.44.0" + "mime-db": "1.52.0" } }, "mimic-fn": { diff --git a/packages/insomnia-app/package.json b/packages/insomnia-app/package.json index 615509b8b..1bd2cd22d 100644 --- a/packages/insomnia-app/package.json +++ b/packages/insomnia-app/package.json @@ -133,8 +133,8 @@ "jsonlint-mod-fixed": "1.7.7", "jsonpath-plus": "^6.0.1", "jwt-authentication": "^0.4.0", - "marked": "^4.0.12", - "mime-types": "^2.1.18", + "marked": "^4.0.10", + "mime-types": "^2.1.35", "mkdirp": "^0.5.1", "moment": "^2.21.0", "multiparty": "^4.2.1", @@ -200,8 +200,8 @@ "@types/js-yaml": "^4.0.1", "@types/less": "^3.0.2", "@types/license-checker": "^25.0.1", + "@types/mime-types": "^2.1.1", "@types/marked": "^4.0.2", - "@types/mime-types": "^2.1.0", "@types/mkdirp": "^0.5.2", "@types/multiparty": "^0.0.32", "@types/ncp": "^2.0.4", diff --git a/packages/insomnia-send-request/package-lock.json b/packages/insomnia-send-request/package-lock.json index 3bb71238a..b885a87d1 100644 --- a/packages/insomnia-send-request/package-lock.json +++ b/packages/insomnia-send-request/package-lock.json @@ -27,7 +27,7 @@ "jsonlint-mod-fixed": "1.7.7", "jsonpath-plus": "^6.0.1", "marked": "^4.0.12", - "mime-types": "^2.1.27", + "mime-types": "^2.1.35", "mkdirp": "^1.0.4", "multiparty": "^4.2.1", "nedb": "^1.8.0", @@ -2413,19 +2413,19 @@ } }, "node_modules/mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "engines": { "node": ">= 0.6" } }, "node_modules/mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "dependencies": { - "mime-db": "1.44.0" + "mime-db": "1.52.0" }, "engines": { "node": ">= 0.6" @@ -5698,16 +5698,16 @@ } }, "mime-db": { - "version": "1.44.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", - "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" }, "mime-types": { - "version": "2.1.27", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", - "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "requires": { - "mime-db": "1.44.0" + "mime-db": "1.52.0" } }, "mimic-response": { diff --git a/packages/insomnia-send-request/package.json b/packages/insomnia-send-request/package.json index 191d29157..b7b765176 100644 --- a/packages/insomnia-send-request/package.json +++ b/packages/insomnia-send-request/package.json @@ -29,7 +29,7 @@ "jsonlint-mod-fixed": "1.7.7", "jsonpath-plus": "^6.0.1", "marked": "^4.0.12", - "mime-types": "^2.1.27", + "mime-types": "^2.1.35", "mkdirp": "^1.0.4", "multiparty": "^4.2.1", "nedb": "^1.8.0",