refactor(server): separate s3 & r2 storage to plugin (#5805)

This commit is contained in:
liuyi
2024-02-05 15:10:09 +00:00
parent 25e8a2a22f
commit 296d47f102
16 changed files with 201 additions and 92 deletions
@@ -0,0 +1,40 @@
import { OptionalModule } from '../../fundamentals';
import { registerStorageProvider } from '../../fundamentals/storage';
import { R2StorageProvider } from './providers/r2';
import { S3StorageProvider } from './providers/s3';
registerStorageProvider('cloudflare-r2', (config, bucket) => {
if (!config.plugins['cloudflare-r2']) {
throw new Error('Missing cloudflare-r2 storage provider configuration');
}
return new R2StorageProvider(config.plugins['cloudflare-r2'], bucket);
});
registerStorageProvider('aws-s3', (config, bucket) => {
if (!config.plugins['aws-s3']) {
throw new Error('Missing aws-s3 storage provider configuration');
}
return new S3StorageProvider(config.plugins['aws-s3'], bucket);
});
@OptionalModule({
requires: [
'plugins.cloudflare-r2.accountId',
'plugins.cloudflare-r2.credentials.accessKeyId',
'plugins.cloudflare-r2.credentials.secretAccessKey',
],
if: config => config.flavor.graphql,
})
export class CloudflareR2Module {}
@OptionalModule({
requires: [
'plugins.aws-s3.credentials.accessKeyId',
'plugins.aws-s3.credentials.secretAccessKey',
],
if: config => config.flavor.graphql,
})
export class AwsS3Module {}
export type { R2StorageConfig, S3StorageConfig } from './types';