parent
f25be154c6
commit
36b4204623
@ -85,10 +85,13 @@ func (d *Github) Init(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
d.client = base.NewRestyClient().
|
d.client = base.NewRestyClient().
|
||||||
SetHeader("Accept", "application/vnd.github.object+json").
|
SetHeader("Accept", "application/vnd.github.object+json").
|
||||||
SetHeader("Authorization", "Bearer "+d.Token).
|
|
||||||
SetHeader("X-GitHub-Api-Version", "2022-11-28").
|
SetHeader("X-GitHub-Api-Version", "2022-11-28").
|
||||||
SetLogger(log.StandardLogger()).
|
SetLogger(log.StandardLogger()).
|
||||||
SetDebug(false)
|
SetDebug(false)
|
||||||
|
token := strings.TrimSpace(d.Token)
|
||||||
|
if token != "" {
|
||||||
|
d.client = d.client.SetHeader("Authorization", "Bearer "+token)
|
||||||
|
}
|
||||||
if d.Ref == "" {
|
if d.Ref == "" {
|
||||||
repo, err := d.getRepo()
|
repo, err := d.getRepo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -149,8 +152,13 @@ func (d *Github) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
|||||||
if obj.Type == "submodule" {
|
if obj.Type == "submodule" {
|
||||||
return nil, errors.New("cannot download a submodule")
|
return nil, errors.New("cannot download a submodule")
|
||||||
}
|
}
|
||||||
|
url := obj.DownloadURL
|
||||||
|
ghProxy := strings.TrimSpace(d.Addition.GitHubProxy)
|
||||||
|
if ghProxy != "" {
|
||||||
|
url = strings.Replace(url, "https://raw.githubusercontent.com", ghProxy, 1)
|
||||||
|
}
|
||||||
return &model.Link{
|
return &model.Link{
|
||||||
URL: obj.DownloadURL,
|
URL: url,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,8 +687,11 @@ func (d *Github) putBlob(ctx context.Context, s model.FileStreamer, up driver.Up
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept", "application/vnd.github+json")
|
req.Header.Set("Accept", "application/vnd.github+json")
|
||||||
req.Header.Set("Authorization", "Bearer "+d.Token)
|
|
||||||
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
|
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
|
||||||
|
token := strings.TrimSpace(d.Token)
|
||||||
|
if token != "" {
|
||||||
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
}
|
||||||
req.ContentLength = length
|
req.ContentLength = length
|
||||||
|
|
||||||
res, err := base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
|
@ -7,10 +7,11 @@ import (
|
|||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
driver.RootPath
|
driver.RootPath
|
||||||
Token string `json:"token" type:"string" required:"true"`
|
Token string `json:"token" type:"string"`
|
||||||
Owner string `json:"owner" type:"string" required:"true"`
|
Owner string `json:"owner" type:"string" required:"true"`
|
||||||
Repo string `json:"repo" type:"string" required:"true"`
|
Repo string `json:"repo" type:"string" required:"true"`
|
||||||
Ref string `json:"ref" type:"string" help:"A branch, a tag or a commit SHA, main branch by default."`
|
Ref string `json:"ref" type:"string" help:"A branch, a tag or a commit SHA, main branch by default."`
|
||||||
|
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"`
|
||||||
CommitterName string `json:"committer_name" type:"string"`
|
CommitterName string `json:"committer_name" type:"string"`
|
||||||
CommitterEmail string `json:"committer_email" type:"string"`
|
CommitterEmail string `json:"committer_email" type:"string"`
|
||||||
AuthorName string `json:"author_name" type:"string"`
|
AuthorName string `json:"author_name" type:"string"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user