{"version":3,"file":"getAllowedFiles.mjs","sources":["../../../admin/src/utils/getAllowedFiles.ts"],"sourcesContent":["import { toSingularTypes } from './toSingularTypes';\n\nimport type { File } from '../../../shared/contracts/files';\n/**\n * Returns the files that can be added to the media field\n * @param {Object[]} pluralTypes Array of string (allowedTypes)\n * @param {Object[]} files Array of files\n * @returns Object[]\n */\n\nexport interface AllowedFiles extends File {\n documentId: string;\n isSelectable: boolean;\n locale: string | null;\n type: string;\n}\n\nexport const getAllowedFiles = (pluralTypes: string[] | null, files: AllowedFiles[]) => {\n if (!pluralTypes) {\n return files;\n }\n\n const singularTypes = toSingularTypes(pluralTypes);\n\n const allowedFiles = files.filter((file) => {\n const fileType = file?.mime?.split('/')[0];\n\n if (!fileType) {\n return false;\n }\n\n if (singularTypes.includes('file') && !['video', 'image', 'audio'].includes(fileType)) {\n return true;\n }\n\n return singularTypes.includes(fileType);\n });\n\n return allowedFiles;\n};\n"],"names":["getAllowedFiles","pluralTypes","files","singularTypes","toSingularTypes","allowedFiles","filter","file","fileType","mime","split","includes"],"mappings":";;AAiBO,MAAMA,eAAkB,GAAA,CAACC,WAA8BC,EAAAA,KAAAA,GAAAA;AAC5D,IAAA,IAAI,CAACD,WAAa,EAAA;QAChB,OAAOC,KAAAA;AACT;AAEA,IAAA,MAAMC,gBAAgBC,eAAgBH,CAAAA,WAAAA,CAAAA;AAEtC,IAAA,MAAMI,YAAeH,GAAAA,KAAAA,CAAMI,MAAM,CAAC,CAACC,IAAAA,GAAAA;AACjC,QAAA,MAAMC,WAAWD,IAAME,EAAAA,IAAAA,EAAMC,KAAM,CAAA,GAAA,CAAI,CAAC,CAAE,CAAA;AAE1C,QAAA,IAAI,CAACF,QAAU,EAAA;YACb,OAAO,KAAA;AACT;AAEA,QAAA,IAAIL,aAAcQ,CAAAA,QAAQ,CAAC,MAAA,CAAA,IAAW,CAAC;AAAC,YAAA,OAAA;AAAS,YAAA,OAAA;AAAS,YAAA;SAAQ,CAACA,QAAQ,CAACH,QAAW,CAAA,EAAA;YACrF,OAAO,IAAA;AACT;QAEA,OAAOL,aAAAA,CAAcQ,QAAQ,CAACH,QAAAA,CAAAA;AAChC,KAAA,CAAA;IAEA,OAAOH,YAAAA;AACT;;;;"}