mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 16:44:49 -04:00
Implement filesystem media backend
This backend stores uploaded media into files on the local filesystem. This commit also adds a `BackendType` enum, which can be used to distinguish different media backends. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
db15afcb88
commit
dc49bfcccb
2 changed files with 32 additions and 0 deletions
6
src/media/backends/backend-type.enum.ts
Normal file
6
src/media/backends/backend-type.enum.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export enum BackendType {
|
||||||
|
FILEYSTEM = 'filesystem',
|
||||||
|
S3 = 's3',
|
||||||
|
IMGUR = 'imgur',
|
||||||
|
AZURE = 'azure',
|
||||||
|
}
|
26
src/media/backends/filesystem-backend.ts
Normal file
26
src/media/backends/filesystem-backend.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { MediaBackend } from '../media-backend.interface';
|
||||||
|
import { BackendData } from '../media-upload.entity';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
|
||||||
|
export class FilesystemBackend implements MediaBackend {
|
||||||
|
async saveFile(
|
||||||
|
buffer: Buffer,
|
||||||
|
fileName: string,
|
||||||
|
): Promise<[string, BackendData]> {
|
||||||
|
// TODO: Get uploads directory from config
|
||||||
|
const uploadDirectory = './uploads';
|
||||||
|
// TODO: Add server address to url
|
||||||
|
const filePath = join(uploadDirectory, fileName);
|
||||||
|
await fs.writeFile(filePath, buffer, null);
|
||||||
|
return ['/' + filePath, null];
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteFile(fileName: string, backendData: BackendData): Promise<void> {
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFileURL(fileNam: string, backendData: BackendData): Promise<string> {
|
||||||
|
return Promise.resolve('');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue