mirror of
https://github.com/AlistGo/alist.git
synced 2025-12-18 18:30:10 +08:00
feat(driver): Added cookie-based authentication support for Gitee driver
- Extended request handling to include `Cookie` header if provided - Updated metadata to include `cookie` field with appropriate documentation - Adjusted file link generation to propagate `Cookie` headers in requests
This commit is contained in:
parent
a22cb5b2b4
commit
2df82e85f4
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
stdpath "path"
|
||||
"strings"
|
||||
@ -103,7 +104,12 @@ func (d *Gitee) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
|
||||
downloadURL = content.DownloadURL
|
||||
}
|
||||
url := d.applyProxy(downloadURL)
|
||||
return &model.Link{URL: url}, nil
|
||||
return &model.Link{
|
||||
URL: url,
|
||||
Header: http.Header{
|
||||
"Cookie": {d.Cookie},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *Gitee) newRequest() *resty.Request {
|
||||
|
||||
@ -13,6 +13,7 @@ type Addition struct {
|
||||
Repo string `json:"repo" type:"string" required:"true"`
|
||||
Ref string `json:"ref" type:"string" help:"Branch, tag or commit SHA, defaults to repository default branch"`
|
||||
DownloadProxy string `json:"download_proxy" type:"string" help:"Prefix added before download URLs, e.g. https://mirror.example.com/"`
|
||||
Cookie string `json:"cookie" type:"string" help:"Cookie returned from user info request"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
|
||||
@ -13,6 +13,9 @@ func (d *Gitee) getRepo() (*Repo, error) {
|
||||
if d.Token != "" {
|
||||
req.SetQueryParam("access_token", d.Token)
|
||||
}
|
||||
if d.Cookie != "" {
|
||||
req.SetHeader("Cookie", d.Cookie)
|
||||
}
|
||||
escapedOwner := url.PathEscape(d.Owner)
|
||||
escapedRepo := url.PathEscape(d.Repo)
|
||||
res, err := req.Get(fmt.Sprintf("/repos/%s/%s", escapedOwner, escapedRepo))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user