- added own provider for drive methods
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m13s
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m13s
- renamed middleware Role and Can to role_middleware and can_middleware - added some typing for inertia vue3 components - npm updates
This commit is contained in:
parent
cb51a4136f
commit
296c8fd46e
67 changed files with 2516 additions and 1914 deletions
154
providers/drive/src/drive_manager.ts
Normal file
154
providers/drive/src/drive_manager.ts
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
import type { ApplicationService } from '@adonisjs/core/types';
|
||||
import { Manager } from '@poppinss/manager';
|
||||
import { Exception } from '@poppinss/utils';
|
||||
import { DriverContract, DriversList, DriveConfig, DriveListItem, DirectoryListingContract, LocalDriverConfig } from './types/drive.js';
|
||||
// import { LocalDriver } from './drivers/local.js';
|
||||
import { LocalDriver } from '../drivers/local.js';
|
||||
|
||||
type test = {
|
||||
[P in keyof DriversList]: DriversList[P];
|
||||
};
|
||||
// type DriveMappings = {
|
||||
// local: string
|
||||
// fake: string
|
||||
// }
|
||||
|
||||
// interface DriversList {
|
||||
// local: {
|
||||
// implementation: LocalDriverContract;
|
||||
// config: LocalDriverConfig;
|
||||
// };
|
||||
// }
|
||||
|
||||
// type DriverConfig = {
|
||||
// disk: keyof DriversList
|
||||
// disks: {
|
||||
// [K in keyof DriversList]: any
|
||||
// }
|
||||
// }
|
||||
|
||||
// const mailerConfig: DriveConfig = {
|
||||
// disk: 'local',
|
||||
|
||||
// disks: {
|
||||
// local: {
|
||||
// driver: 'local',
|
||||
// root: '',
|
||||
// visibility: '',
|
||||
// serveFiles: false,
|
||||
// basePath: '',
|
||||
// },
|
||||
|
||||
// // 'fake': {
|
||||
// // driver: 'fake',
|
||||
// // root: '',
|
||||
// // },
|
||||
// },
|
||||
// };
|
||||
|
||||
export default class DriveManager extends Manager<
|
||||
ApplicationService,
|
||||
DriverContract,
|
||||
DriverContract,
|
||||
{
|
||||
[P in keyof DriversList]: DriversList[P]['implementation'];
|
||||
}
|
||||
> {
|
||||
protected singleton = true;
|
||||
private config;
|
||||
/**
|
||||
* Find if drive is ready to be used
|
||||
*/
|
||||
private isReady: boolean;
|
||||
|
||||
protected getDefaultMappingName() {
|
||||
return this.config.disk; // "local"
|
||||
}
|
||||
|
||||
protected getMappingConfig(mappingName: string) {
|
||||
return this.config.disks[mappingName];
|
||||
}
|
||||
|
||||
protected getMappingDriver(mappingName: string) {
|
||||
return this.config.disks[mappingName].driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make instance of the local driver
|
||||
*/
|
||||
protected createLocal(diskName: keyof DriversList, config: LocalDriverConfig) {
|
||||
// const { LocalDriver } = await import('../drivers/local.js');
|
||||
return new LocalDriver(diskName, config);
|
||||
}
|
||||
|
||||
constructor(application: ApplicationService, config: DriveConfig) {
|
||||
super(application);
|
||||
this.config = config;
|
||||
|
||||
/**
|
||||
* Find if drive is ready to be used
|
||||
*/
|
||||
this.isReady = false;
|
||||
|
||||
this.validateConfig();
|
||||
}
|
||||
/**
|
||||
* Validate config
|
||||
*/
|
||||
private validateConfig() {
|
||||
if (!this.config) {
|
||||
return;
|
||||
}
|
||||
// const validator = new utils_1.ManagerConfigValidator(this.config, 'drive', 'config/drive');
|
||||
// validator.validateDefault('disk');
|
||||
// validator.validateList('disks', 'disk');
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve instance for a disk
|
||||
*/
|
||||
use(disk?: keyof test): DriversList[keyof DriversList]['implementation'] {
|
||||
if (!this.isReady) {
|
||||
throw new Exception('Missing configuration for drive. Visit https://bit.ly/2WnR5j9 for setup instructions', {
|
||||
status: 500,
|
||||
code: 'E_MISSING_DRIVE_CONFIG',
|
||||
});
|
||||
}
|
||||
disk = disk || this.getDefaultMappingName();
|
||||
// if (this.fakeDrive.isFaked(disk)) {
|
||||
// return this.fakeDrive.use(disk);
|
||||
// }
|
||||
return super.use(disk);
|
||||
}
|
||||
|
||||
/**
|
||||
* A boolean to find if the location path exists or not
|
||||
*/
|
||||
exists(location: string): Promise<boolean> {
|
||||
const driver = this.use();
|
||||
return driver.exists(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given location path
|
||||
*/
|
||||
delete(location: string): Promise<void> {
|
||||
const driver = this.use();
|
||||
return driver.delete(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a listing directory iterator for given location.
|
||||
*/
|
||||
list(location: string): DirectoryListingContract<DriverContract, DriveListItem> {
|
||||
const driver = this.use();
|
||||
if (typeof driver.list !== 'function') {
|
||||
throw new Exception(`List is not supported by the "${driver.name}" driver.`, {
|
||||
status: 500,
|
||||
code: 'E_LIST_NOT_SUPPORTED',
|
||||
});
|
||||
}
|
||||
return driver.list(location);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue