FilesystemBackend: Implement deleteFile and getFileURL.

We use `fs.unlink` instead of `fs.rm`, as the latter is only available in the fsPromises API since Node 14.14

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-10-17 16:24:30 +02:00
parent 9743018591
commit 3da16baeae
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 35 additions and 13 deletions

View file

@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { InjectRepository } from '@nestjs/typeorm';
import * as FileType from 'file-type';
import { Repository } from 'typeorm';
@ -16,6 +17,7 @@ export class MediaService {
private mediaUploadRepository: Repository<MediaUpload>,
private notesService: NotesService,
private usersService: UsersService,
private moduleRef: ModuleRef,
) {}
public async saveFile(file: MulterFile, username: string, noteId: string) {
@ -35,7 +37,7 @@ export class MediaService {
fileTypeResult.ext,
BackendType.FILEYSTEM,
);
const backend = new FilesystemBackend();
const backend = this.moduleRef.get(FilesystemBackend);
const [url, backendData] = await backend.saveFile(
file.buffer,
mediaUpload.id,