mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-01 15:48:32 -04:00
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:
parent
9743018591
commit
3da16baeae
3 changed files with 35 additions and 13 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue