package routes import ( "github.com/gofiber/fiber/v2" "github.com/break/junhong_cmp_fiber/internal/handler/admin" "github.com/break/junhong_cmp_fiber/internal/model/dto" "github.com/break/junhong_cmp_fiber/pkg/openapi" ) func registerStorageRoutes(router fiber.Router, handler *admin.StorageHandler, doc *openapi.Generator, basePath string) { storage := router.Group("/storage") groupPath := basePath + "/storage" Register(storage, doc, groupPath, "POST", "/upload-url", handler.GetUploadURL, RouteSpec{ Summary: "获取文件上传预签名 URL", Description: `## 文件上传流程 本接口用于获取对象存储的预签名上传 URL,实现前端直传文件到对象存储。 ### 完整流程 1. **调用本接口** 获取预签名 URL 和 file_key 2. **使用预签名 URL 上传文件** 发起 PUT 请求直接上传到对象存储 3. **调用业务接口** 使用 file_key 调用相关业务接口(如 ICCID 导入) ### 前端上传示例 ` + "```" + `javascript // 1. 获取预签名 URL const { data } = await api.post('/storage/upload-url', { file_name: 'cards.csv', content_type: 'text/csv', purpose: 'iot_import' }); // 2. 上传文件到对象存储 await fetch(data.upload_url, { method: 'PUT', headers: { 'Content-Type': 'text/csv' }, body: file }); // 3. 调用业务接口 await api.post('/iot-cards/import', { carrier_id: 1, batch_no: 'BATCH-2025-01', file_key: data.file_key }); ` + "```" + ` ### purpose 可选值 | 值 | 说明 | 生成路径格式 | |---|------|-------------| | iot_import | ICCID 导入 | imports/YYYY/MM/DD/uuid.csv | | export | 数据导出 | exports/YYYY/MM/DD/uuid.xlsx | | attachment | 附件上传 | attachments/YYYY/MM/DD/uuid.ext | ### 注意事项 - 预签名 URL 有效期 **15 分钟**,请及时使用 - 上传时 Content-Type 需与请求时一致 - file_key 在上传成功后永久有效,用于后续业务接口调用 - 上传失败时可重新调用本接口获取新的 URL`, Tags: []string{"对象存储"}, Input: new(dto.GetUploadURLRequest), Output: new(dto.GetUploadURLResponse), Auth: true, }) }