update license structures and setup file storage services
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { UploadedFileTypes } from '@/common/enums/enums'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { StorageService } from '../storage/storage.service'
|
||||
|
||||
@Injectable()
|
||||
export class UploaderService {
|
||||
constructor(private readonly storageService: StorageService) {}
|
||||
|
||||
async uploadFile(file: Express.Multer.File, type: UploadedFileTypes) {
|
||||
const uploaded = await this.storageService.uploadFile(file, type)
|
||||
return uploaded
|
||||
|
||||
// await fs.mkdir(dirPath, { recursive: true })
|
||||
// await fs.writeFile(filePath, buffer)
|
||||
|
||||
// Return a URL path, e.g. /uploads/{accountId}/{type}/{filename}
|
||||
// return `/uploads/${type}/${filename}`
|
||||
}
|
||||
|
||||
async deleteFile(url: string) {
|
||||
const key = url?.split('/').pop()
|
||||
if (key) {
|
||||
return await this.storageService.deleteFile(key)
|
||||
}
|
||||
return {}
|
||||
|
||||
// await fs.mkdir(dirPath, { recursive: true })
|
||||
// await fs.writeFile(filePath, buffer)
|
||||
|
||||
// Return a URL path, e.g. /uploads/{accountId}/{type}/{filename}
|
||||
// return `/uploads/${type}/${filename}`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user