buildOutputFileItems builds the output file items for response
(files []*model.UploadFile)
| 4263 | |
| 4264 | // buildOutputFileItems builds the output file items for response |
| 4265 | func buildOutputFileItems(files []*model.UploadFile) []map[string]interface{} { |
| 4266 | if len(files) == 0 { |
| 4267 | return nil |
| 4268 | } |
| 4269 | fileItems := make([]map[string]interface{}, 0, len(files)) |
| 4270 | for _, f := range files { |
| 4271 | // 将ID编码为HashID |
| 4272 | fileIDHash, _ := hashids.Encode(f.ID) |
| 4273 | messageIDHash, _ := hashids.Encode(f.MessageID) |
| 4274 | if fileIDHash == "" { |
| 4275 | fileIDHash = strconv.FormatInt(f.ID, 10) |
| 4276 | } |
| 4277 | if messageIDHash == "" { |
| 4278 | messageIDHash = strconv.FormatInt(f.MessageID, 10) |
| 4279 | } |
| 4280 | fileItems = append(fileItems, map[string]interface{}{ |
| 4281 | "id": fileIDHash, |
| 4282 | "file_name": f.FileName, |
| 4283 | "url": f.GetAISignedDownloadURL(sandboxSignedDownloadTTL), |
| 4284 | "mime_type": f.MimeType, |
| 4285 | "size": f.Size, |
| 4286 | "message_id": messageIDHash, |
| 4287 | }) |
| 4288 | } |
| 4289 | return fileItems |
| 4290 | } |
| 4291 | |
| 4292 | func resolveMediaKind(mimeType string) string { |
| 4293 | lower := strings.ToLower(strings.TrimSpace(mimeType)) |
no test coverage detected