UNPKG

@teenth/sdk-tool

Version:

sdk-tool with R2 storage support

45 lines (44 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateUniqueFileName = exports.getMimeType = exports.VERSION = exports.post = exports.get = void 0; // 核心功能模块 - 所有环境通用 // 导出请求相关的函数 var request_1 = require("./request"); Object.defineProperty(exports, "get", { enumerable: true, get: function () { return request_1.get; } }); Object.defineProperty(exports, "post", { enumerable: true, get: function () { return request_1.post; } }); // 版本信息 exports.VERSION = "1.0.0"; // 浏览器安全的工具函数 - 直接在这里实现,避免引用 utils.ts function getMimeType(fileName) { const ext = fileName.split(".").pop()?.toLowerCase(); const mimeTypes = { jpg: "image/jpeg", jpeg: "image/jpeg", png: "image/png", gif: "image/gif", webp: "image/webp", svg: "image/svg+xml", pdf: "application/pdf", txt: "text/plain", json: "application/json", xml: "application/xml", html: "text/html", css: "text/css", js: "application/javascript", zip: "application/zip", rar: "application/x-rar-compressed", mp4: "video/mp4", mp3: "audio/mpeg", wav: "audio/wav", }; return mimeTypes[ext || ""] || "application/octet-stream"; } exports.getMimeType = getMimeType; function generateUniqueFileName(originalName, prefix = "") { const timestamp = Date.now(); const random = Math.random().toString(36).substring(2, 15); const ext = originalName.split(".").pop(); const baseName = originalName.split(".").slice(0, -1).join("."); return `${prefix}${prefix ? "_" : ""}${baseName}_${timestamp}_${random}.${ext}`; } exports.generateUniqueFileName = generateUniqueFileName;