github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/utils.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React from "react"; 18 19 import { 20 FileBookIcon, 21 FileCodeIcon, 22 FileConfigIcon, 23 FileDbIcon, 24 FileFontIcon, 25 FileImageIcon, 26 FileLockIcon, 27 FileMissingIcon, 28 FileMusicIcon, 29 FileNonType, 30 FilePdfIcon, 31 FilePptIcon, 32 FileTxtIcon, 33 FileVideoIcon, 34 FileXlsIcon, 35 FileZipIcon, 36 FolderBrowserIcon, 37 } from "mds"; 38 import IconWithLabel from "./IconWithLabel"; 39 40 interface IExtToIcon { 41 icon: any; 42 extensions: string[]; 43 } 44 45 export const extensionToIcon: IExtToIcon[] = [ 46 { 47 icon: <FileVideoIcon />, 48 extensions: ["mp4", "mov", "avi", "mpeg", "mpg"], 49 }, 50 { 51 icon: <FileMusicIcon />, 52 extensions: ["mp3", "m4a", "aac"], 53 }, 54 { 55 icon: <FilePdfIcon />, 56 extensions: ["pdf"], 57 }, 58 { 59 icon: <FilePptIcon />, 60 extensions: ["ppt", "pptx"], 61 }, 62 { 63 icon: <FileXlsIcon />, 64 extensions: ["xls", "xlsx"], 65 }, 66 { 67 icon: <FileLockIcon />, 68 extensions: ["cer", "crt", "pem"], 69 }, 70 { 71 icon: <FileCodeIcon />, 72 extensions: ["html", "xml", "css", "py", "go", "php", "cpp", "h", "java"], 73 }, 74 { 75 icon: <FileConfigIcon />, 76 extensions: ["cfg", "yaml"], 77 }, 78 { 79 icon: <FileDbIcon />, 80 extensions: ["sql"], 81 }, 82 { 83 icon: <FileFontIcon />, 84 extensions: ["ttf", "otf"], 85 }, 86 { 87 icon: <FileTxtIcon />, 88 extensions: ["doc", "docx", "txt", "rtf"], 89 }, 90 { 91 icon: <FileZipIcon />, 92 extensions: ["zip", "rar", "tar", "gz"], 93 }, 94 { 95 icon: <FileBookIcon />, 96 extensions: ["epub", "mobi", "azw", "azw3"], 97 }, 98 { 99 icon: <FileImageIcon />, 100 extensions: ["jpeg", "jpg", "gif", "tiff", "png", "heic", "dng"], 101 }, 102 ]; 103 104 export const displayFileIconName = ( 105 element: string, 106 returnOnlyIcon: boolean = false, 107 ) => { 108 let elementString = element; 109 let icon = <FileNonType />; 110 // Element is a folder 111 if (element.endsWith("/")) { 112 icon = <FolderBrowserIcon />; 113 elementString = element.slice(0, -1); 114 } 115 116 const lowercaseElement = element.toLowerCase(); 117 for (const etc of extensionToIcon) { 118 for (const ext of etc.extensions) { 119 if (lowercaseElement.endsWith(`.${ext}`)) { 120 icon = etc.icon; 121 } 122 } 123 } 124 125 if (!element.endsWith("/") && element.indexOf(".") < 0) { 126 icon = <FileMissingIcon />; 127 } 128 129 const splitItem = elementString.split("/"); 130 131 if (returnOnlyIcon) { 132 return icon; 133 } 134 135 return <IconWithLabel icon={icon} strings={splitItem} />; 136 };