@adonisjs/drive
Version:
A thin wrapper on top of Flydrive to work seamlessly with AdonisJS
77 lines (76 loc) • 2.77 kB
TypeScript
import { DriveManager } from 'flydrive';
import type { ApplicationService } from '@adonisjs/core/types';
import type { DriveDisks, DriveService, WriteOptions } from '../src/types.js';
/**
* Extending the container with a custom service
*/
declare module '@adonisjs/core/types' {
interface ContainerBindings {
'drive.manager': DriveService;
}
}
/**
* Extending BodyParser Multipart file with "moveToDisk"
* method to move file from the local filesystem to
* a drive disk
*/
declare module '@adonisjs/core/bodyparser' {
interface MultipartFile {
/**
* Move user uploaded file from the tmp directory
* to a Drive disk
*/
moveToDisk(key: string, disk?: keyof DriveDisks, options?: WriteOptions & {
/**
* When using "stream", the file from the tmpPath will be read
* as a stream and written to the cloud provider.
*
* Whereas, in case of "buffer", the entire file will be first
* read into the memory and then sent to the cloud provider. Some
* cloud providers like supabase cannot work with the "stream" option.
*/
moveAs?: 'stream' | 'buffer';
}): Promise<void>;
moveToDisk(key: string, options?: WriteOptions & {
/**
* When using "stream", the file from the tmpPath will be read
* as a stream and written to the cloud provider.
*
* Whereas, in case of "buffer", the entire file will be first
* read into the memory and then sent to the cloud provider. Some
* cloud providers like supabase cannot work with the "stream" option.
*/
moveAs?: 'stream' | 'buffer';
}): Promise<void>;
}
}
/**
* Drive Provider registers a singleton drive manager services
* to the IoC container and wires up the routing to serve
* files from the "fs" driver.
*/
export default class DriveProvider {
#private;
protected app: ApplicationService;
constructor(app: ApplicationService);
/**
* Defines the template engine on the message class to
* render templates
*/
protected registerViewHelpers(drive: DriveManager<any>): Promise<void>;
/**
* Extending BodyParser Multipart file with "moveToDisk"
* method to move file from the local filesystem to
* a drive disk
*/
protected extendMultipartFile(drive: DriveManager<any>): Promise<void>;
register(): void;
/**
* The boot method resolves drive and router to register
* the routes for the locally served services.
*
* The routes must be defined before the application has
* started.
*/
boot(): Promise<void>;
}