8000 feat(github): support github proxy (#7979 close #7963) · AlistGo/alist@36b4204 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 36b4204

Browse files
authored
feat(github): support github proxy (#7979 close #7963)
1 parent f25be15 commit 36b4204

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

drivers/github/driver.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ func (d *Github) Init(ctx context.Context) error {
8585
}
8686
d.client = base.NewRestyClient().
8787
SetHeader("Accept", "application/vnd.github.object+json").
88-
SetHeader("Authorization", "Bearer "+d.Token).
8988
SetHeader("X-GitHub-Api-Version", "2022-11-28").
9089
SetLogger(log.StandardLogger()).
9190
SetDebug(false)
91+
token := strings.TrimSpace(d.Token)
92+
if token != "" {
93+
d.client = d.client.SetHeader("Authorization", "Bearer "+token)
94+
}
9295
if d.Ref == "" {
9396
repo, err := d.getRepo()
9497
if err != nil {
@@ -149,8 +152,13 @@ func (d *Github) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
149152
if obj.Type == "submodule" {
150153
return nil, errors.New("cannot download a submodule")
151154
}
155+
url := obj.DownloadURL
156+
ghProxy := strings.TrimSpace(d.Addition.GitHubProxy)
157+
if ghProxy != "" {
158+
url = strings.Replace(url, "https://raw.githubusercontent.com", ghProxy, 1)
159+
}
152160
return &model.Link{
153-
URL: obj.DownloadURL,
161+
URL: url,
154162
}, nil
155163
}
156164

@@ -679,8 +687,11 @@ func (d *Github) putBlob(ctx context.Context, s model.FileStreamer, up driver.Up
679687
return "", err
680688
}
681689
req.Header.Set("Accept", "application/vnd.github+json")
682-
req.Header.Set("Authorization", "Bearer "+d.Token)
683690
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
691+
token := strings.TrimSpace(d.Token)
692+
if token != "" {
693+
req.Header.Set("Authorization", "Bearer "+token)
694+
}
684695
req.ContentLength = length
685696

686697
res, err := base.HttpClient.Do(req)

drivers/github/meta.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77

88
type Addition struct {
99
driver.RootPath
10-
Token string `json:"token" type:"string" required:"true"`
10+
Token string `json:"token" type:"string"`
1111
Owner string `json:"owner" type:"string" required:"true"`
1212
Repo string `json:"repo" type:"string" required:"true"`
1313
Ref string `json:"ref" type:"string" help:"A branch, a tag or a commit SHA, main branch by default."`
14+
GitHubProxy string `json:"gh_proxy" type:"string" help:"GitHub proxy, e.g. https://ghproxy.net/raw.githubusercontent.com or https://gh-proxy.com/raw.githubusercontent.com"`
1415
CommitterName string `json:"committer_name" type:"string"`
1516
CommitterEmail string `json:"committer_email" type:"string"`
1617
AuthorName string `json:"author_name" type:"string"`

0 commit comments

Comments
 (0)
0