Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/fs/link.go
1560 views
1
package fs
2
3
import (
4
"context"
5
"strings"
6
7
"github.com/alist-org/alist/v3/internal/model"
8
"github.com/alist-org/alist/v3/internal/op"
9
"github.com/alist-org/alist/v3/server/common"
10
"github.com/gin-gonic/gin"
11
"github.com/pkg/errors"
12
)
13
14
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
15
storage, actualPath, err := op.GetStorageAndActualPath(path)
16
if err != nil {
17
return nil, nil, errors.WithMessage(err, "failed get storage")
18
}
19
l, obj, err := op.Link(ctx, storage, actualPath, args)
20
if err != nil {
21
return nil, nil, errors.WithMessage(err, "failed link")
22
}
23
if l.URL != "" && !strings.HasPrefix(l.URL, "http://") && !strings.HasPrefix(l.URL, "https://") {
24
if c, ok := ctx.(*gin.Context); ok {
25
l.URL = common.GetApiUrl(c.Request) + l.URL
26
}
27
}
28
return l, obj, nil
29
}
30
31