fix(media): initialize backends only if configured
Some checks are pending
Docker / build-and-push (backend) (push) Waiting to run
Docker / build-and-push (frontend) (push) Waiting to run
E2E Tests / backend-sqlite (push) Waiting to run
E2E Tests / backend-mariadb (push) Waiting to run
E2E Tests / backend-postgres (push) Waiting to run
E2E Tests / Build test build of frontend (push) Waiting to run
E2E Tests / frontend-cypress (1) (push) Blocked by required conditions
E2E Tests / frontend-cypress (2) (push) Blocked by required conditions
E2E Tests / frontend-cypress (3) (push) Blocked by required conditions
Lint and check format / Lint files and check formatting (push) Waiting to run
REUSE Compliance Check / reuse (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Static Analysis / Njsscan code scanning (push) Waiting to run
Static Analysis / CodeQL analysis (push) Waiting to run
Run tests & build / Test and build with NodeJS 20 (push) Waiting to run

Signed-off-by: Erik Michelson <erik@michelson.eu>
This commit is contained in:
Erik Michelson 2025-05-17 10:41:04 +00:00 committed by Erik Michelson
parent 902abf72e6
commit b771f1c1bf
5 changed files with 55 additions and 47 deletions

View file

@ -35,9 +35,11 @@ export class AzureBackend implements MediaBackend {
private mediaConfig: MediaConfig,
) {
this.logger.setContext(AzureBackend.name);
this.config = (this.mediaConfig.backend as AzureMediaConfig).azure;
if (this.mediaConfig.backend.use === BackendType.AZURE) {
// only create the client if the backend is configured to azure
// only create the backend if azure is configured
if (this.mediaConfig.backend.use !== BackendType.AZURE) {
return;
}
this.config = this.mediaConfig.backend.azure;
const blobServiceClient = BlobServiceClient.fromConnectionString(
this.config.connectionString,
);
@ -45,7 +47,6 @@ export class AzureBackend implements MediaBackend {
blobServiceClient.credential as StorageSharedKeyCredential;
this.client = blobServiceClient.getContainerClient(this.config.container);
}
}
async saveFile(
uuid: string,

View file

@ -8,13 +8,11 @@ import { FileTypeResult } from 'file-type';
import { promises as fs } from 'fs';
import { join } from 'path';
import mediaConfiguration, {
FilesystemMediaConfig,
MediaConfig,
} from '../../config/media.config';
import mediaConfiguration, { MediaConfig } from '../../config/media.config';
import { MediaBackendError } from '../../errors/errors';
import { ConsoleLoggerService } from '../../logger/console-logger.service';
import { MediaBackend } from '../media-backend.interface';
import { BackendType } from './backend-type.enum';
@Injectable()
export class FilesystemBackend implements MediaBackend {
@ -26,9 +24,12 @@ export class FilesystemBackend implements MediaBackend {
private mediaConfig: MediaConfig,
) {
this.logger.setContext(FilesystemBackend.name);
this.uploadDirectory = (
this.mediaConfig.backend as FilesystemMediaConfig
).filesystem.uploadPath;
// only create the backend if local filesystem is configured
if (this.mediaConfig.backend.use !== BackendType.FILESYSTEM) {
this.uploadDirectory = '';
return;
}
this.uploadDirectory = this.mediaConfig.backend.filesystem.uploadPath;
}
async saveFile(

View file

@ -14,6 +14,7 @@ import mediaConfiguration, {
import { MediaBackendError } from '../../errors/errors';
import { ConsoleLoggerService } from '../../logger/console-logger.service';
import { MediaBackend } from '../media-backend.interface';
import { BackendType } from './backend-type.enum';
type UploadResult = {
data: {
@ -37,7 +38,11 @@ export class ImgurBackend implements MediaBackend {
private mediaConfig: MediaConfig,
) {
this.logger.setContext(ImgurBackend.name);
this.config = (this.mediaConfig.backend as ImgurMediaConfig).imgur;
// only create the backend if imgur is configured
if (this.mediaConfig.backend.use !== BackendType.IMGUR) {
return;
}
this.config = this.mediaConfig.backend.imgur;
}
async saveFile(uuid: string, buffer: Buffer): Promise<string> {

View file

@ -33,6 +33,7 @@ export class S3Backend implements MediaBackend {
private mediaConfig: MediaConfig,
) {
this.logger.setContext(S3Backend.name);
// only create the backend if s3 is configured
if (this.mediaConfig.backend.use !== BackendType.S3) {
return;
}

View file

@ -29,15 +29,16 @@ export class WebdavBackend implements MediaBackend {
private mediaConfig: MediaConfig,
) {
this.logger.setContext(WebdavBackend.name);
if (this.mediaConfig.backend.use === BackendType.WEBDAV) {
// only create the backend if WebDAV is configured
if (this.mediaConfig.backend.use !== BackendType.WEBDAV) {
return;
}
this.config = this.mediaConfig.backend.webdav;
const url = new URL(this.config.connectionString);
this.baseUrl = url.toString();
if (this.config.uploadDir && this.config.uploadDir !== '') {
this.baseUrl = WebdavBackend.joinURL(
this.baseUrl,
this.config.uploadDir,
);
this.baseUrl = WebdavBackend.joinURL(this.baseUrl, this.config.uploadDir);
}
this.authHeader = WebdavBackend.generateBasicAuthHeader(
url.username,
@ -60,7 +61,6 @@ export class WebdavBackend implements MediaBackend {
throw new Error(`Can't access ${this.baseUrl}`);
});
}
}
async saveFile(
uuid: string,