diff --git a/.gitignore b/.gitignore index 392aa51..ed03dea 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ data/ version.go notes docs/* +lang/langtostruct.py config-payload.json !docs/go.mod diff --git a/api.go b/api.go index afe4e0b..9747ab7 100644 --- a/api.go +++ b/api.go @@ -1050,6 +1050,7 @@ func (app *appContext) ApplySettings(gc *gin.Context) { "homescreen": map[string]string{}, } for _, id := range req.ApplyTo { + fmt.Printf("%+v\n", policy) status, err := app.jf.SetPolicy(id, policy) if !(status == 200 || status == 204) || err != nil { errors["policy"][id] = fmt.Sprintf("%d: %s", status, err) diff --git a/config.go b/config.go index 71e1724..d9c3a44 100644 --- a/config.go +++ b/config.go @@ -82,5 +82,7 @@ func (app *appContext) loadConfig() error { app.email = NewEmailer(app) + substituteStrings = app.config.Section("jellyfin").Key("substitute_jellyfin_strings").MustString("") + return nil } diff --git a/config/config-base.json b/config/config-base.json index ec97f21..0785755 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -66,6 +66,14 @@ ], "value": "jellyfin", "description": "Note: Emby integration works, but is not much of a priority. Jellyfin branding will still appear accross jfa-go." + }, + "substitute_jellyfin_strings": { + "name": "Substitute occurrences of \"Jellyfin\"", + "required": false, + "requires_restart": true, + "type": "text", + "value": "", + "description": "Optionally substitute occurrences of \"Jellyfin\" in the account creation form with this. May result in bad grammar." } } }, diff --git a/config/jsontostruct.py b/config/jsontostruct.py deleted file mode 100644 index b99be2b..0000000 --- a/config/jsontostruct.py +++ /dev/null @@ -1,57 +0,0 @@ -import json - -with open("config-formatted.json", "r") as f: - config = json.load(f) - -indent = 0 - - -def writeln(ln): - global indent - if "}" in ln and "{" not in ln: - indent -= 1 - s.write(("\t" * indent) + ln + "\n") - if "{" in ln and "}" not in ln: - indent += 1 - - -with open("configStruct.go", "w") as s: - writeln("package main") - writeln("") - writeln("type Metadata struct{") - writeln('Name string `json:"name"`') - writeln('Description string `json:"description"`') - writeln("}") - writeln("") - writeln("type Config struct{") - if "order" in config: - writeln('Order []string `json:"order"`') - for section in [x for x in config.keys() if x != "order"]: - title = "".join([x.title() for x in section.split("_")]) - writeln(title + " struct{") - if "order" in config[section]: - writeln('Order []string `json:"order"`') - if "meta" in config[section]: - writeln('Meta Metadata `json:"meta"`') - for setting in [ - x for x in config[section].keys() if x != "order" and x != "meta" - ]: - name = "".join([x.title() for x in setting.split("_")]) - writeln(name + " struct{") - writeln('Name string `json:"name"`') - writeln('Required bool `json:"required"`') - writeln('Restart bool `json:"requires_restart"`') - writeln('Description string `json:"description"`') - writeln('Type string `json:"type"`') - dt = config[section][setting]["type"] - if dt == "select": - dt = "string" - writeln('Options []string `json:"options"`') - elif dt == "number": - dt = "int" - elif dt != "bool": - dt = "string" - writeln(f'Value {dt} `json:"value" cfg:"{setting}"`') - writeln("} " + f'`json:"{setting}" cfg:"{setting}"`') - writeln("} " + f'`json:"{section}"`') - writeln("}") diff --git a/main.go b/main.go index 917576e..5e2c1fe 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,8 @@ var serverTypes = map[string]string{ "jellyfin": "Jellyfin", "emby": "Emby (experimental)", } +var serverType = mediabrowser.JellyfinServer +var substituteStrings = "" // User is used for auth purposes. type User struct { @@ -282,12 +284,6 @@ func start(asDaemon, firstCall bool) { if app.loadConfig() != nil { app.err.Fatalf("Failed to load config file \"%s\"", app.configPath) } - lang := app.config.Section("ui").Key("language").MustString("en-us") - app.storage.lang.FormPath = filepath.Join(app.localPath, "lang", "form", lang+".json") - if _, err := os.Stat(app.storage.lang.FormPath); os.IsNotExist(err) { - app.storage.lang.FormPath = filepath.Join(app.localPath, "lang", "form", "en-us.json") - } - app.storage.loadLang() app.version = app.config.Section("jellyfin").Key("version").String() // read from config... debugMode = app.config.Section("ui").Key("debug").MustBool(false) @@ -446,7 +442,6 @@ func start(asDaemon, firstCall bool) { server := app.config.Section("jellyfin").Key("server").String() cacheTimeout := int(app.config.Section("jellyfin").Key("cache_timeout").MustUint(30)) stringServerType := app.config.Section("jellyfin").Key("type").String() - serverType := mediabrowser.JellyfinServer timeoutHandler := common.NewTimeoutHandler("Jellyfin", server, true) if stringServerType == "emby" { serverType = mediabrowser.EmbyServer @@ -526,6 +521,14 @@ func start(asDaemon, firstCall bool) { } } } + + lang := app.config.Section("ui").Key("language").MustString("en-us") + app.storage.lang.FormPath = filepath.Join(app.localPath, "lang", "form", lang+".json") + if _, err := os.Stat(app.storage.lang.FormPath); os.IsNotExist(err) { + app.storage.lang.FormPath = filepath.Join(app.localPath, "lang", "form", "en-us.json") + } + app.storage.loadLang() + app.authJf, _ = mediabrowser.NewServer(serverType, server, "jfa-go", app.version, "auth", "auth", timeoutHandler, cacheTimeout) app.loadStrftime() diff --git a/storage.go b/storage.go index 689d6a1..4786ca2 100644 --- a/storage.go +++ b/storage.go @@ -58,6 +58,21 @@ func (st *Storage) storeInvites() error { } func (st *Storage) loadLang() error { + if substituteStrings != "" { + var file []byte + var err error + file, err = ioutil.ReadFile(st.lang.FormPath) + if err != nil { + file = []byte("{}") + } + // Replace Jellyfin with emby on form + file = []byte(strings.ReplaceAll(string(file), "Jellyfin", substituteStrings)) + err = json.Unmarshal(file, &st.lang.Form) + if err != nil { + log.Printf("ERROR: Failed to read \"%s\": %s", st.lang.FormPath, err) + } + return err + } err := loadJSON(st.lang.FormPath, &st.lang.Form) if err != nil { return err