1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/ReactNativeClient/lib/mime-utils.js

45 lines
34 KiB
JavaScript
Raw Normal View History

2017-06-24 20:51:43 +02:00
const mimeTypes = [{t:"application/andrew-inset",e:["ez"]},{t:"application/applixware",e:["aw"]},{t:"application/atom+xml",e:["atom"]},{t:"application/atomcat+xml",e:["atomcat"]},{t:"application/atomsvc+xml",e:["atomsvc"]},{t:"application/ccxml+xml",e:["ccxml"]},{t:"application/cdmi-capability",e:["cdmia"]},{t:"application/cdmi-container",e:["cdmic"]},{t:"application/cdmi-domain",e:["cdmid"]},{t:"application/cdmi-object",e:["cdmio"]},{t:"application/cdmi-queue",e:["cdmiq"]},{t:"application/cu-seeme",e:["cu"]},{t:"application/davmount+xml",e:["davmount"]},{t:"application/docbook+xml",e:["dbk"]},{t:"application/dssc+der",e:["dssc"]},{t:"application/dssc+xml",e:["xdssc"]},{t:"application/ecmascript",e:["ecma"]},{t:"application/emma+xml",e:["emma"]},{t:"application/epub+zip",e:["epub"]},{t:"application/exi",e:["exi"]},{t:"application/font-tdpfr",e:["pfr"]},{t:"application/font-woff",e:["woff"]},{t:"application/gml+xml",e:["gml"]},{t:"application/gpx+xml",e:["gpx"]},{t:"application/gxf",e:["gxf"]},{t:"application/hyperstudio",e:["stk"]},{t:"application/inkml+xml",e:["ink","inkml"]},{t:"application/ipfix",e:["ipfix"]},{t:"application/java-archive",e:["jar"]},{t:"application/java-serialized-object",e:["ser"]},{t:"application/java-vm",e:["class"]},{t:"application/javascript",e:["js"]},{t:"application/json",e:["json"]},{t:"application/jsonml+json",e:["jsonml"]},{t:"application/lost+xml",e:["lostxml"]},{t:"application/mac-binhex40",e:["hqx"]},{t:"application/mac-compactpro",e:["cpt"]},{t:"application/mads+xml",e:["mads"]},{t:"application/marc",e:["mrc"]},{t:"application/marcxml+xml",e:["mrcx"]},{t:"application/mathematica",e:["ma","nb","mb"]},{t:"application/mathml+xml",e:["mathml"]},{t:"application/mbox",e:["mbox"]},{t:"application/mediaservercontrol+xml",e:["mscml"]},{t:"application/metalink+xml",e:["metalink"]},{t:"application/metalink4+xml",e:["meta4"]},{t:"application/mets+xml",e:["mets"]},{t:"application/mods+xml",e:["mods"]},{t:"application/mp21",e:["m21","mp21"]},{t:"application/mp4",e:["mp4s"]},{t:"application/msword",e:["doc","dot"]},{t:"application/mxf",e:["mxf"]},{t:"application/octet-stream",e:["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy"]},{t:"application/oda",e:["oda"]},{t:"application/oebps-package+xml",e:["opf"]},{t:"application/ogg",e:["ogx"]},{t:"application/omdoc+xml",e:["omdoc"]},{t:"application/onenote",e:["onetoc","onetoc2","onetmp","onepkg"]},{t:"application/oxps",e:["oxps"]},{t:"application/patch-ops-error+xml",e:["xer"]},{t:"application/pdf",e:["pdf"]},{t:"application/pgp-encrypted",e:["pgp"]},{t:"application/pgp-signature",e:["asc","sig"]},{t:"application/pics-rules",e:["prf"]},{t:"application/pkcs10",e:["p10"]},{t:"application/pkcs7-mime",e:["p7m","p7c"]},{t:"application/pkcs7-signature",e:["p7s"]},{t:"application/pkcs8",e:["p8"]},{t:"application/pkix-attr-cert",e:["ac"]},{t:"application/pkix-cert",e:["cer"]},{t:"application/pkix-crl",e:["crl"]},{t:"application/pkix-pkipath",e:["pkipath"]},{t:"application/pkixcmp",e:["pki"]},{t:"application/pls+xml",e:["pls"]},{t:"application/postscript",e:["ai","eps","ps"]},{t:"application/prs.cww",e:["cww"]},{t:"application/pskc+xml",e:["pskcxml"]},{t:"application/rdf+xml",e:["rdf"]},{t:"application/reginfo+xml",e:["rif"]},{t:"application/relax-ng-compact-syntax",e:["rnc"]},{t:"application/resource-lists+xml",e:["rl"]},{t:"application/resource-lists-diff+xml",e:["rld"]},{t:"application/rls-services+xml",e:["rs"]},{t:"application/rpki-ghostbusters",e:["gbr"]},{t:"application/rpki-manifest",e:["mft"]},{t:"application/rpki-roa",e:["roa"]},{t:"application/rsd+xml",e:["rsd"]},{t:"application/rss+xml",e:["rss"]},{t:"application/rtf",e:["rtf"]},{t:"application/sbml+xml",e:["sbml"]},{t:"application/scvp-cv-request",e:["scq"]},{t:"application/scvp-cv-response",e:["scs"]},{t:"application/scvp-vp-request",e:["spq"]},{t:"application/scvp-vp-response",e:["spp"]},{t:"application/sdp",e:["sdp"]},{t:"application/set-payment-initiation",e:["setpay"]},{t:"application/set-registration-initiation",e:["setreg"]},{t:"application/shf+xml",e:["shf"]},{t:"app
const mime = {
2017-11-20 00:08:58 +02:00
fromFileExtension(ext) {
ext = ext.toLowerCase();
for (let i = 0; i < mimeTypes.length; i++) {
const t = mimeTypes[i];
if (t.e.indexOf(ext) >= 0) {
return t.t;
}
}
return null;
},
2017-06-24 20:51:43 +02:00
toFileExtension(mimeType) {
mimeType = mimeType.toLowerCase();
for (let i = 0; i < mimeTypes.length; i++) {
2017-06-25 01:19:11 +02:00
const t = mimeTypes[i];
if (mimeType == t.t) {
// Return the first file extension that is 3 characters long
// If none exist return the first one in the list.
for (let j = 0; j < t.e.length; j++) {
if (t.e[j].length == 3) return t.e[j];
}
return t.e[0];
}
2017-06-24 20:51:43 +02:00
}
return null;
},
2018-05-25 09:51:54 +02:00
fromDataUrl(dataUrl) {
// Example: data:image/jpeg;base64,/9j/4AAQSkZJR.....
const defaultMime = 'text/plain';
let p = dataUrl.substr(0, dataUrl.indexOf(',')).split(';');
let s = p[0];
s = s.split(':');
if (s.length <= 1) return defaultMime;
s = s[1];
return s.indexOf('/') >= 0 ? s : defaultMime; // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
},
2017-06-24 20:51:43 +02:00
}
2017-11-03 02:13:17 +02:00
module.exports = { mime };