Skip to content

Commit ecbca27

Browse files
committed
Move mimetypes.json to mimetypes.js
Now there is a script in /build that can generate the a js file from the mimetypealiases.json file in config and the files listed. This makes it possible for users to easier extend the list of mimetype aliases.
1 parent 39c9d7f commit ecbca27

File tree

5 files changed

+132
-115
lines changed

5 files changed

+132
-115
lines changed

build/mimetypes.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
// Fetch all the aliases
4+
$aliases = json_decode(file_get_contents(dirname(__DIR__) . '/config/mimetypealiases.json'), true);
5+
6+
// Fetch all files
7+
$dir = new DirectoryIterator(dirname(__DIR__) . '/core/img/filetypes');
8+
9+
$files = [];
10+
foreach($dir as $fileInfo) {
11+
if ($fileInfo->isFile()) {
12+
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
13+
$files[] = $file;
14+
}
15+
}
16+
17+
//Remove duplicates
18+
$files = array_values(array_unique($files));
19+
20+
//Generate the JS
21+
$js = 'OC.MimeTypes={
22+
aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT) . ',
23+
files: ' . json_encode($files, JSON_PRETTY_PRINT) . '
24+
};
25+
';
26+
27+
//Output the JS
28+
file_put_contents(dirname(__DIR__) . '/core/js/mimetypes.js', $js);
29+

