@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.92 kB
Source Map (JSON)
{"version":3,"file":"get-file-metadata.mjs","names":[],"sources":["../../../src/utils/media/get-file-metadata.ts"],"sourcesContent":["import mime from \"mime-types\";\nimport type { MediaType } from \"../../types.js\";\nimport type { ServiceResponse } from \"../services/types.js\";\nimport getMediaType from \"./get-media-type.js\";\n\nexport type FileMetadata = {\n\tmimeType: string;\n\ttype: MediaType;\n\textension: string;\n};\n\n/**\n * Gets the metadata for a file.\n */\nconst getFileMetadata = async (props: {\n\tmimeType: string | null;\n\tfileName: string;\n}): ServiceResponse<FileMetadata> => {\n\tconst fallbackMimeType = \"application/octet-stream\";\n\tconst fileNameExtension =\n\t\tprops.fileName.split(\".\").pop()?.toLowerCase() || \"\";\n\tlet mimeType = props.mimeType?.toLowerCase().split(\";\")[0]?.trim() || null;\n\tlet extension = mime.extension(mimeType || \"\") || fileNameExtension;\n\n\tif (mimeType === undefined || mimeType === null) {\n\t\tmimeType = mime.lookup(fileNameExtension || extension) || null;\n\t}\n\tif (mimeType === \"application/mp4\") {\n\t\tmimeType = \"video/mp4\";\n\t}\n\tif (mimeType === undefined || mimeType === null) {\n\t\tmimeType = fallbackMimeType;\n\t}\n\tif (!extension) {\n\t\textension = mime.extension(mimeType) || \"bin\";\n\t}\n\n\tconst type = getMediaType(mimeType);\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: {\n\t\t\tmimeType,\n\t\t\ttype,\n\t\t\textension,\n\t\t},\n\t};\n};\n\nexport default getFileMetadata;\n"],"mappings":"8DAcA,MAAM,EAAkB,KAAO,IAGM,CACpC,IACM,EACL,EAAM,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,YAAY,GAAK,GAC/C,EAAW,EAAM,UAAU,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,GAAK,KAClE,EAAY,EAAK,UAAU,GAAY,EAAE,GAAK,EAElD,AACC,IAAW,EAAK,OAAO,GAAqB,CAAS,GAAK,KAEvD,IAAa,oBAChB,EAAW,aAEZ,AACC,IAAW,2BAEZ,AACC,IAAY,EAAK,UAAU,CAAQ,GAAK,MAGzC,IAAM,EAAO,EAAa,CAAQ,EAElC,MAAO,CACN,MAAO,IAAA,GACP,KAAM,CACL,WACA,OACA,WACD,CACD,CACD"}