feat: embed default tmdb api key

This commit is contained in:
Simon Ding
2025-03-19 10:49:05 +08:00
parent ca06e560e3
commit be86fd05e1
6 changed files with 24 additions and 7 deletions

View File

@@ -58,4 +58,6 @@ jobs:
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TMDB_API_KEY=${{ secrets.TMDB_API_KEY }}

View File

@@ -6,6 +6,8 @@ ENV GO111MODULE=on
WORKDIR /app
ARG TMDB_API_KEY
COPY go.mod .
COPY go.sum .
RUN go mod download
@@ -13,7 +15,7 @@ RUN go mod download
COPY . .
# 指定OS等并go build
RUN CGO_ENABLED=0 go build -o polaris -ldflags="-X polaris/db.Version=$(git describe --tags --long)" ./cmd/
RUN CGO_ENABLED=0 go build -o polaris -ldflags="-X polaris/db.Version=$(git describe --tags --long) -X polaris/db.TmdbApiKey=$(echo $TMDB_API_KEY)" ./cmd/
FROM debian:stable-slim

View File

@@ -2,7 +2,10 @@ package db
import "polaris/ent/media"
var Version = "undefined"
var (
Version = "undefined"
TmdbApiKey = ""
)
const (
SettingTmdbApiKey = "tmdb_api_key"
@@ -48,15 +51,16 @@ const DefaultNamingFormat = "{{.NameCN}} {{.NameEN}} {{if .Year}} ({{.Year}}) {{
//https://en.wikipedia.org/wiki/Video_file_format
var defaultAcceptedVideoFormats = []string{
".webm", ".mkv", ".flv", ".vob", ".ogv", ".ogg", ".drc", ".mng", ".avi", ".mts", ".m2ts",".ts",
".mov", ".qt", ".wmv", ".yuv", ".rm", ".rmvb", ".viv", ".amv", ".mp4", ".m4p", ".m4v",
".webm", ".mkv", ".flv", ".vob", ".ogv", ".ogg", ".drc", ".mng", ".avi", ".mts", ".m2ts", ".ts",
".mov", ".qt", ".wmv", ".yuv", ".rm", ".rmvb", ".viv", ".amv", ".mp4", ".m4p", ".m4v",
".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".m2v", ".m4v",
".svi", ".3gp", ".3g2", ".nsv",
}
var defaultAcceptedSubtitleFormats = []string{
".ass", ".srt",".vtt", ".webvtt", ".sub", ".idx",
".ass", ".srt", ".vtt", ".webvtt", ".sub", ".idx",
}
type NamingInfo struct {
NameCN string
NameEN string

View File

@@ -733,3 +733,12 @@ func (c *Client) GetAcceptedSubtitleFormats() ([]string, error) {
func (c *Client) SetAcceptedSubtitleFormats(key string, v []string) error {
return c.setAcceptedFormats(SettingAcceptedSubtitleFormats, v)
}
func (c *Client) GetTmdbApiKey() string {
k := c.GetSetting(SettingTmdbApiKey)
if k == "" {
return TmdbApiKey
}
return k
}

View File

@@ -145,7 +145,7 @@ func (c *Client) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, erro
}
func (c *Client) TMDB() (*tmdb.Client, error) {
api := c.db.GetSetting(db.SettingTmdbApiKey)
api := c.db.GetTmdbApiKey()
if api == "" {
return nil, errors.New("TMDB apiKey not set")
}

View File

@@ -146,7 +146,7 @@ func (s *Server) Serve() error {
}
func (s *Server) TMDB() (*tmdb.Client, error) {
api := s.db.GetSetting(db.SettingTmdbApiKey)
api := s.db.GetTmdbApiKey()
if api == "" {
return nil, errors.New("TMDB apiKey not set")
}