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

Function get

internal/sharing/get.go:15–60  ·  view source on GitHub ↗
(ctx context.Context, sid, path string, args model.SharingListArgs)

Source from the content-addressed store, hash-verified

13)
14
15func get(ctx context.Context, sid, path string, args model.SharingListArgs) (*model.Sharing, model.Obj, error) {
16 sharing, err := op.GetSharingById(sid, args.Refresh)
17 if err != nil {
18 return nil, nil, errors.WithStack(errs.SharingNotFound)
19 }
20 if !sharing.Valid() {
21 return sharing, nil, errors.WithStack(errs.InvalidSharing)
22 }
23 if !sharing.Verify(args.Pwd) {
24 return sharing, nil, errors.WithStack(errs.WrongShareCode)
25 }
26 path = utils.FixAndCleanPath(path)
27 if len(sharing.Files) == 1 || path != "/" {
28 unwrapPath, err := op.GetSharingUnwrapPath(sharing, path)
29 if err != nil {
30 return nil, nil, errors.WithMessage(err, "failed get sharing unwrap path")
31 }
32 if unwrapPath != "/" {
33 virtualFiles := op.GetStorageVirtualFilesByPath(stdpath.Dir(unwrapPath))
34 for _, f := range virtualFiles {
35 if f.GetName() == stdpath.Base(unwrapPath) {
36 return sharing, f, nil
37 }
38 }
39 } else {
40 return sharing, &model.Object{
41 Name: sid,
42 Size: 0,
43 Modified: time.Time{},
44 IsFolder: true,
45 }, nil
46 }
47 storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath)
48 if err != nil {
49 return nil, nil, errors.WithMessage(err, "failed get sharing file")
50 }
51 obj, err := op.Get(ctx, storage, actualPath)
52 return sharing, obj, err
53 }
54 return sharing, &model.Object{
55 Name: sid,
56 Size: 0,
57 Modified: time.Time{},
58 IsFolder: true,
59 }, nil
60}

Callers 1

GetFunction · 0.70

Calls 9

GetSharingByIdFunction · 0.92
FixAndCleanPathFunction · 0.92
GetSharingUnwrapPathFunction · 0.92
GetStorageAndActualPathFunction · 0.92
GetFunction · 0.92
ValidMethod · 0.80
VerifyMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected