storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/mime.js (about) 1 /* 2 * MinIO Cloud Storage (C) 2016 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import mimedb from "mime-types" 18 19 const isFolder = (name, contentType) => { 20 if (name.endsWith("/")) return true 21 return false 22 } 23 24 const isPdf = (name, contentType) => { 25 if (contentType === "application/pdf") return true 26 return false 27 } 28 const isImage = (name, contentType) => { 29 if ( 30 contentType === "image/jpeg" || 31 contentType === "image/gif" || 32 contentType === "image/x-icon" || 33 contentType === "image/png" || 34 contentType === "image/svg+xml" || 35 contentType === "image/tiff" || 36 contentType === "image/webp" 37 ) 38 return true 39 return false 40 } 41 42 const isZip = (name, contentType) => { 43 if (!contentType || !contentType.includes("/")) return false 44 if (contentType.split("/")[1].includes("zip")) return true 45 return false 46 } 47 48 const isCode = (name, contentType) => { 49 const codeExt = [ 50 "c", 51 "cpp", 52 "go", 53 "py", 54 "java", 55 "rb", 56 "js", 57 "pl", 58 "fs", 59 "php", 60 "css", 61 "less", 62 "scss", 63 "coffee", 64 "net", 65 "html", 66 "rs", 67 "exs", 68 "scala", 69 "hs", 70 "clj", 71 "el", 72 "scm", 73 "lisp", 74 "asp", 75 "aspx", 76 ] 77 const ext = name.split(".").reverse()[0] 78 for (var i in codeExt) { 79 if (ext === codeExt[i]) return true 80 } 81 return false 82 } 83 84 const isExcel = (name, contentType) => { 85 if (!contentType || !contentType.includes("/")) return false 86 const types = ["excel", "spreadsheet"] 87 const subType = contentType.split("/")[1] 88 for (var i in types) { 89 if (subType.includes(types[i])) return true 90 } 91 return false 92 } 93 94 const isDoc = (name, contentType) => { 95 if (!contentType || !contentType.includes("/")) return false 96 const types = ["word", ".document"] 97 const subType = contentType.split("/")[1] 98 for (var i in types) { 99 if (subType.includes(types[i])) return true 100 } 101 return false 102 } 103 104 const isPresentation = (name, contentType) => { 105 if (!contentType || !contentType.includes("/")) return false 106 var types = ["powerpoint", "presentation"] 107 const subType = contentType.split("/")[1] 108 for (var i in types) { 109 if (subType.includes(types[i])) return true 110 } 111 return false 112 } 113 114 const typeToIcon = (type) => { 115 return (name, contentType) => { 116 if (!contentType || !contentType.includes("/")) return false 117 if (contentType.split("/")[0] === type) return true 118 return false 119 } 120 } 121 122 export const getDataType = (name, contentType) => { 123 if (contentType === "") { 124 contentType = mimedb.lookup(name) || "application/octet-stream" 125 } 126 const check = [ 127 ["folder", isFolder], 128 ["code", isCode], 129 ["audio", typeToIcon("audio")], 130 ["image", typeToIcon("image")], 131 ["video", typeToIcon("video")], 132 ["text", typeToIcon("text")], 133 ["pdf", isPdf], 134 ["image", isImage], 135 ["zip", isZip], 136 ["excel", isExcel], 137 ["doc", isDoc], 138 ["presentation", isPresentation], 139 ] 140 for (var i in check) { 141 if (check[i][1](name, contentType)) return check[i][0] 142 } 143 return "other" 144 }