UNPKG

payload-cloudinary

Version:
30 lines 1.26 kB
import path from "path"; import { IMAGE_EXTENSIONS, RAW_EXTENSIONS, VIDEO_EXTENSIONS } from "./constants"; const getResourceType = (ext) => { if (VIDEO_EXTENSIONS.includes(ext)) return "video"; if (IMAGE_EXTENSIONS.includes(ext)) return "image"; if (RAW_EXTENSIONS.includes(ext)) return "raw"; return "auto"; // Default to auto for unknown types }; export const getGenerateURL = ({ config, folder }) => ({ filename, prefix = "" }) => { // Construct the folder path with proper handling of prefix const folderPath = prefix ? path.posix.join(folder, prefix) : folder; const filePath = path.posix.join(folderPath, filename); const ext = path.extname(filename).toLowerCase(); const resourceType = getResourceType(ext); const baseUrl = `https://res.cloudinary.com/${config.cloud_name}`; switch (resourceType) { case "video": return `${baseUrl}/video/upload/f_auto,q_auto/${filePath}`; case "image": return `${baseUrl}/image/upload/f_auto,q_auto/${filePath}`; case "raw": return `${baseUrl}/raw/upload/${filePath}`; default: return `${baseUrl}/auto/upload/${filePath}`; } }; //# sourceMappingURL=generateURL.js.map