feat: add task info to resp of add task api (close #5579)

This commit is contained in:
Andy Hsu
2023-12-03 14:44:20 +08:00
parent 8bdfc7ac8e
commit 026e944cbb
8 changed files with 79 additions and 50 deletions

View File

@ -33,28 +33,29 @@ func (t *UploadTask) Run() error {
var UploadTaskManager *tache.Manager[*UploadTask]
// putAsTask add as a put task and return immediately
func putAsTask(dstDirPath string, file model.FileStreamer) error {
func putAsTask(dstDirPath string, file model.FileStreamer) (tache.TaskWithInfo, error) {
storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
if err != nil {
return errors.WithMessage(err, "failed get storage")
return nil, errors.WithMessage(err, "failed get storage")
}
if storage.Config().NoUpload {
return errors.WithStack(errs.UploadNotSupported)
return nil, errors.WithStack(errs.UploadNotSupported)
}
if file.NeedStore() {
_, err := file.CacheFullInTempFile()
if err != nil {
return errors.Wrapf(err, "failed to create temp file")
return nil, errors.Wrapf(err, "failed to create temp file")
}
//file.SetReader(tempFile)
//file.SetTmpFile(tempFile)
}
UploadTaskManager.Add(&UploadTask{
t := &UploadTask{
storage: storage,
dstDirActualPath: dstDirActualPath,
file: file,
})
return nil
}
UploadTaskManager.Add(t)
return t, nil
}
// putDirect put the file and return after finish