0.0.3 • Published 2 years ago
@scholten.dev/file-store v0.0.3
File store
Typescript package which interfaces the filestore api.
Usage
Usage in plain nodejs
const fileStore = new FileStore('domainname.com', 'userId', 'api-key');
const file = await fileStore.getFile('myfile.jpg');
const text = arrayBufferToText(file);
const buffer = arrayBufferToBuffer(file);
const filePath = await fileStore.saveFile('myfile.jpg', 'image/jpeg', bufferToBase64(buffer));
await fileStore.deleteFile('myfile.jpg);
Usage in nestjs
import { Global, Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FileStore } from '@scholten.dev/file-store';
export enum Globals {
FILE_STORE = 'filestore',
}
@Global()
@Module({
providers: [
{
provide: Globals.FILE_STORE,
inject: [ConfigService],
useFactory: async (configService: ConfigService) =>
new FileStore(
configService.getOrThrow('FILESTORE_DOMAIN'),
configService.getOrThrow('FILESTORE_USERID'),
configService.getOrThrow('FILESTORE_APIKEY'),
),
},
],
exports: [Globals.FILE_STORE],
})
export class GlobalModule {}