Remove mime dependency

This commit is contained in:
shamoon 2023-09-10 07:13:42 -07:00
parent 6caa38965c
commit 51dcfd4c21
4 changed files with 5 additions and 28 deletions

12
package-lock.json generated
View File

@ -19,7 +19,6 @@
"js-yaml": "^4.1.0",
"json-rpc-2.0": "^1.4.1",
"memory-cache": "^0.2.0",
"mime": "^3.0.0",
"minecraft-ping-js": "^1.0.2",
"next": "^12.3.1",
"next-i18next": "^12.0.1",
@ -4167,17 +4166,6 @@
"node": ">=8.6"
}
},
"node_modules/mime": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz",
"integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",

View File

@ -21,7 +21,6 @@
"js-yaml": "^4.1.0",
"json-rpc-2.0": "^1.4.1",
"memory-cache": "^0.2.0",
"mime": "^3.0.0",
"minecraft-ping-js": "^1.0.2",
"next": "^12.3.1",
"next-i18next": "^12.0.1",

View File

@ -38,9 +38,6 @@ dependencies:
memory-cache:
specifier: ^0.2.0
version: 0.2.0
mime:
specifier: ^3.0.0
version: 3.0.0
minecraft-ping-js:
specifier: ^1.0.2
version: 1.0.2
@ -2701,12 +2698,6 @@ packages:
mime-db: 1.52.0
dev: false
/mime@3.0.0:
resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==}
engines: {node: '>=10.0.0'}
hasBin: true
dev: false
/mimic-fn@2.1.0:
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
engines: {node: '>=6'}

View File

@ -1,8 +1,6 @@
import path from "path";
import fs from "fs";
import mime from "mime";
import { CONF_DIR } from "utils/config/config";
import createLogger from "utils/logger";
@ -15,18 +13,19 @@ const logger = createLogger("configFileService");
export default async function handler(req, res) {
const { path: relativePath } = req.query;
if(relativePath !== 'custom.js' && relativePath !== 'custom.css')
// only two supported files, for now
if (!['custom.css', 'custom.js'].includes(relativePath))
{
res.status(422).end('Incorrect file extension, expected custom.js or custom.css')
res.status(422).end('Unsupported file')
}
const filePath = path.join(CONF_DIR, relativePath);
const mimeType = mime.getType(relativePath);
try {
// Read the content of the file or return empty content
const fileContent = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '';
// hard-coded since we only support two known files for now
const mimeType = (relativePath === 'custom.css') ? 'text/css' : 'text/javascript';
res.setHeader('Content-Type', mimeType);
res.status(200).send(fileContent);
} catch (error) {