@jrmc/adonis-attachment
Version:
Turn any field on your Lucid model to an attachment data type
29 lines (28 loc) • 1.05 kB
JavaScript
/**
* @jrmc/adonis-attachment
*
* @license MIT
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
*/
import { configProvider } from '@adonisjs/core';
import { RuntimeException } from '@poppinss/utils';
export default class AttachmentProvider {
app;
#manager = null;
constructor(app) {
this.app = app;
}
register() {
this.app.container.singleton('jrmc.attachment', async () => {
const { AttachmentManager } = await import('../src/attachment_manager.js');
const attachmentConfig = this.app.config.get('attachment');
const config = await configProvider.resolve(this.app, attachmentConfig);
const drive = await this.app.container.make('drive.manager');
if (!config) {
throw new RuntimeException('Invalid config exported from "config/attachment.ts" file. Make sure to use the defineConfig method');
}
this.#manager = new AttachmentManager(config, drive);
return this.#manager;
});
}
}