https://github.com/the-software-compagny/nestjs_module_factorydrive
Factory drive module for NestJS framework
https://github.com/the-software-compagny/nestjs_module_factorydrive
abstract abstraction async bucket disk drive driver factory factorydrive file filesystem nestjs node nodejs npm promise spaces storage
Last synced: 4 months ago
JSON representation
Factory drive module for NestJS framework
- Host: GitHub
- URL: https://github.com/the-software-compagny/nestjs_module_factorydrive
- Owner: The-Software-Compagny
- License: mit
- Created: 2023-09-18T01:13:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T06:19:48.000Z (over 1 year ago)
- Last Synced: 2024-12-03T09:09:54.592Z (over 1 year ago)
- Topics: abstract, abstraction, async, bucket, disk, drive, driver, factory, factorydrive, file, filesystem, nestjs, node, nodejs, npm, promise, spaces, storage
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@streamkits/nestjs_module_factorydrive
- Size: 245 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
Factory drive module for NestJS framework
# NestJS Factory drive Module
Factory drive module for NestJS Framework
## Install dependencies
```bash
yarn add @the-software-compagny/nestjs_module_factorydrive
```
## Instanciate
```ts
// app.module.ts
import { FactorydriveModule, FactorydriveService } from '@the-software-compagny/nestjs_module_factorydrive'
@Module({
imports: [
// ...
FactorydriveModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
...config.get('factorydrive.options'),
}),
}),
// ...
],
})
export class AppModule {
public constructor(storage: FactorydriveService) {
// If you want to add a new driver you can use the registerDriver method
storage.registerDriver('s3', AwsS3Storage)
}
}
//config.ts
export default {
// ...
factorydrive: {
options: {
default: 'local',
disks: {
local: {
driver: 'local',
config: {
root: process.cwd() + '/storage',
},
},
s3: {
driver: 's3',
config: {
credentials: {
accessKeyId: '******',
secretAccessKey: '******',
},
endpoint: 'http://minio:9000/',
region: 'us-east-1',
bucket: 'example',
forcePathStyle: true,
},
},
},
},
},
// ...
}
```
## Usage
```ts
// filestorage.service.ts
import { FactorydriveService } from '@the-software-compagny/nestjs_module_factorydrive'
@Injectable()
export class FileStorageService {
public constructor(
@InjectFactorydrive() private readonly factorydrive: FactorydriveService,
) {}
public async uploadFile(path: string, file: Express.Multer.File): Promise {
const res = await this.factorydrive.getDisk('s3').put(path, file.buffer)
return res.raw
}
public async deleteFile(path: string): Promise {
await this.factorydrive.getDisk('s3').delete(path)
}
public async moveFile(path: string, target: string): Promise {
await this.factorydrive.getDisk('s3').move(path, target)
}
public async copyFile(path: string, target: string): Promise {
await this.factorydrive.getDisk('s3').copy(path, target)
}
public async listFiles(path: string): Promise {
await this.factorydrive.getDisk('s3').flatList(path)
}
}
```