mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-12 00:06:37 +08:00
fix: 使 TMDbProvider 支持从数据库读取 API Key
- 修改 TMDbProvider 添加 apiConfig *APIConfigService 字段 - NewTMDbProvider 接受 apiConfig 参数(可为 nil) - 添加 resolveAPIKey(ctx) 方法:优先从 config 读取,回退到数据库 - 添加 resolveBaseURL(ctx) 方法:解析基础 URL - 修改 SearchMovie 使用 resolveAPIKey / resolveBaseURL - 修改 DiscoverService.Fetch 使用 resolveAPIKey / resolveBaseURL - 调整 service.go 初始化顺序,确保 tmdb 在 scraper 之前初始化 - 构建验证通过
This commit is contained in:
@@ -53,14 +53,22 @@ func (d *DiscoverService) fetch(ctx context.Context, path string) ([]Match, erro
|
||||
// It paginates page=1 only — that's all the home page needs and it
|
||||
// keeps us under TMDb's 50 rps limit.
|
||||
func (d *DiscoverService) Fetch(ctx context.Context, path string) ([]Match, error) {
|
||||
if d.tmdb == nil || !d.tmdb.Enabled() {
|
||||
if d.tmdb == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Resolve API key from config or database
|
||||
apiKey := d.tmdb.resolveAPIKey(ctx)
|
||||
if apiKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
base := d.tmdb.resolveBaseURL(ctx)
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("api_key", d.tmdb.cfg.Secrets.TMDbAPIKey)
|
||||
q.Set("api_key", apiKey)
|
||||
q.Set("language", "zh-CN")
|
||||
q.Set("page", "1")
|
||||
u := d.tmdb.base + path + "?" + q.Encode()
|
||||
u := base + path + "?" + q.Encode()
|
||||
|
||||
type result struct {
|
||||
ID int `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user