UNPKG

@jrmc/adonis-attachment

Version:

Turn any field on your Lucid model to an attachment data type

37 lines (36 loc) 1.36 kB
/** * @jrmc/adonis-attachment * * @license MIT * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr> */ import { configProvider } from '@adonisjs/core'; export function defineConfig(config) { return configProvider.create(async (_app) => { const convertersList = Object.keys(config.converters || {}); const converters = {}; if (config.converters) { for (let converterName of convertersList) { const converter = config.converters[converterName]; const binConfig = config.bin; if (converter.converter === undefined) { converter.converter = () => import('@jrmc/adonis-attachment/converters/autodetect_converter'); } try { const { default: value } = await converter.converter(); const { converter: _, ...opt } = converter; const options = converter.options || opt; const Converter = value; converters[converterName] = new Converter(options, binConfig); } catch (error) { console.error(`Failed to load converter ${converterName}:`, error); } } } return { ...config, converters, }; }); }