Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #2

Merged
merged 11 commits into from
May 24, 2024
9 changes: 6 additions & 3 deletions drivers/139/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ type Addition struct {
}

var config = driver.Config{
Name: "139Yun",
LocalSort: true,
Name: "139Yun",
LocalSort: true,
ProxyRangeOption: true,
}

func init() {
op.RegisterDriver(func() driver.Driver {
return &Yun139{}
d := &Yun139{}
d.ProxyRange = true
return d
})
}
26 changes: 26 additions & 0 deletions drivers/alias/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
)
Expand Down Expand Up @@ -45,6 +46,9 @@ func (d *Alias) Init(ctx context.Context) error {
d.oneKey = k
}
d.autoFlatten = true
} else {
d.oneKey = ""
d.autoFlatten = false
}
return nil
}
Expand Down Expand Up @@ -111,4 +115,26 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
return nil, errs.ObjectNotFound
}

func (d *Alias) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
reqPath, err := d.getReqPath(ctx, srcObj)
if err == nil {
return fs.Rename(ctx, *reqPath, newName)
}
if errs.IsNotImplement(err) {
return errors.New("same-name files cannot be Rename")
}
return err
}

func (d *Alias) Remove(ctx context.Context, obj model.Obj) error {
reqPath, err := d.getReqPath(ctx, obj)
if err == nil {
return fs.Remove(ctx, *reqPath)
}
if errs.IsNotImplement(err) {
return errors.New("same-name files cannot be Delete")
}
return err
}

var _ driver.Driver = (*Alias)(nil)
20 changes: 13 additions & 7 deletions drivers/alias/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ type Addition struct {
// Usually one of two
// driver.RootPath
// define other
Paths string `json:"paths" required:"true" type:"text"`
Paths string `json:"paths" required:"true" type:"text"`
ProtectSameName bool `json:"protect_same_name" default:"true" required:"false" help:"Protects same-name files from Delete or Rename"`
}

var config = driver.Config{
Name: "Alias",
LocalSort: true,
NoCache: true,
NoUpload: true,
DefaultRoot: "/",
Name: "Alias",
LocalSort: true,
NoCache: true,
NoUpload: true,
DefaultRoot: "/",
ProxyRangeOption: true,
}

func init() {
op.RegisterDriver(func() driver.Driver {
return &Alias{}
return &Alias{
Addition: Addition{
ProtectSameName: true,
},
}
})
}
41 changes: 39 additions & 2 deletions drivers/alias/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
stdpath "path"
"strings"

"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/sign"
Expand Down Expand Up @@ -102,13 +103,49 @@ func (d *Alias) link(ctx context.Context, dst, sub string, args model.LinkArgs)
return nil, err
}
if common.ShouldProxy(storage, stdpath.Base(sub)) {
return &model.Link{
link := &model.Link{
URL: fmt.Sprintf("%s/p%s?sign=%s",
common.GetApiUrl(args.HttpReq),
utils.EncodePath(reqPath, true),
sign.Sign(reqPath)),
}, nil
}
if args.HttpReq != nil && d.ProxyRange {
link.RangeReadCloser = common.NoProxyRange
}
return link, nil
}
link, _, err := fs.Link(ctx, reqPath, args)
return link, err
}

func (d *Alias) getReqPath(ctx context.Context, obj model.Obj) (*string, error) {
root, sub := d.getRootAndPath(obj.GetPath())
if sub == "" || sub == "/" {
return nil, errs.NotSupport
}
dsts, ok := d.pathMap[root]
if !ok {
return nil, errs.ObjectNotFound
}
var reqPath string
var err error
for _, dst := range dsts {
reqPath = stdpath.Join(dst, sub)
_, err = fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true})
if err == nil {
if d.ProtectSameName {
if ok {
ok = false
} else {
return nil, errs.NotImplement
}
} else {
break
}
}
}
if err != nil {
return nil, errs.ObjectNotFound
}
return &reqPath, nil
}
9 changes: 5 additions & 4 deletions drivers/alist_v3/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type Addition struct {
}

var config = driver.Config{
Name: "AList V3",
LocalSort: true,
DefaultRoot: "/",
CheckStatus: true,
Name: "AList V3",
LocalSort: true,
DefaultRoot: "/",
CheckStatus: true,
ProxyRangeOption: true,
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions drivers/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
_ "github.com/alist-org/alist/v3/drivers/teambition"
_ "github.com/alist-org/alist/v3/drivers/terabox"
_ "github.com/alist-org/alist/v3/drivers/thunder"
_ "github.com/alist-org/alist/v3/drivers/thunderx"
_ "github.com/alist-org/alist/v3/drivers/trainbit"
_ "github.com/alist-org/alist/v3/drivers/url_tree"
_ "github.com/alist-org/alist/v3/drivers/uss"
Expand Down
10 changes: 8 additions & 2 deletions drivers/ilanzou/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,21 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
// get the url after redirect
res, err := base.NoRedirectClient.R().SetHeaders(map[string]string{
//"Origin": d.conf.site,
"Referer": d.conf.site + "/",
"Referer": d.conf.site + "/",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
}).Get(realURL)
if err != nil {
return nil, err
}
if res.StatusCode() == 302 {
realURL = res.Header().Get("location")
} else {
return nil, fmt.Errorf("redirect failed, status: %d", res.StatusCode())
contentLengthStr := res.Header().Get("Content-Length")
contentLength, err := strconv.Atoi(contentLengthStr)
if err != nil || contentLength == 0 || contentLength > 1024*10 {
return nil, fmt.Errorf("redirect failed, status: %d", res.StatusCode())
}
return nil, fmt.Errorf("redirect failed, content: %s", res.String())
}
link := model.Link{URL: realURL}
return &link, nil
Expand Down
4 changes: 2 additions & 2 deletions drivers/ilanzou/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
bucket: "wpanstore-lanzou",
unproved: "unproved",
proved: "proved",
devVersion: "122",
devVersion: "125",
site: "https://www.ilanzou.com",
},
}
Expand All @@ -72,7 +72,7 @@ func init() {
bucket: "wpanstore",
unproved: "ws",
proved: "app",
devVersion: "121",
devVersion: "125",
site: "https://www.feijipan.com",
},
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/ilanzou/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
"extra": "2",
})
req.SetHeaders(map[string]string{
"Origin": d.conf.site,
"Referer": d.conf.site + "/",
"Origin": d.conf.site,
"Referer": d.conf.site + "/",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
})
if proved {
req.SetQueryParam("appToken", d.Token)
Expand Down
8 changes: 8 additions & 0 deletions drivers/lark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build linux darwin windows
// +build amd64 arm64

package drivers

import (
_ "github.com/alist-org/alist/v3/drivers/lark"
)
Loading
Loading