Merge file and mime code into simple Common/File.js

This commit is contained in:
djmaze 2020-10-02 14:44:29 +02:00
parent cb2048f163
commit 9992b20163
9 changed files with 345 additions and 452 deletions

View file

@ -1,5 +1,4 @@
import { ComposeType, SaveSettingsStep, FolderType } from 'Common/Enums';
import { Mime } from 'Common/Mime';
const
doc = document,
@ -820,39 +819,6 @@ export function computedPagenatorHelper(koCurrentPage, koPageCount) {
};
}
/**
* @param {string} fileName
* @returns {string}
*/
export function getFileExtension(fileName) {
fileName = fileName.toLowerCase().trim();
const result = fileName.split('.').pop();
return result === fileName ? '' : result;
}
/**
* @param {string} fileName
* @returns {string}
*/
export function mimeContentType(fileName) {
let ext = '',
result = 'application/octet-stream';
fileName = fileName.toLowerCase().trim();
if ('winmail.dat' === fileName) {
return 'application/ms-tnef';
}
ext = getFileExtension(fileName);
if (ext && ext.length && undefined !== Mime[ext]) {
result = Mime[ext];
}
return result;
}
/**
* @param {string} color
* @returns {boolean}