Skip to content

Commit

Permalink
Move mimetypes.json to mimetypes.js
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rullzer committed Jun 25, 2015
1 parent 39c9d7f commit ecbca27
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 115 deletions.
29 changes: 29 additions & 0 deletions build/mimetypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

// Fetch all the aliases
$aliases = json_decode(file_get_contents(dirname(__DIR__) . '/config/mimetypealiases.json'), true);

// Fetch all files
$dir = new DirectoryIterator(dirname(__DIR__) . '/core/img/filetypes');

$files = [];
foreach($dir as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$files[] = $file;
}
}

//Remove duplicates
$files = array_values(array_unique($files));

//Generate the JS
$js = 'OC.MimeTypes={
aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT) . ',
files: ' . json_encode($files, JSON_PRETTY_PRINT) . '
};
';

//Output the JS
file_put_contents(dirname(__DIR__) . '/core/js/mimetypes.js', $js);

20 changes: 4 additions & 16 deletions core/js/mimetype.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
OC.MimeType = {

files: [],

mimeTypeAlias: {},

mimeTypeIcons: {},

init: function() {
$.getJSON(OC.webroot + '/core/mimetypes.json', function(data) {
OC.MimeType.mimeTypeAlias = data['aliases'];
OC.MimeType.files = data['files'];
});
},

mimetypeIcon: function(mimeType) {
if (_.isUndefined(mimeType)) {
return undefined;
}

if (mimeType in OC.MimeType.mimeTypeAlias) {
mimeType = OC.MimeType.mimeTypeAlias[mimeType];
if (mimeType in OC.MimeTypes.aliases) {
mimeType = OC.MimeTypes.aliases[mimeType];
}
if (mimeType in OC.MimeType.mimeTypeIcons) {
return OC.MimeType.mimeTypeIcons[mimeType];
Expand All @@ -37,9 +26,9 @@ OC.MimeType = {
path += 'folder-shared';
} else if (mimeType === 'dir-external') {
path += 'folder-external';
} else if ($.inArray(icon, OC.MimeType.files)) {
} else if ($.inArray(icon, OC.MimeTypes.files)) {
path += icon;
} else if ($.inArray(icon.split('-')[0], OC.MimeType.files)) {
} else if ($.inArray(icon.split('-')[0], OC.MimeTypes.files)) {
path += icon.split('-')[0];
} else {
path += 'file';
Expand All @@ -59,5 +48,4 @@ OC.MimeType = {

};

$(document).ready(OC.MimeType.init);

98 changes: 98 additions & 0 deletions core/js/mimetypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
OC.MimeTypes={
aliases: {
"application\/coreldraw": "image",
"application\/font-sfnt": "font",
"application\/font-woff": "font",
"application\/illustrator": "image\/vector",
"application\/json": "text\/code",
"application\/msaccess": "database",
"application\/msexcel": "x-office\/spreadsheet",
"application\/mspowerpoint": "x-office\/presentation",
"application\/msword": "x-office\/document",
"application\/octet-stream": "file",
"application\/postscript": "image\/vector",
"application\/vnd.android.package-archive": "package\/x-generic",
"application\/vnd.ms-excel": "x-office\/spreadsheet",
"application\/vnd.ms-excel.addin.macroEnabled.12": "x-office\/spreadsheet",
"application\/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office\/spreadsheet",
"application\/vnd.ms-excel.sheet.macroEnabled.12": "x-office\/spreadsheet",
"application\/vnd.ms-excel.template.macroEnabled.12": "x-office\/spreadsheet",
"application\/vnd.ms-fontobject": "font",
"application\/vnd.ms-powerpoint": "x-office\/presentation",
"application\/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office\/presentation",
"application\/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office\/presentation",
"application\/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office\/presentation",
"application\/vnd.ms-powerpoint.template.macroEnabled.12": "x-office\/presentation",
"application\/vnd.ms-word.document.macroEnabled.12": "x-office\/document",
"application\/vnd.ms-word.template.macroEnabled.12": "x-office\/document",
"application\/vnd.oasis.opendocument.presentation": "x-office\/presentation",
"application\/vnd.oasis.opendocument.presentation-template": "x-office\/presentation",
"application\/vnd.oasis.opendocument.spreadsheet": "x-office\/spreadsheet",
"application\/vnd.oasis.opendocument.spreadsheet-template": "x-office\/spreadsheet",
"application\/vnd.oasis.opendocument.text": "x-office\/document",
"application\/vnd.oasis.opendocument.text-master": "x-office\/document",
"application\/vnd.oasis.opendocument.text-template": "x-office\/document",
"application\/vnd.oasis.opendocument.text-web": "x-office\/document",
"application\/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office\/presentation",
"application\/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office\/presentation",
"application\/vnd.openxmlformats-officedocument.presentationml.template": "x-office\/presentation",
"application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office\/spreadsheet",
"application\/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office\/spreadsheet",
"application\/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office\/document",
"application\/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office\/document",
"application\/x-7z-compressed": "package\/x-generic",
"application\/x-compressed": "package\/x-generic",
"application\/x-dcraw": "image",
"application\/x-deb": "package\/x-generic",
"application\/x-font": "font",
"application\/x-gimp": "image",
"application\/x-gzip": "package\/x-generic",
"application\/x-perl": "text\/code",
"application\/x-photoshop": "image",
"application\/x-php": "text\/code",
"application\/x-rar-compressed": "package\/x-generic",
"application\/x-tar": "package\/x-generic",
"application\/x-tex": "text",
"application\/xml": "text\/html",
"application\/yaml": "text\/code",
"application\/zip": "package\/x-generic",
"image\/svg+xml": "image\/vector",
"text\/css": "text\/code",
"text\/csv": "x-office\/spreadsheet",
"text\/x-shellscript": "text\/code"
},
files: [
"text-x-h",
"application-rss+xml",
"video",
"folder-drag-accept",
"application-epub+zip",
"folder-public",
"package-x-generic",
"application-x-shockwave-flash",
"text",
"folder-external",
"web",
"text-vcard",
"application",
"image-vector",
"database",
"text-code",
"text-x-python",
"x-office-spreadsheet",
"application-pdf",
"folder",
"x-office-document",
"text-html",
"text-calendar",
"x-office-presentation",
"text-x-c",
"file",
"font",
"folder-shared",
"application-x-cbr",
"application-javascript",
"image",
"audio"
]
};
99 changes: 0 additions & 99 deletions core/mimetypes.json

This file was deleted.

1 change: 1 addition & 0 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ public static function initTemplateEngine() {
OC_Util::addScript("oc-requesttoken");
OC_Util::addScript("apps");
OC_Util::addScript('mimetype');
OC_Util::addScript('mimetypes');
OC_Util::addVendorScript('snapjs/dist/latest/snap');

// avatars
Expand Down

0 comments on commit ecbca27

Please sign in to comment.