Skip to content

Commit

Permalink
support authorize github api
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Mar 22, 2024
1 parent 5b0b83a commit b6b0edb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ dashboard:
# 签名推送 JWT 时的 subject, 请将其设为 "mailto:<您的邮箱>" 或 "https://<您的域名>"
notification-subject: mailto:[email protected]

# Github API 客户端配置
github-api:
# 更新检测间隔
update-check-interval: 1h0m0s
# Github API 访问令牌, 绕过IP速率限制
# 请访问 <https://github.com/settings/tokens> 生成新的无权限令牌
authorization: Bearer ghp_xxxx

# 数据库
database:
# 数据库驱动, 可选值有:
Expand Down
11 changes: 11 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"regexp"
"strconv"
"strings"
"time"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -118,6 +119,11 @@ func (c *CacheConfig) UnmarshalYAML(n *yaml.Node) (err error) {
return nil
}

type GithubAPIConfig struct {
UpdateCheckInterval utils.YAMLDuration `yaml:"update-check-interval"`
Authorization string `yaml:"authorization"`
}

type DashboardConfig struct {
Enable bool `yaml:"enable"`
Username string `yaml:"username"`
Expand Down Expand Up @@ -184,6 +190,7 @@ type Config struct {
Cache CacheConfig `yaml:"cache"`
ServeLimit ServeLimitConfig `yaml:"serve-limit"`
Dashboard DashboardConfig `yaml:"dashboard"`
GithubAPI GithubAPIConfig `yaml:"github-api"`
Database DatabaseConfig `yaml:"database"`
Hijack HijackConfig `yaml:"hijack"`
Storages []storage.StorageOption `yaml:"storages"`
Expand Down Expand Up @@ -248,6 +255,10 @@ var defaultConfig = Config{
NotifySubject: "mailto:[email protected]",
},

GithubAPI: GithubAPIConfig{
UpdateCheckInterval: (utils.YAMLDuration)(time.Hour),
},

Database: DatabaseConfig{
Driver: "sqlite",
DSN: filepath.Join("data", "files.db"),
Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dashboard:
pwa-short_name: GOBA Dash
pwa-description: Go-Openbmclapi Internal Dashboard
notification-subject: mailto:[email protected]
github-api:
update-check-interval: 1h0m0s
authorization: ""
database:
driver: sqlite
data-source-name: files.db
Expand Down
5 changes: 5 additions & 0 deletions update_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ func (cr *Cluster) checkUpdate() (err error) {
return
}

log.Info("Checking for Go-OpenBmclAPI latest release")

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

req, err := http.NewRequest(http.MethodGet, lastetReleaseEndPoint, nil)
if err != nil {
return
}
if config.GithubAPI.Authorization != "" {
req.Header.Set("Authorization", config.GithubAPI.Authorization)
}
var resp *http.Response
{
tctx, cancel := context.WithTimeout(ctx, time.Second*10)
Expand Down

0 comments on commit b6b0edb

Please sign in to comment.