putAsTask add as a put task and return immediately
(ctx context.Context, dstDirPath string, file model.FileStreamer)
| 62 | |
| 63 | // putAsTask add as a put task and return immediately |
| 64 | func putAsTask(ctx context.Context, dstDirPath string, file model.FileStreamer) (task.TaskExtensionInfo, error) { |
| 65 | storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) |
| 66 | if err != nil { |
| 67 | return nil, errors.WithMessage(err, "failed get storage") |
| 68 | } |
| 69 | if storage.Config().NoUpload { |
| 70 | return nil, errors.WithStack(errs.UploadNotSupported) |
| 71 | } |
| 72 | if file.NeedStore() { |
| 73 | _, err := file.CacheFullAndWriter(nil, nil) |
| 74 | if err != nil { |
| 75 | return nil, errors.Wrapf(err, "failed to create temp file") |
| 76 | } |
| 77 | //file.SetReader(tempFile) |
| 78 | //file.SetTmpFile(tempFile) |
| 79 | } |
| 80 | taskCreator, _ := ctx.Value(conf.UserKey).(*model.User) // taskCreator is nil when convert failed |
| 81 | t := &UploadTask{ |
| 82 | TaskExtension: task.TaskExtension{ |
| 83 | Creator: taskCreator, |
| 84 | ApiUrl: common.GetApiUrl(ctx), |
| 85 | }, |
| 86 | storage: storage, |
| 87 | dstDirActualPath: dstDirActualPath, |
| 88 | file: file, |
| 89 | } |
| 90 | t.SetTotalBytes(file.GetSize()) |
| 91 | task_group.TransferCoordinator.AddTask(stdpath.Join(storage.GetStorage().MountPath, dstDirActualPath), nil) |
| 92 | UploadTaskManager.Add(t) |
| 93 | return t, nil |
| 94 | } |
| 95 | |
| 96 | // putDirect put the file and return after finish |
| 97 | func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer, skipHook ...bool) error { |
no test coverage detected