From b6b0edb6def8fefa85a9b96dc9cd6ac85460092f Mon Sep 17 00:00:00 2001 From: zyxkad Date: Thu, 21 Mar 2024 22:22:03 -0600 Subject: [PATCH] support authorize github api --- README.MD | 8 ++++++++ config.go | 11 +++++++++++ config.yaml | 3 +++ update_checker.go | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/README.MD b/README.MD index 47cc755f..b514c11a 100644 --- a/README.MD +++ b/README.MD @@ -210,6 +210,14 @@ dashboard: # 签名推送 JWT 时的 subject, 请将其设为 "mailto:<您的邮箱>" 或 "https://<您的域名>" notification-subject: mailto:user@example.com +# Github API 客户端配置 +github-api: + # 更新检测间隔 + update-check-interval: 1h0m0s + # Github API 访问令牌, 绕过IP速率限制 + # 请访问 生成新的无权限令牌 + authorization: Bearer ghp_xxxx + # 数据库 database: # 数据库驱动, 可选值有: diff --git a/config.go b/config.go index f172fddf..b51cddb4 100644 --- a/config.go +++ b/config.go @@ -29,6 +29,7 @@ import ( "regexp" "strconv" "strings" + "time" "gopkg.in/yaml.v3" @@ -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"` @@ -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"` @@ -248,6 +255,10 @@ var defaultConfig = Config{ NotifySubject: "mailto:user@example.com", }, + GithubAPI: GithubAPIConfig{ + UpdateCheckInterval: (utils.YAMLDuration)(time.Hour), + }, + Database: DatabaseConfig{ Driver: "sqlite", DSN: filepath.Join("data", "files.db"), diff --git a/config.yaml b/config.yaml index 045dea69..519a865e 100644 --- a/config.yaml +++ b/config.yaml @@ -35,6 +35,9 @@ dashboard: pwa-short_name: GOBA Dash pwa-description: Go-Openbmclapi Internal Dashboard notification-subject: mailto:user@example.com +github-api: + update-check-interval: 1h0m0s + authorization: "" database: driver: sqlite data-source-name: files.db diff --git a/update_checker.go b/update_checker.go index cd5680a6..8f4d6f4d 100644 --- a/update_checker.go +++ b/update_checker.go @@ -48,6 +48,8 @@ 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() @@ -55,6 +57,9 @@ func (cr *Cluster) checkUpdate() (err error) { 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)