mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
FilesystemBackend: Use scoped appConfig
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
75b6d3cc2b
commit
9f170bca4c
3 changed files with 29 additions and 18 deletions
|
@ -4,10 +4,10 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { promises as fs } from 'fs';
|
||||
import { join } from 'path';
|
||||
import applicationConfig, { AppConfig } from '../../config/app.config';
|
||||
import { ConsoleLoggerService } from '../../logger/console-logger.service';
|
||||
import { MediaBackend } from '../media-backend.interface';
|
||||
import { BackendData } from '../media-upload.entity';
|
||||
|
@ -18,24 +18,11 @@ export class FilesystemBackend implements MediaBackend {
|
|||
|
||||
constructor(
|
||||
private readonly logger: ConsoleLoggerService,
|
||||
private configService: ConfigService,
|
||||
@Inject(applicationConfig.KEY)
|
||||
private appConfig: AppConfig,
|
||||
) {
|
||||
this.logger.setContext(FilesystemBackend.name);
|
||||
this.uploadDirectory = configService.get<string>(
|
||||
'media.backend.filesystem.uploadPath',
|
||||
);
|
||||
}
|
||||
|
||||
private getFilePath(fileName: string): string {
|
||||
return join(this.uploadDirectory, fileName);
|
||||
}
|
||||
|
||||
private async ensureDirectory() {
|
||||
try {
|
||||
await fs.access(this.uploadDirectory);
|
||||
} catch (e) {
|
||||
await fs.mkdir(this.uploadDirectory);
|
||||
}
|
||||
this.uploadDirectory = appConfig.media.backend.filesystem.uploadPath;
|
||||
}
|
||||
|
||||
async saveFile(
|
||||
|
@ -58,4 +45,16 @@ export class FilesystemBackend implements MediaBackend {
|
|||
// TODO: Add server address to url
|
||||
return Promise.resolve('/' + filePath);
|
||||
}
|
||||
|
||||
private getFilePath(fileName: string): string {
|
||||
return join(this.uploadDirectory, fileName);
|
||||
}
|
||||
|
||||
private async ensureDirectory() {
|
||||
try {
|
||||
await fs.access(this.uploadDirectory);
|
||||
} catch (e) {
|
||||
await fs.mkdir(this.uploadDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue