Reorder file creation logic to ensure size limit check occurs before database insertion

This commit is contained in:
2025-05-26 20:57:10 +08:00
parent 710c83a16e
commit b61027defd

View File

@@ -505,18 +505,18 @@ func CreateServerDownloadTask(uid uint, url, filename, description string, resou
return nil, model.NewRequestError("failed to test file URL: " + err.Error()) return nil, model.NewRequestError("failed to test file URL: " + err.Error())
} }
file, err := dao.CreateFile(filename, description, resourceID, &storageID, storageKeyUnavailable, "", 0, uid)
if err != nil {
log.Error("failed to create file in db: ", err)
return nil, model.NewInternalServerError("failed to create file in db")
}
if contentLength+getUploadingSize() > config.MaxUploadingSize() { if contentLength+getUploadingSize() > config.MaxUploadingSize() {
log.Info("A new downloading file is rejected due to max uploading size limit") log.Info("A new downloading file is rejected due to max uploading size limit")
_ = dao.DeleteFile(file.UUID) _ = dao.DeleteFile(file.UUID)
return nil, model.NewRequestError("server is busy, please try again later") return nil, model.NewRequestError("server is busy, please try again later")
} }
file, err := dao.CreateFile(filename, description, resourceID, &storageID, storageKeyUnavailable, "", 0, uid)
if err != nil {
log.Error("failed to create file in db: ", err)
return nil, model.NewInternalServerError("failed to create file in db")
}
updateUploadingSize(contentLength) updateUploadingSize(contentLength)
go func() { go func() {