Files
upage-git/app/lib/storage/index.server.ts
2025-09-24 17:02:44 +08:00

36 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createScopedLogger } from '~/lib/.server/logger';
import { LocalStorageProvider } from './local-provider.server';
import type { StorageProvider } from './types';
const logger = createScopedLogger('storage');
/**
* 获取存储目录配置
* @returns 存储目录路径
*/
const getStorageDir = (): string | undefined => {
// 如果在Docker环境中运行使用环境变量中的配置
if (process.env.RUNNING_IN_DOCKER === 'true' && process.env.STORAGE_DIR) {
logger.debug('使用Docker环境中的存储目录', JSON.stringify({ dir: process.env.STORAGE_DIR }));
return process.env.STORAGE_DIR;
}
// 使用环境变量中的配置
if (process.env.STORAGE_DIR) {
logger.debug('使用环境变量中的存储目录', JSON.stringify({ dir: process.env.STORAGE_DIR }));
return process.env.STORAGE_DIR;
}
// 默认使用项目根目录下的 public/uploads 目录
logger.debug('使用默认存储目录');
return undefined;
};
const createStorageProvider = (): StorageProvider => {
return new LocalStorageProvider(getStorageDir());
};
export const storageProvider = createStorageProvider();
export * from './types';