import { DiskOptions , StorageDriver , StorageDriver$FileMetadataResponse , StorageDriver$PutFileResponse , StorageDriver$RenameFileResponse , } from "../interfaces" ; import { join } from "path" ; import * as fs from "fs-extra" ; export class Local implements StorageDriver { constructor ( private disk , private config ) { } param path param fileContent async put ( filePath , fileContent ) { const res = await fs . outputFile ( join ( this . config . basePath || "" , filePath ) , fileContent ) ; return { path : join ( this . config . basePath || "" , filePath ) , url : "" } ; } param path async get ( filePath ) { const res = await fs . readFile ( join ( this . config . basePath || "" , filePath ) ) ; return res ; } param path async meta ( filePath ) { const path = join ( this . config . basePath || "" , filePath ) ; const res = await fs . stat ( path ) ; return { path , contentLength : res . size , lastModified : res . mtime , } ; } param path signedUrl ( filePath , expire = 10 ) { return "" ; } param path async exists ( filePath ) { return fs . pathExists ( join ( this . config . basePath || "" , filePath ) ) ; } param path async missing ( filePath ) { return ! ( await this . exists ( filePath ) ) ; } param path url ( fileName ) { if ( this . config . hasOwnProperty ( "baseUrl" ) ) { const filePath = join ( "public" , fileName ) ; return `${ this . config . basePath }/${ filePath }` ; } else { return "" ; } } param path async delete ( filePath ) { try { await fs . remove ( join ( this . config . basePath || "" , filePath ) ) ; } catch ( e ) { } return true ; } param path param newPath async copy ( path , newPath ) { const res = await fs . copy ( join ( this . config . basePath || "" , path ) , join ( this . config . basePath || "" , newPath ) , { overwrite : true } ) ; return { path : join ( this . config . basePath || "" , newPath ) , url : this . url ( newPath ) , } ; } param path param newPath async move ( path , newPath ) { await this . copy ( path , newPath ) ; await this . delete ( path ) ; return { path : join ( this . config . basePath || "" , newPath ) , url : this . url ( newPath ) , } ; } /**
     * Get instance of driver's client.
     */ getClient ( ) { return null ; } /**
     * Get config of the driver's instance.
     */ getConfig ( ) { return this . config ; } }