mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-26 20:47:57 +08:00
feat: add check
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"polaris/db"
|
"polaris/db"
|
||||||
"polaris/ent"
|
"polaris/ent"
|
||||||
"polaris/log"
|
"polaris/log"
|
||||||
@@ -22,8 +23,8 @@ type GeneralSettings struct {
|
|||||||
EnableNfo bool `json:"enable_nfo"`
|
EnableNfo bool `json:"enable_nfo"`
|
||||||
AllowQiangban bool `json:"allow_qiangban"`
|
AllowQiangban bool `json:"allow_qiangban"`
|
||||||
EnableAdultContent bool `json:"enable_adult_content"`
|
EnableAdultContent bool `json:"enable_adult_content"`
|
||||||
TvNamingFormat string `json:"tv_naming_format"`
|
TvNamingFormat string `json:"tv_naming_format"`
|
||||||
MovieNamingFormat string `json:"movie_naming_format"`
|
MovieNamingFormat string `json:"movie_naming_format"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||||
@@ -50,9 +51,17 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if in.TvNamingFormat != "" {
|
if in.TvNamingFormat != "" {
|
||||||
|
if _, err := template.New("test").Parse(in.TvNamingFormat);err != nil {
|
||||||
|
return nil, errors.Wrap(err, "tv format")
|
||||||
|
}
|
||||||
|
|
||||||
s.db.SetSetting(db.SettingTvNamingFormat, in.TvNamingFormat)
|
s.db.SetSetting(db.SettingTvNamingFormat, in.TvNamingFormat)
|
||||||
}
|
}
|
||||||
if in.MovieNamingFormat != "" {
|
if in.MovieNamingFormat != "" {
|
||||||
|
if _, err := template.New("test").Parse(in.MovieNamingFormat);err != nil {
|
||||||
|
return nil, errors.Wrap(err, "movie format")
|
||||||
|
}
|
||||||
|
|
||||||
s.db.SetSetting(db.SettingMovieNamingFormat, in.MovieNamingFormat)
|
s.db.SetSetting(db.SettingMovieNamingFormat, in.MovieNamingFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,16 +104,16 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
|||||||
tvFormat := s.db.GetTvNamingFormat()
|
tvFormat := s.db.GetTvNamingFormat()
|
||||||
movieFormat := s.db.GetMovingNamingFormat()
|
movieFormat := s.db.GetMovingNamingFormat()
|
||||||
return &GeneralSettings{
|
return &GeneralSettings{
|
||||||
TmdbApiKey: tmdb,
|
TmdbApiKey: tmdb,
|
||||||
DownloadDir: downloadDir,
|
DownloadDir: downloadDir,
|
||||||
LogLevel: logLevel,
|
LogLevel: logLevel,
|
||||||
Proxy: s.db.GetSetting(db.SettingProxy),
|
Proxy: s.db.GetSetting(db.SettingProxy),
|
||||||
EnablePlexmatch: plexmatchEnabled == "true",
|
EnablePlexmatch: plexmatchEnabled == "true",
|
||||||
AllowQiangban: allowQiangban == "true",
|
AllowQiangban: allowQiangban == "true",
|
||||||
EnableNfo: enableNfo == "true",
|
EnableNfo: enableNfo == "true",
|
||||||
EnableAdultContent: enableAdult == "true",
|
EnableAdultContent: enableAdult == "true",
|
||||||
TvNamingFormat: tvFormat,
|
TvNamingFormat: tvFormat,
|
||||||
MovieNamingFormat: movieFormat,
|
MovieNamingFormat: movieFormat,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user