UNPKG

@jrmc/adonis-attachment

Version:

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

32 lines (31 loc) 1.05 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; try { const { default: value } = await converter.converter(); const Converter = value; converters[converterName] = new Converter(converter.options, binConfig); } catch (error) { console.error(`Failed to load converter ${converterName}:`, error); } } } return { ...config, converters, }; }); }