mirror of
https://github.com/nextcloud/server.git
synced 2026-04-23 07:08:34 -04:00
Merge pull request #17483 from rullzer/migrate-mimetype-js
Move away from OCA.files.getMimeIcon and use OC.MimeType.getIconUrl
This commit is contained in:
commit
87f3500fda
9 changed files with 101 additions and 135 deletions
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Robin Appelman <icewind@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
\OC::$server->getSession()->close();
|
||||
|
||||
$mime = isset($_GET['mime']) ? (string)$_GET['mime'] : '';
|
||||
|
||||
print OC_Helper::mimetypeIcon($mime);
|
||||
|
|
@ -66,8 +66,6 @@ $this->create('files_ajax_getstoragestats', 'ajax/getstoragestats.php')
|
|||
->actionInclude('files/ajax/getstoragestats.php');
|
||||
$this->create('files_ajax_list', 'ajax/list.php')
|
||||
->actionInclude('files/ajax/list.php');
|
||||
$this->create('files_ajax_mimeicon', 'ajax/mimeicon.php')
|
||||
->actionInclude('files/ajax/mimeicon.php');
|
||||
$this->create('files_ajax_move', 'ajax/move.php')
|
||||
->actionInclude('files/ajax/move.php');
|
||||
$this->create('files_ajax_newfile', 'ajax/newfile.php')
|
||||
|
|
|
|||
|
|
@ -670,7 +670,7 @@
|
|||
*/
|
||||
_createRow: function(fileData, options) {
|
||||
var td, simpleSize, basename, extension, sizeColor,
|
||||
icon = OC.Util.replaceSVGIcon(fileData.icon),
|
||||
icon = OC.MimeType.getIconUrl(fileData.mimetype),
|
||||
name = fileData.name,
|
||||
type = fileData.type || 'file',
|
||||
mtime = parseInt(fileData.mtime, 10),
|
||||
|
|
@ -1213,36 +1213,34 @@
|
|||
var etag = options.etag;
|
||||
|
||||
// get mime icon url
|
||||
OCA.Files.Files.getMimeIcon(mime, function(iconURL) {
|
||||
var previewURL,
|
||||
urlSpec = {};
|
||||
ready(iconURL); // set mimeicon URL
|
||||
var iconURL = OC.MimeType.getIconUrl(mime);
|
||||
var previewURL,
|
||||
urlSpec = {};
|
||||
ready(iconURL); // set mimeicon URL
|
||||
|
||||
urlSpec.file = OCA.Files.Files.fixPath(path);
|
||||
urlSpec.file = OCA.Files.Files.fixPath(path);
|
||||
|
||||
if (etag){
|
||||
// use etag as cache buster
|
||||
urlSpec.c = etag;
|
||||
if (etag){
|
||||
// use etag as cache buster
|
||||
urlSpec.c = etag;
|
||||
} else {
|
||||
console.warn('OCA.Files.FileList.lazyLoadPreview(): missing etag argument');
|
||||
}
|
||||
|
||||
previewURL = self.generatePreviewUrl(urlSpec);
|
||||
previewURL = previewURL.replace('(', '%28');
|
||||
previewURL = previewURL.replace(')', '%29');
|
||||
|
||||
// preload image to prevent delay
|
||||
// this will make the browser cache the image
|
||||
var img = new Image();
|
||||
img.onload = function(){
|
||||
// if loading the preview image failed (no preview for the mimetype) then img.width will < 5
|
||||
if (img.width > 5) {
|
||||
ready(previewURL);
|
||||
}
|
||||
else {
|
||||
console.warn('OCA.Files.FileList.lazyLoadPreview(): missing etag argument');
|
||||
}
|
||||
|
||||
previewURL = self.generatePreviewUrl(urlSpec);
|
||||
previewURL = previewURL.replace('(', '%28');
|
||||
previewURL = previewURL.replace(')', '%29');
|
||||
|
||||
// preload image to prevent delay
|
||||
// this will make the browser cache the image
|
||||
var img = new Image();
|
||||
img.onload = function(){
|
||||
// if loading the preview image failed (no preview for the mimetype) then img.width will < 5
|
||||
if (img.width > 5) {
|
||||
ready(previewURL);
|
||||
}
|
||||
};
|
||||
img.src = previewURL;
|
||||
});
|
||||
};
|
||||
img.src = previewURL;
|
||||
},
|
||||
|
||||
setDirectoryPermissions: function(permissions) {
|
||||
|
|
|
|||
|
|
@ -163,18 +163,14 @@
|
|||
return OC.filePath('files', 'ajax', action + '.php') + q;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch the icon url for the mimetype
|
||||
* @param {string} mime The mimetype
|
||||
* @param {Files~mimeicon} ready Function to call when mimetype is retrieved
|
||||
* @deprecated use OC.MimeType.getIconUrl(mime)
|
||||
*/
|
||||
getMimeIcon: function(mime, ready) {
|
||||
if (Files.getMimeIcon.cache[mime]) {
|
||||
ready(Files.getMimeIcon.cache[mime]);
|
||||
} else {
|
||||
$.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) {
|
||||
if(OC.Util.hasSVGSupport()){
|
||||
path = path.substr(0, path.length-4) + '.svg';
|
||||
}
|
||||
Files.getMimeIcon.cache[mime]=path;
|
||||
ready(Files.getMimeIcon.cache[mime]);
|
||||
});
|
||||
}
|
||||
ready(OC.MimeType.getIconUrl(mime));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -211,7 +207,6 @@
|
|||
* Initialize the files view
|
||||
*/
|
||||
initialize: function() {
|
||||
Files.getMimeIcon.cache = {};
|
||||
Files.bindKeyboardShortcuts(document, $);
|
||||
|
||||
// TODO: move file list related code (upload) to OCA.Files.FileList
|
||||
|
|
|
|||
|
|
@ -697,7 +697,7 @@ describe('OCA.Files.FileList tests', function() {
|
|||
|
||||
expect(fileList.findFileEl('One.txt').length).toEqual(1);
|
||||
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
||||
.toEqual(OC.imagePath('core', 'filetypes/file.svg'));
|
||||
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
||||
});
|
||||
});
|
||||
describe('Moving files', function() {
|
||||
|
|
@ -816,7 +816,7 @@ describe('OCA.Files.FileList tests', function() {
|
|||
expect(notificationStub.getCall(0).args[0]).toEqual('Error while moving file');
|
||||
|
||||
expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail')))
|
||||
.toEqual(OC.imagePath('core', 'filetypes/file.svg'));
|
||||
.toEqual(OC.imagePath('core', 'filetypes/text.svg'));
|
||||
});
|
||||
});
|
||||
describe('List rendering', function() {
|
||||
|
|
@ -1161,7 +1161,8 @@ describe('OCA.Files.FileList tests', function() {
|
|||
var fileData = {
|
||||
type: 'file',
|
||||
name: 'test dir',
|
||||
icon: OC.webroot + '/core/img/filetypes/application-pdf.svg'
|
||||
icon: OC.webroot + '/core/img/filetypes/application-pdf.svg',
|
||||
mimetype: 'application/pdf'
|
||||
};
|
||||
var $tr = fileList.add(fileData);
|
||||
var $imgDiv = $tr.find('td.filename .thumbnail');
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ describe('OCA.Sharing.Util tests', function() {
|
|||
type: 'dir',
|
||||
name: 'One',
|
||||
path: '/subdir',
|
||||
mimetype: 'text/plain',
|
||||
mimetype: 'httpd/unix-directory',
|
||||
size: 12,
|
||||
permissions: OC.PERMISSION_ALL,
|
||||
etag: 'abc'
|
||||
|
|
|
|||
|
|
@ -4,65 +4,66 @@
|
|||
"_comment3": "Otherwise your update won't propagate through the system",
|
||||
|
||||
|
||||
"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",
|
||||
"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",
|
||||
"httpd/unix-directory": "dir",
|
||||
"image/svg+xml": "image/vector",
|
||||
"text/css": "text/code",
|
||||
"text/csv": "x-office/spreadsheet",
|
||||
"text/x-shellscript": "text/code"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ OC.MimeTypeList={
|
|||
"application/xml": "text/html",
|
||||
"application/yaml": "text/code",
|
||||
"application/zip": "package/x-generic",
|
||||
"httpd/unix-directory": "dir",
|
||||
"image/svg+xml": "image/vector",
|
||||
"text/css": "text/code",
|
||||
"text/csv": "x-office/spreadsheet",
|
||||
|
|
|
|||
|
|
@ -396,9 +396,8 @@ var OCdialogs = {
|
|||
function(path){
|
||||
$replacementDiv.find('.icon').css('background-image','url(' + path + ')');
|
||||
}, function(){
|
||||
Files.getMimeIcon(replacement.type,function(path){
|
||||
$replacementDiv.find('.icon').css('background-image','url(' + path + ')');
|
||||
});
|
||||
path = OC.MimeType.getIconUrl(replacement.type);
|
||||
$replacementDiv.find('.icon').css('background-image','url(' + path + ')');
|
||||
}
|
||||
);
|
||||
$conflicts.append($conflict);
|
||||
|
|
|
|||
Loading…
Reference in a new issue