Skip to content

Commit

Permalink
move envToModuleMappings to file-uploader interface file
Browse files Browse the repository at this point in the history
  • Loading branch information
arafubeatbox committed Sep 2, 2024
1 parent eac51eb commit 49f8b4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 9 additions & 1 deletion apps/app/src/interfaces/file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FileUploadType = {

export type FileUploadType = typeof FileUploadType[keyof typeof FileUploadType]

// file upload type strings you can specify in the env var
// file upload type strings you can specify in the env variable
export const FileUploadTypeForEnvVar = {
...FileUploadType,
mongo: 'mongo',
Expand All @@ -18,3 +18,11 @@ export const FileUploadTypeForEnvVar = {
} as const;

export type FileUploadTypeForEnvVar = typeof FileUploadTypeForEnvVar[keyof typeof FileUploadTypeForEnvVar]

// mapping from env variable to actual module name
export const EnvToModuleMappings = {
...FileUploadTypeForEnvVar,
mongo: 'gridfs',
mongodb: 'gridfs',
gcp: 'gcs',
} as const;
11 changes: 2 additions & 9 deletions apps/app/src/server/service/file-uploader/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileUploadTypeForEnvVar } from '~/interfaces/file-uploader';
import { EnvToModuleMappings } from '~/interfaces/file-uploader';
import type Crowi from '~/server/crowi';
import loggerFactory from '~/utils/logger';

Expand All @@ -10,15 +10,8 @@ export type { FileUploader } from './file-uploader';

const logger = loggerFactory('growi:service:FileUploaderServise');

const envToModuleMappings = {
...FileUploadTypeForEnvVar,
mongo: 'gridfs',
mongodb: 'gridfs',
gcp: 'gcs',
} as const;

export const getUploader = (crowi: Crowi): FileUploader => {
const method = envToModuleMappings[configManager.getConfig('crowi', 'app:fileUploadType')];
const method = EnvToModuleMappings[configManager.getConfig('crowi', 'app:fileUploadType')];
const modulePath = `./${method}`;
const uploader = require(modulePath)(crowi);

Expand Down

0 comments on commit 49f8b4a

Please sign in to comment.