mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 00:54:43 -04:00
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
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:
parent
902abf72e6
commit
b771f1c1bf
5 changed files with 55 additions and 47 deletions
|
@ -35,16 +35,17 @@ 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
|
||||
const blobServiceClient = BlobServiceClient.fromConnectionString(
|
||||
this.config.connectionString,
|
||||
);
|
||||
this.credential =
|
||||
blobServiceClient.credential as StorageSharedKeyCredential;
|
||||
this.client = blobServiceClient.getContainerClient(this.config.container);
|
||||
// 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,
|
||||
);
|
||||
this.credential =
|
||||
blobServiceClient.credential as StorageSharedKeyCredential;
|
||||
this.client = blobServiceClient.getContainerClient(this.config.container);
|
||||
}
|
||||
|
||||
async saveFile(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -29,37 +29,37 @@ export class WebdavBackend implements MediaBackend {
|
|||
private mediaConfig: MediaConfig,
|
||||
) {
|
||||
this.logger.setContext(WebdavBackend.name);
|
||||
if (this.mediaConfig.backend.use === BackendType.WEBDAV) {
|
||||
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.authHeader = WebdavBackend.generateBasicAuthHeader(
|
||||
url.username,
|
||||
url.password,
|
||||
);
|
||||
fetch(this.baseUrl, {
|
||||
method: 'PROPFIND',
|
||||
headers: {
|
||||
Accept: 'text/plain', // eslint-disable-line @typescript-eslint/naming-convention
|
||||
Authorization: this.authHeader, // eslint-disable-line @typescript-eslint/naming-convention
|
||||
Depth: '0', // eslint-disable-line @typescript-eslint/naming-convention
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`Can't access ${this.baseUrl}`);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
throw new Error(`Can't access ${this.baseUrl}`);
|
||||
});
|
||||
// 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.authHeader = WebdavBackend.generateBasicAuthHeader(
|
||||
url.username,
|
||||
url.password,
|
||||
);
|
||||
fetch(this.baseUrl, {
|
||||
method: 'PROPFIND',
|
||||
headers: {
|
||||
Accept: 'text/plain', // eslint-disable-line @typescript-eslint/naming-convention
|
||||
Authorization: this.authHeader, // eslint-disable-line @typescript-eslint/naming-convention
|
||||
Depth: '0', // eslint-disable-line @typescript-eslint/naming-convention
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`Can't access ${this.baseUrl}`);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
throw new Error(`Can't access ${this.baseUrl}`);
|
||||
});
|
||||
}
|
||||
|
||||
async saveFile(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue