UNPKG

mui-component

Version:

some custom mui components

84 lines 2.77 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } import { IconExcelColorful, IconFileColorful, IconImageColorful, IconPdfColorful, IconPptColorful, IconVideoColorful, IconWordColorful, IconZipColorful } from "@iimm/icons"; import { getFileNameFromUrl } from "@iimm/shared"; import { jsx as _jsx } from "react/jsx-runtime"; export var getFileInfo = function getFileInfo(file) { var iconSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 24; var url = typeof file === "string" ? file : file === null || file === void 0 ? void 0 : file.url; if (!url || typeof url !== "string") return null; var fileName = _typeof(file) === "object" && file !== null && file !== void 0 && file.name ? file.name : null; if (!fileName) fileName = getFileNameFromUrl(url); var info = { fileName: fileName, icon: /*#__PURE__*/_jsx(IconFileColorful, { size: iconSize }), view: false, type: "file", url: url }; var last = fileName.lastIndexOf("."); if (last !== -1) { var ext = fileName.slice(last + 1).toLowerCase(); switch (ext) { case "pdf": info.type = "pdf"; info.view = true; info.icon = /*#__PURE__*/_jsx(IconPdfColorful, { size: iconSize }); break; case "jpg": case "jpeg": case "png": case "bmp": case "ico": info.type = "image"; info.view = true; info.icon = /*#__PURE__*/_jsx(IconImageColorful, { size: iconSize }); break; case "mp4": info.type = "video"; info.view = true; info.icon = /*#__PURE__*/_jsx(IconVideoColorful, { size: iconSize }); break; case "doc": case "docx": info.type = "word"; info.icon = /*#__PURE__*/_jsx(IconWordColorful, { size: iconSize }); break; case "xls": case "xlsx": info.type = "excel"; info.icon = /*#__PURE__*/_jsx(IconExcelColorful, { size: iconSize }); break; case "ppt": case "pptx": info.type = "ppt"; info.icon = /*#__PURE__*/_jsx(IconPptColorful, { size: iconSize }); break; case "zip": case "rar": case "7z": case "rar4": info.type = "zip"; info.icon = /*#__PURE__*/_jsx(IconZipColorful, { size: iconSize }); break; default: break; } } return info; };