mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Full CLI rework and repair
This commit is contained in:
parent
cbc6f46103
commit
28c73bc62a
9 changed files with 1739 additions and 1114 deletions
|
|
@ -32,6 +32,24 @@ export class MediaBackend {
|
|||
public backend: MediaBackendType
|
||||
) {}
|
||||
|
||||
static async fromBackendType(
|
||||
backend: MediaBackendType,
|
||||
config: ConfigType
|
||||
): Promise<MediaBackend> {
|
||||
switch (backend) {
|
||||
case MediaBackendType.LOCAL:
|
||||
return new (await import("./backends/local")).LocalMediaBackend(
|
||||
config
|
||||
);
|
||||
case MediaBackendType.S3:
|
||||
return new (await import("./backends/s3")).S3MediaBackend(
|
||||
config
|
||||
);
|
||||
default:
|
||||
throw new Error(`Unknown backend type: ${backend as any}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getBackendType() {
|
||||
return this.backend;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,39 @@ describe("MediaBackend", () => {
|
|||
expect(mediaBackend.getBackendType()).toEqual(MediaBackendType.S3);
|
||||
});
|
||||
|
||||
describe("fromBackendType", () => {
|
||||
it("should return a LocalMediaBackend instance for LOCAL backend type", async () => {
|
||||
const backend = await MediaBackend.fromBackendType(
|
||||
MediaBackendType.LOCAL,
|
||||
mockConfig
|
||||
);
|
||||
expect(backend).toBeInstanceOf(LocalMediaBackend);
|
||||
});
|
||||
|
||||
it("should return a S3MediaBackend instance for S3 backend type", async () => {
|
||||
const backend = await MediaBackend.fromBackendType(
|
||||
MediaBackendType.S3,
|
||||
{
|
||||
s3: {
|
||||
endpoint: "localhost:4566",
|
||||
region: "us-east-1",
|
||||
bucket_name: "test-bucket",
|
||||
access_key: "test-access",
|
||||
public_url: "test",
|
||||
secret_access_key: "test-secret",
|
||||
},
|
||||
} as ConfigType
|
||||
);
|
||||
expect(backend).toBeInstanceOf(S3MediaBackend);
|
||||
});
|
||||
|
||||
it("should throw an error for unknown backend type", () => {
|
||||
expect(
|
||||
MediaBackend.fromBackendType("unknown" as any, mockConfig)
|
||||
).rejects.toThrow("Unknown backend type: unknown");
|
||||
});
|
||||
});
|
||||
|
||||
it("should check if images should be converted", () => {
|
||||
expect(mediaBackend.shouldConvertImages(mockConfig)).toBe(true);
|
||||
mockConfig.media.conversion.convert_images = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue