2022-06-23 15:03:11 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-14 05:38:41 +00:00
|
|
|
"strings"
|
2022-08-03 06:26:59 +00:00
|
|
|
|
2022-06-23 15:03:11 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-08-31 13:01:15 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2023-03-14 05:38:41 +00:00
|
|
|
"github.com/alist-org/alist/v3/server/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-06-23 15:03:11 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-06-28 13:58:46 +00:00
|
|
|
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
2022-08-31 13:01:15 +00:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return nil, nil, errors.WithMessage(err, "failed get storage")
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
2023-03-14 05:38:41 +00:00
|
|
|
l, obj, err := op.Link(ctx, storage, actualPath, args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.WithMessage(err, "failed link")
|
|
|
|
}
|
|
|
|
if l.URL != "" && !strings.HasPrefix(l.URL, "http://") && !strings.HasPrefix(l.URL, "https://") {
|
|
|
|
if c, ok := ctx.(*gin.Context); ok {
|
|
|
|
l.URL = common.GetApiUrl(c.Request) + l.URL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l, obj, nil
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|