Skip to content

feat: add MinIO file storage service with upload and download capabilities#11

Merged
c121914yu merged 10 commits intolabring:mainfrom
sd0ric4:s3
Jun 25, 2025
Merged

feat: add MinIO file storage service with upload and download capabilities#11
c121914yu merged 10 commits intolabring:mainfrom
sd0ric4:s3

Conversation

@sd0ric4
Copy link
Contributor

@sd0ric4 sd0ric4 commented Jun 24, 2025

  • Updated package.json to include MinIO and UUID dependencies.
  • Created config.ts for file storage configuration, including max file size, retention days, and MinIO credentials.
  • Implemented service.ts to handle file uploads, downloads, and metadata management using MinIO.
  • Added upload.ts to support various file input types (network, local, base64, buffer) for uploading files.
  • Introduced Zod schemas for input validation and structured response handling.
  • Implemented logging for connection tests, bucket initialization, and error handling.

…ities

- Updated package.json to include MinIO and UUID dependencies.
- Created config.ts for file storage configuration, including max file size, retention days, and MinIO credentials.
- Implemented service.ts to handle file uploads, downloads, and metadata management using MinIO.
- Added upload.ts to support various file input types (network, local, base64, buffer) for uploading files.
- Introduced Zod schemas for input validation and structured response handling.
- Implemented logging for connection tests, bucket initialization, and error handling.
- Removed legacy upload.ts file and migrated its logic to a new S3-based implementation.
- Introduced new configuration and controller files for S3 integration.
- Implemented file upload service with support for multiple input types (network, local, base64, buffer).
- Added validation schemas using Zod for input and output.
- Created worker support for file service initialization and upload handling.
- Enhanced logging for better traceability during file operations.
await this.ensureInitialized();

if (fileBuffer.length > this.config.maxFileSize) {
throw new Error(`File size ${fileBuffer.length} exceeds limit ${this.config.maxFileSize}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Promise.reject

fileBuffer,
fileBuffer.length,
{
'Content-Type': 'application/octet-stream', // 强制下载,不预览
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个会导致覆盖原来的 content type 么

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像有 attachment 就好了吧


const metadata = await this.uploadFile(buffer, filename);
const inputType = validatedInput.url
? 'network'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉去掉,这些log 都啥用呢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还不如每个 function 里 log 呢

}
await this.setBucketDownloadOnly();
} catch (error) {
addLog.error('Failed to initialize bucket:', error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addlog.error(xxx,error)

addLog.error('Failed to initialize bucket:', error);
if (error instanceof Error && error.message.includes('Method Not Allowed')) {
addLog.warn('Method Not Allowed - bucket may exist with different permissions');
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抛错

// ================================

// 创建默认的文件服务实例
export const fileService = new FileService();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全局存一个实例。
worker 里传实例进去看能不能用

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

系统初始化就增加 minio 实例化流程:
const file = new Fileserver()
await file.initBucket()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抽个 init.ts。

@c121914yu c121914yu merged commit bff23ba into labring:main Jun 25, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants