Skip to content
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

fix: upgrade mime library #6754

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"deep-object-diff": "^1.1.9",
"deepmerge": "^4.3.1",
"errorhandler": "^1.5.1",
"express": "^4.18.2",
"express": "^4.19.2",
"express-rate-limit": "^7.1.2",
"express-session": "^1.17.3",
"fast-json-patch": "^3.1.0",
Expand All @@ -127,7 +127,7 @@
"log4js": "^6.0.0",
"make-fetch-happen": "^11.0.0",
"memoizee": "^0.4.15",
"mime": "^3.0.0",
"mime": "^4.0.1",
"multer": "^1.4.5-lts.1",
"murmurhash3js": "^3.0.1",
"mustache": "^4.1.0",
Expand Down Expand Up @@ -166,7 +166,6 @@
"@types/lodash.groupby": "4.6.9",
"@types/make-fetch-happen": "10.0.4",
"@types/memoizee": "0.4.11",
"@types/mime": "3.0.4",
"@types/node": "18.19.26",
"@types/nodemailer": "6.4.14",
"@types/owasp-password-strength-test": "1.3.2",
Expand Down
16 changes: 7 additions & 9 deletions src/lib/routes/admin-api/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as mime from 'mime';
import mime from 'mime';
import YAML from 'js-yaml';
import multer from 'multer';
import { format as formatDate } from 'date-fns';
Expand Down Expand Up @@ -104,15 +104,13 @@ class StateController extends Controller {
// TODO: Should override request type so file is a type on request
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
let data;
// @ts-expect-error
if (req.file) {
// @ts-expect-error
if (mime.getType(req.file.originalname) === 'text/yaml') {
// @ts-expect-error
data = YAML.load(req.file.buffer);
// @ts-expect-error req.file may not exist in the type
const file = req.file;
if (file) {
if (mime.getType(file.originalname) === 'text/yaml') {
data = YAML.load(file.buffer);
} else {
// @ts-expect-error
data = JSON.parse(req.file.buffer);
data = JSON.parse(file.buffer);
}
} else {
data = req.body;
Expand Down
7 changes: 1 addition & 6 deletions src/lib/routes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export const handleErrors: (
error: Error,
) => void = (res, logger, error) => {
if (createError.isHttpError(error)) {
return res
.status(
// @ts-expect-error - The error object here is not guaranteed to contain status
error.status ?? 400,
)
.json({ message: error.message });
return res.status(error.status ?? 400).json({ message: error.message });
}

const finalError =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/state-util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import * as mime from 'mime';
import mime from 'mime';
import * as YAML from 'js-yaml';

export const readFile: (file: string) => Promise<string> = (file) =>
Expand Down
Loading
Loading