mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-03 23:36:21 +02:00
70 lines
2.4 KiB
JavaScript
70 lines
2.4 KiB
JavaScript
"use strict";
|
|
/*
|
|
* @adonisjs/drive
|
|
*
|
|
* (c) Harminder Virk <virk@adonisjs.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
/**
|
|
* Registers drive with the IoC container
|
|
*/
|
|
class DriveProvider {
|
|
constructor(app) {
|
|
this.app = app;
|
|
}
|
|
/**
|
|
* Register drive with the container
|
|
*/
|
|
registerDrive() {
|
|
this.app.container.singleton('Adonis/Core/Drive', () => {
|
|
const { DriveManager } = require('../src/DriveManager');
|
|
const Router = this.app.container.resolveBinding('Adonis/Core/Route');
|
|
const Config = this.app.container.resolveBinding('Adonis/Core/Config');
|
|
const Logger = this.app.container.resolveBinding('Adonis/Core/Logger');
|
|
return new DriveManager(this.app, Router, Logger, Config.get('drive'));
|
|
});
|
|
}
|
|
/**
|
|
* Register routes for disks using "local" driver.
|
|
*/
|
|
defineDriveRoutes() {
|
|
this.app.container.withBindings(['Adonis/Core/Config', 'Adonis/Core/Route', 'Adonis/Core/Logger'], (Config, Router, Logger) => {
|
|
/**
|
|
* Do not attempt to resolve Drive from the container when there is
|
|
* no configuration in place.
|
|
*
|
|
* This is a make shift arrangement. Later, we will have a universal
|
|
* approach to disabling modules
|
|
*/
|
|
const driveConfig = Config.get('drive');
|
|
if (!driveConfig) {
|
|
return;
|
|
}
|
|
const Drive = this.app.container.resolveBinding('Adonis/Core/Drive');
|
|
const { LocalFileServer } = require('../src/LocalFileServer');
|
|
Object.keys(driveConfig.disks).forEach((diskName) => {
|
|
const diskConfig = driveConfig.disks[diskName];
|
|
if (diskConfig.driver === 'local' && diskConfig.serveFiles) {
|
|
new LocalFileServer(diskName, diskConfig, Drive.use(diskName), Router, Logger).registerRoute();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* Registering all required bindings to the container
|
|
*/
|
|
register() {
|
|
this.registerDrive();
|
|
}
|
|
/**
|
|
* Register drive routes
|
|
*/
|
|
boot() {
|
|
this.defineDriveRoutes();
|
|
}
|
|
}
|
|
exports.default = DriveProvider;
|