diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 422e5d4..0756002 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 }} diff --git a/Dockerfile b/Dockerfile index e60b551..7183ddc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/db/const.go b/db/const.go index e6264ef..e5b1db1 100644 --- a/db/const.go +++ b/db/const.go @@ -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 diff --git a/db/db.go b/db/db.go index 0bbd06f..ed807a0 100644 --- a/db/db.go +++ b/db/db.go @@ -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 +} \ No newline at end of file diff --git a/server/core/client.go b/server/core/client.go index 639cf1b..2e1934d 100644 --- a/server/core/client.go +++ b/server/core/client.go @@ -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") } diff --git a/server/server.go b/server/server.go index 2a75bcd..b5ce3e6 100644 --- a/server/server.go +++ b/server/server.go @@ -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") }