{"version":3,"sources":["../../src/uploads/getFileByPath.ts"],"sourcesContent":["import { fileTypeFromFile } from 'file-type'\nimport fs from 'fs/promises'\nimport path from 'path'\n\nimport type { PayloadRequest } from '../types/index.js'\n\nconst mimeTypeEstimate: Record = {\n svg: 'image/svg+xml',\n}\n\nexport const getFileByPath = async (filePath: string): Promise => {\n if (typeof filePath !== 'string') {\n return undefined\n }\n\n const name = path.basename(filePath)\n const ext = path.extname(filePath).slice(1)\n\n const [data, stat, type] = await Promise.all([\n fs.readFile(filePath),\n fs.stat(filePath),\n fileTypeFromFile(filePath),\n ])\n\n return {\n name,\n data,\n mimetype: type?.mime || mimeTypeEstimate[ext]!,\n size: stat.size,\n }\n}\n"],"names":["fileTypeFromFile","fs","path","mimeTypeEstimate","svg","getFileByPath","filePath","undefined","name","basename","ext","extname","slice","data","stat","type","Promise","all","readFile","mimetype","mime","size"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,YAAW;AAC5C,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAIvB,MAAMC,mBAA2C;IAC/CC,KAAK;AACP;AAEA,OAAO,MAAMC,gBAAgB,OAAOC;IAClC,IAAI,OAAOA,aAAa,UAAU;QAChC,OAAOC;IACT;IAEA,MAAMC,OAAON,KAAKO,QAAQ,CAACH;IAC3B,MAAMI,MAAMR,KAAKS,OAAO,CAACL,UAAUM,KAAK,CAAC;IAEzC,MAAM,CAACC,MAAMC,MAAMC,KAAK,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC3ChB,GAAGiB,QAAQ,CAACZ;QACZL,GAAGa,IAAI,CAACR;QACRN,iBAAiBM;KAClB;IAED,OAAO;QACLE;QACAK;QACAM,UAAUJ,MAAMK,QAAQjB,gBAAgB,CAACO,IAAI;QAC7CW,MAAMP,KAAKO,IAAI;IACjB;AACF,EAAC"}