core/js/mimetype.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
OC.MimeType = {
22

3-
files: [],
4-
5-
mimeTypeAlias: {},
6-
73
mimeTypeIcons: {},
84

9-
init: function() {
10-
$.getJSON(OC.webroot + '/core/mimetypes.json', function(data) {
11-
OC.MimeType.mimeTypeAlias = data['aliases'];
12-
OC.MimeType.files = data['files'];
13-
});
14-
},
15-
165
mimetypeIcon: function(mimeType) {
176
if (_.isUndefined(mimeType)) {
187
return undefined;
198
}
209

21-
if (mimeType in OC.MimeType.mimeTypeAlias) {
22-
mimeType = OC.MimeType.mimeTypeAlias[mimeType];
10+
if (mimeType in OC.MimeTypes.aliases) {
11+
mimeType = OC.MimeTypes.aliases[mimeType];
2312
}
2413
if (mimeType in OC.MimeType.mimeTypeIcons) {
2514
return OC.MimeType.mimeTypeIcons[mimeType];
@@ -37,9 +26,9 @@ OC.MimeType = {
3726
path += 'folder-shared';
3827
} else if (mimeType === 'dir-external') {
3928
path += 'folder-external';
40-
} else if ($.inArray(icon, OC.MimeType.files)) {
29+
} else if ($.inArray(icon, OC.MimeTypes.files)) {
4130
path += icon;
42-
} else if ($.inArray(icon.split('-')[0], OC.MimeType.files)) {
31+
} else if ($.inArray(icon.split('-')[0], OC.MimeTypes.files)) {
4332
path += icon.split('-')[0];
4433
} else {
4534
path += 'file';
@@ -59,5 +48,4 @@ OC.MimeType = {
5948

6049
};
6150

62-
$(document).ready(OC.MimeType.init);
6351

core/js/mimetypes.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
OC.MimeTypes={
2+
aliases: {
3+
"application\/coreldraw": "image",
4+
"application\/font-sfnt": "font",
5+
"application\/font-woff": "font",
6+
"application\/illustrator": "image\/vector",
7+
"application\/json": "text\/code",
8+
"application\/msaccess": "database",
9+
"application\/msexcel": "x-office\/spreadsheet",
10+
"application\/mspowerpoint": "x-office\/presentation",
11+
"application\/msword": "x-office\/document",
12+
"application\/octet-stream": "file",
13+
"application\/postscript": "image\/vector",
14+
"application\/vnd.android.package-archive": "package\/x-generic",
15+
"application\/vnd.ms-excel": "x-office\/spreadsheet",
16+
"application\/vnd.ms-excel.addin.macroEnabled.12": "x-office\/spreadsheet",
17+
"application\/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office\/spreadsheet",
18+
"application\/vnd.ms-excel.sheet.macroEnabled.12": "x-office\/spreadsheet",
19+
"application\/vnd.ms-excel.template.macroEnabled.12": "x-office\/spreadsheet",
20+
"application\/vnd.ms-fontobject": "font",
21+
"application\/vnd.ms-powerpoint": "x-office\/presentation",
22+
"application\/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office\/presentation",
23+
"application\/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office\/presentation",
24+
"application\/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office\/presentation",
25+
"application\/vnd.ms-powerpoint.template.macroEnabled.12": "x-office\/presentation",
26+
"application\/vnd.ms-word.document.macroEnabled.12": "x-office\/document",
27+
"application\/vnd.ms-word.template.macroEnabled.12": "x-office\/document",
28+
"application\/vnd.oasis.opendocument.presentation": "x-office\/presentation",
29+
"application\/vnd.oasis.opendocument.presentation-template": "x-office\/presentation",
30+
"application\/vnd.oasis.opendocument.spreadsheet": "x-office\/spreadsheet",
31+
"application\/vnd.oasis.opendocument.spreadsheet-template": "x-office\/spreadsheet",
32+
"application\/vnd.oasis.opendocument.text": "x-office\/document",
33+
"application\/vnd.oasis.opendocument.text-master": "x-office\/document",
34+
"application\/vnd.oasis.opendocument.text-template": "x-office\/document",
35+
"application\/vnd.oasis.opendocument.text-web": "x-office\/document",
36+
"application\/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office\/presentation",
37+
"application\/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office\/presentation",
38+
"application\/vnd.openxmlformats-officedocument.presentationml.template": "x-office\/presentation",
39+
"application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office\/spreadsheet",
40+
"application\/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office\/spreadsheet",
41+
"application\/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office\/document",
42+
"application\/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office\/document",
43+
"application\/x-7z-compressed": "package\/x-generic",
44+
"application\/x-compressed": "package\/x-generic",
45+
"application\/x-dcraw": "image",
46+
"application\/x-deb": "package\/x-generic",
47+
"application\/x-font": "font",
48+
"application\/x-gimp": "image",
49+
"application\/x-gzip": "package\/x-generic",
50+
"application\/x-perl": "text\/code",
51+
"application\/x-photoshop": "image",
52+
"application\/x-php": "text\/code",
53+
"application\/x-rar-compressed": "package\/x-generic",
54+
"application\/x-tar": "package\/x-generic",
55+
"application\/x-tex": "text",
56+
"application\/xml": "text\/html",
57+
"application\/yaml": "text\/code",
58+
"application\/zip": "package\/x-generic",
59+
"image\/svg+xml": "image\/vector",
60+
"text\/css": "text\/code",
61+
"text\/csv": "x-office\/spreadsheet",
62+
"text\/x-shellscript": "text\/code"
63+
},
64+
files: [
65+
"text-x-h",
66+
"application-rss+xml",
67+
"video",
68+
"folder-drag-accept",
69+
"application-epub+zip",
70+
"folder-public",
71+
"package-x-generic",
72+
"application-x-shockwave-flash",
73+
"text",
74+
"folder-external",
75+
"web",
76+
"text-vcard",
77+
"application",
78+
"image-vector",
79+
"database",
80+
"text-code",
81+
"text-x-python",
82+
"x-office-spreadsheet",
83+
"application-pdf",
84+
"folder",
85+
"x-office-document",
86+
"text-html",
87+
"text-calendar",
88+
"x-office-presentation",
89+
"text-x-c",
90+
"file",
91+
"font",
92+
"folder-shared",
93+
"application-x-cbr",
94+
"application-javascript",
95+
"image",
96+
"audio"
97+
]
98+
};

core/mimetypes.json

Lines changed: 0 additions & 99 deletions
This file was deleted.

lib/base.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public static function initTemplateEngine() {
407407
OC_Util::addScript("oc-requesttoken");
408408
OC_Util::addScript("apps");
409409
OC_Util::addScript('mimetype');
410+
OC_Util::addScript('mimetypes');
410411
OC_Util::addVendorScript('snapjs/dist/latest/snap');
411412

412413
// avatars

0 commit comments

Comments
 (0)