Skip to content

Commit b2b2b0d

Browse files
committed
Converted file type utils to TypeScript and restored .jsonld in file allowlist
1 parent 374ebeb commit b2b2b0d

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

ghost/core/core/server/services/files/file-type-utils.js renamed to ghost/core/core/server/services/files/file-type-utils.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const path = require('path');
2-
const mime = require('mime-types');
1+
import path from 'path';
2+
import {lookup} from 'mime-types';
33

4-
const CONTENT_TYPE_OVERRIDES = new Map([
4+
const CONTENT_TYPE_OVERRIDES = new Map<string, string>([
55
['.html', 'text/plain'],
66
['.htm', 'text/plain'],
77
['.js', 'text/plain'],
88
['.css', 'text/plain'],
99
['.xml', 'text/plain']
1010
]);
1111

12-
const BROWSER_RENDERABLE_TYPES = new Set([
12+
const BROWSER_RENDERABLE_TYPES = new Set<string>([
1313
'image/jpeg',
1414
'image/png',
1515
'image/gif',
@@ -34,26 +34,23 @@ const BROWSER_RENDERABLE_TYPES = new Set([
3434
* 1. Override map — forced to text/plain to prevent browser execution
3535
* 2. Browser-renderable — type preserved as safe for browser rendering
3636
* 3. Fallback — application/octet-stream to force download
37-
*
38-
* @param {string} filename
39-
* @returns {string} content type to store
4037
*/
41-
function getStorageContentType(filename) {
38+
function getStorageContentType(filename: string): string {
4239
const ext = path.extname(filename).toLowerCase();
4340

4441
const override = CONTENT_TYPE_OVERRIDES.get(ext);
4542
if (override) {
4643
return override;
4744
}
4845

49-
const mimeType = mime.lookup(ext);
46+
const mimeType = lookup(ext);
5047
if (mimeType && BROWSER_RENDERABLE_TYPES.has(mimeType)) {
5148
return mimeType;
5249
}
5350

5451
return 'application/octet-stream';
5552
}
5653

57-
module.exports = {
54+
export {
5855
getStorageContentType
5956
};

ghost/core/core/shared/config/overrides.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"extensions": [
4747
".pdf",
4848
".json",
49+
".jsonld",
4950
".ods",
5051
".odt",
5152
".pptx",

ghost/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
"@types/bookshelf": "1.2.9",
233233
"@types/common-tags": "1.8.4",
234234
"@types/jsonwebtoken": "9.0.10",
235+
"@types/mime-types": "3.0.1",
235236
"@types/node": "22.18.10",
236237
"@types/node-jose": "1.1.13",
237238
"@types/nodemailer": "6.4.20",

ghost/core/test/unit/server/data/importer/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Importer', function () {
4242

4343
it('gets the correct extensions', function () {
4444
assert(Array.isArray(ImportManager.getExtensions()));
45-
assert.equal(ImportManager.getExtensions().length, 54);
45+
assert.equal(ImportManager.getExtensions().length, 55);
4646
assert(ImportManager.getExtensions().includes('.csv'));
4747
assert(ImportManager.getExtensions().includes('.json'));
4848
assert(ImportManager.getExtensions().includes('.zip'));
@@ -108,7 +108,7 @@ describe('Importer', function () {
108108
});
109109

110110
it('globs extensions correctly', function () {
111-
const extGlob = '+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.webp|.mp4|.webm|.ogv|.mp3|.wav|.ogg|.m4a|.pdf|.json|.ods|.odt|.pptx|.rtf|.txt|.xls|.xlsx|.xml|.apkg|.css|.csv|.doc|.docx|.epub|.gpx|.html|.ics|.ipynb|.js|.key|.kml|.md|.mobi|.mov|.otf|.pages|.paprikarecipes|.psd|.py|.skp|.woff|.woff2|.xlsb|.xlsm|.yaml|.zip|.markdown)';
111+
const extGlob = '+(.jpg|.jpeg|.gif|.png|.svg|.svgz|.ico|.webp|.mp4|.webm|.ogv|.mp3|.wav|.ogg|.m4a|.pdf|.json|.jsonld|.ods|.odt|.pptx|.rtf|.txt|.xls|.xlsx|.xml|.apkg|.css|.csv|.doc|.docx|.epub|.gpx|.html|.ics|.ipynb|.js|.key|.kml|.md|.mobi|.mov|.otf|.pages|.paprikarecipes|.psd|.py|.skp|.woff|.woff2|.xlsb|.xlsm|.yaml|.zip|.markdown)';
112112
assert.equal(ImportManager.getGlobPattern(ImportManager.getExtensions()), extGlob);
113113
assert.equal(ImportManager.getGlobPattern(ImportManager.getDirectories()), '+(images|content|media|files)');
114114
assert.equal(ImportManager.getGlobPattern(JSONHandler.extensions), '+(.json)');

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10262,6 +10262,11 @@
1026210262
resolved "https://registry.yarnpkg.com/@types/methods/-/methods-1.1.4.tgz#d3b7ac30ac47c91054ea951ce9eed07b1051e547"
1026310263
integrity sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==
1026410264

10265+
"@types/mime-types@3.0.1":
10266+
version "3.0.1"
10267+
resolved "https://registry.yarnpkg.com/@types/mime-types/-/mime-types-3.0.1.tgz#7fb74656179257c27cd48aa503eb918811727115"
10268+
integrity sha512-xRMsfuQbnRq1Ef+C+RKaENOxXX87Ygl38W1vDfPHRku02TgQr+Qd8iivLtAMcR0KF5/29xlnFihkTlbqFrGOVQ==
10269+
1026510270
"@types/mime@*":
1026610271
version "3.0.1"
1026710272
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10"

0 commit comments

Comments
 (0)