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:
okatu-loli 2025-11-08 14:54:52 +08:00
parent a22cb5b2b4
commit 2df82e85f4
3 changed files with 11 additions and 1 deletions

View File

@ -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 {

View File

@ -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{

View File

@ -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))