MCPcopy Create free account
hub / github.com/53AI/53AIHub / updateBatchProgress

Method updateBatchProgress

api/service/file_processor.go:481–523  ·  view source on GitHub ↗

updateBatchProgress 更新批量上传进度

(task *UploadTask, status string, progress float64)

Source from the content-addressed store, hash-verified

479
480// updateBatchProgress 更新批量上传进度
481func (fp *FileProcessor) updateBatchProgress(task *UploadTask, status string, progress float64) {
482 if task.BatchID == "" || task.FileID == "" {
483 return
484 }
485
486 manager := GetBatchUploadManagerInstance()
487 if manager.IsBatchCancelled(task.BatchID) {
488 return
489 }
490 if batch, err := manager.GetBatch(task.BatchID); err == nil {
491 // Fix: Use GetFileUpload for thread-safe access to the map
492 if fileUploadPtr, exists := batch.GetFileUpload(task.FileID); exists {
493 // Create a copy to modify, avoiding race conditions on struct fields
494 fileUpload := *fileUploadPtr
495
496 fileUpload.Status = status
497 fileUpload.Progress = progress
498 if status == "failed" {
499 // 从数据库获取错误信息,如果没有则使用通用错误
500 if task.DatabaseID != 0 {
501 if dbFile, err := model.GetUploadFileByID(task.DatabaseID); err == nil && dbFile != nil && dbFile.Error != "" {
502 fileUpload.Error = dbFile.Error
503 } else {
504 fileUpload.Error = "处理失败"
505 }
506 } else {
507 fileUpload.Error = "处理失败"
508 }
509 }
510
511 // 如果task中有DatabaseID和FileID,则使用它们
512 if task.DatabaseID != 0 {
513 fileUpload.DatabaseID = task.DatabaseID
514 }
515 if task.FileIDRef != 0 {
516 fileUpload.FileID = task.FileIDRef
517 }
518
519 // Pass the address of the modified copy
520 manager.updateFileProgress(task.BatchID, task.FileID, &fileUpload)
521 }
522 }
523}
524
525// cleanupCancelledUpload 回收取消时已经创建的上传/文件记录
526func (fp *FileProcessor) cleanupCancelledUpload(task *UploadTask, uploadFile *model.UploadFile, fileID int64) {

Callers 1

Calls 5

IsBatchCancelledMethod · 0.80
GetBatchMethod · 0.80
GetFileUploadMethod · 0.80
updateFileProgressMethod · 0.80

Tested by

no test coverage detected