MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / putAsTask

Function putAsTask

internal/fs/put.go:64–94  ·  view source on GitHub ↗

putAsTask add as a put task and return immediately

(ctx context.Context, dstDirPath string, file model.FileStreamer)

Source from the content-addressed store, hash-verified

62
63// putAsTask add as a put task and return immediately
64func 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
97func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer, skipHook ...bool) error {

Callers 1

PutAsTaskFunction · 0.85

Calls 10

GetStorageAndActualPathFunction · 0.92
GetApiUrlFunction · 0.92
SetTotalBytesMethod · 0.80
AddTaskMethod · 0.80
ConfigMethod · 0.65
NeedStoreMethod · 0.65
CacheFullAndWriterMethod · 0.65
GetSizeMethod · 0.65
GetStorageMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected