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

Function link

internal/sharing/link.go:15–46  ·  view source on GitHub ↗
(ctx context.Context, sid, path string, args *LinkArgs)

Source from the content-addressed store, hash-verified

13)
14
15func link(ctx context.Context, sid, path string, args *LinkArgs) (*model.Sharing, *model.Link, model.Obj, error) {
16 sharing, err := op.GetSharingById(sid, args.SharingListArgs.Refresh)
17 if err != nil {
18 return nil, nil, nil, errors.WithStack(errs.SharingNotFound)
19 }
20 if !sharing.Valid() {
21 return sharing, nil, nil, errors.WithStack(errs.InvalidSharing)
22 }
23 if !sharing.Verify(args.Pwd) {
24 return sharing, nil, 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, nil, errors.WithMessage(err, "failed get sharing unwrap path")
31 }
32 storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath)
33 if err != nil {
34 return nil, nil, nil, errors.WithMessage(err, "failed get sharing link")
35 }
36 l, obj, err := op.Link(ctx, storage, actualPath, args.LinkArgs)
37 if err != nil {
38 return nil, nil, nil, errors.WithMessage(err, "failed get sharing link")
39 }
40 if l.URL != "" && !strings.HasPrefix(l.URL, "http://") && !strings.HasPrefix(l.URL, "https://") {
41 l.URL = common.GetApiUrl(ctx) + l.URL
42 }
43 return sharing, l, obj, nil
44 }
45 return nil, nil, nil, errors.New("cannot get sharing root link")
46}

Callers 1

LinkFunction · 0.70

Calls 8

GetSharingByIdFunction · 0.92
FixAndCleanPathFunction · 0.92
GetSharingUnwrapPathFunction · 0.92
GetStorageAndActualPathFunction · 0.92
LinkFunction · 0.92
GetApiUrlFunction · 0.92
ValidMethod · 0.80
VerifyMethod · 0.65

Tested by

no test coverage detected