Skip to content

refactor: Upgrade to mime 4.0.4 #9363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 30 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ldapjs": "3.0.7",
"lodash": "4.17.21",
"lru-cache": "10.4.0",
"mime": "3.0.0",
"mime": "4.0.4",
"mongodb": "5.9.0",
"mustache": "4.2.0",
"otpauth": "9.3.4",
Expand Down
3 changes: 1 addition & 2 deletions src/Controllers/FilesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { randomHexString } from '../cryptoUtils';
import AdaptableController from './AdaptableController';
import { validateFilename, FilesAdapter } from '../Adapters/Files/FilesAdapter';
import path from 'path';
import mime from 'mime';
const Parse = require('parse').Parse;

const legacyFilesRegex = new RegExp(
Expand All @@ -19,7 +18,7 @@ export class FilesController extends AdaptableController {
const extname = path.extname(filename);

const hasExtension = extname.length > 0;

const mime = (await import('mime')).default
if (!hasExtension && contentType && mime.getExtension(contentType)) {
filename = filename + '.' + mime.getExtension(contentType);
} else if (hasExtension && !contentType) {
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/loaders/filesMutations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLNonNull } from 'graphql';
import { request } from 'http';
import { getExtension } from 'mime';
import { mutationWithClientMutationId } from 'graphql-relay';
import Parse from 'parse/node';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
Expand All @@ -17,8 +16,9 @@ const handleUpload = async (upload, config) => {
delete headers['host'];
delete headers['content-length'];
const stream = createReadStream();
const mime = (await import('mime')).default;
try {
const ext = getExtension(mimetype);
const ext = mime.getExtension(mimetype);
const fullFileName = filename.endsWith(`.${ext}`) ? filename : `${filename}.${ext}`;
const serverUrl = new URL(config.serverURL);
const fileInfo = await new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions src/Routers/FilesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import BodyParser from 'body-parser';
import * as Middlewares from '../middlewares';
import Parse from 'parse/node';
import Config from '../Config';
import mime from 'mime';
import logger from '../logger';
const triggers = require('../triggers');
const http = require('http');
Expand Down Expand Up @@ -67,7 +66,7 @@ export class FilesRouter {
return router;
}

getHandler(req, res) {
async getHandler(req, res) {
const config = Config.get(req.params.appId);
if (!config) {
res.status(403);
Expand All @@ -77,6 +76,7 @@ export class FilesRouter {
}
const filesController = config.filesController;
const filename = req.params.filename;
const mime = (await import('mime')).default;
const contentType = mime.getType(filename);
if (isFileStreamable(req, filesController)) {
filesController.handleFileStream(config, filename, req, res, contentType).catch(() => {
Expand Down
Loading