mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Reorder file creation logic to ensure size limit check occurs before database insertion
This commit is contained in:
@@ -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() {
|
||||||
|
Reference in New Issue
Block a user