Files
AIclinicalresearch/backend/src/common/storage/StorageAdapter.ts
HaHafeng 8bba33ac89 feat(platform): Implement platform infrastructure with cloud-native support
- Add storage service (LocalAdapter + OSSAdapter stub)
- Add database connection pool with graceful shutdown
- Add logging system with winston (JSON format)
- Add environment config management
- Add async job queue (MemoryQueue + DatabaseQueue stub)
- Add cache service (MemoryCache + RedisCache stub)
- Add health check endpoints for SAE
- Add monitoring metrics for DB, memory, API

Key Features:
- Zero-code switching between local and cloud environments
- Adapter pattern for multi-environment support
- Backward compatible with legacy modules
- Ready for Aliyun Serverless deployment

Related: Platform Infrastructure Planning (docs/09-鏋舵瀯瀹炴柦/04-骞冲彴鍩虹璁炬柦瑙勫垝.md)
2025-11-17 08:31:23 +08:00

67 lines
1.6 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.
/**
* 存储适配器接口
*
* 支持多种存储实现:
* - LocalAdapter: 本地文件系统(开发环境)
* - OSSAdapter: 阿里云OSS生产环境
*
* 使用场景:
* - 上传PDF文献文件
* - 上传Excel批量导入文件
* - 上传用户头像等静态资源
*
* @example
* ```typescript
* import { storage } from '@/common/storage'
*
* // 上传文件
* const url = await storage.upload('literature/123.pdf', buffer)
*
* // 下载文件
* const buffer = await storage.download('literature/123.pdf')
*
* // 删除文件
* await storage.delete('literature/123.pdf')
*
* // 获取URL
* const url = storage.getUrl('literature/123.pdf')
* ```
*/
export interface StorageAdapter {
/**
* 上传文件
* @param key 文件存储路径相对路径literature/123.pdf
* @param buffer 文件内容(二进制数据)
* @returns 文件访问URL
*/
upload(key: string, buffer: Buffer): Promise<string>
/**
* 下载文件
* @param key 文件存储路径
* @returns 文件内容(二进制数据)
*/
download(key: string): Promise<Buffer>
/**
* 删除文件
* @param key 文件存储路径
*/
delete(key: string): Promise<void>
/**
* 获取文件访问URL
* @param key 文件存储路径
* @returns 文件访问URL本地http://localhost:3001/uploads/xxxOSShttps://xxx.oss-cn-hangzhou.aliyuncs.com/xxx
*/
getUrl(key: string): string
/**
* 检查文件是否存在
* @param key 文件存储路径
* @returns 是否存在
*/
exists(key: string): Promise<boolean>
}