2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-29 19:51:15 +00:00
|
|
|
"fmt"
|
2021-01-31 23:12:50 +00:00
|
|
|
"io/fs"
|
2020-07-29 21:11:28 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2020-11-22 16:36:43 +00:00
|
|
|
"strings"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
var emailEnabled = false
|
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
func (app *appContext) GetPath(sect, key string) (fs.FS, string) {
|
|
|
|
val := app.config.Section(sect).Key(key).MustString("")
|
|
|
|
if strings.HasPrefix(val, "jfa-go:") {
|
2021-02-02 15:44:30 +00:00
|
|
|
return localFS, strings.TrimPrefix(val, "jfa-go:")
|
2021-01-31 23:12:50 +00:00
|
|
|
}
|
|
|
|
return app.systemFS, val
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) loadConfig() error {
|
2020-07-29 21:11:28 +00:00
|
|
|
var err error
|
2020-11-22 16:36:43 +00:00
|
|
|
app.config, err = ini.Load(app.configPath)
|
2020-07-29 21:11:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
app.config.Section("jellyfin").Key("public_server").SetValue(app.config.Section("jellyfin").Key("public_server").MustString(app.config.Section("jellyfin").Key("server").String()))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
for _, key := range app.config.Section("files").Keys() {
|
2020-10-23 13:39:04 +00:00
|
|
|
if key.Name() != "html_templates" {
|
2020-11-22 16:36:43 +00:00
|
|
|
key.SetValue(key.MustString(filepath.Join(app.dataPath, (key.Name() + ".json"))))
|
2020-10-23 13:39:04 +00:00
|
|
|
}
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2021-01-14 17:51:12 +00:00
|
|
|
for _, key := range []string{"user_configuration", "user_displayprefs", "user_profiles", "ombi_template", "invites", "emails", "user_template"} {
|
2020-11-22 16:36:43 +00:00
|
|
|
app.config.Section("files").Key(key).SetValue(app.config.Section("files").Key(key).MustString(filepath.Join(app.dataPath, (key + ".json"))))
|
2020-07-29 21:11:28 +00:00
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
app.URLBase = strings.TrimSuffix(app.config.Section("ui").Key("url_base").MustString(""), "/")
|
2020-08-16 12:36:54 +00:00
|
|
|
app.config.Section("email").Key("no_username").SetValue(strconv.FormatBool(app.config.Section("email").Key("no_username").MustBool(false)))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("password_resets").Key("email_html").SetValue(app.config.Section("password_resets").Key("email_html").MustString("jfa-go:" + "email.html"))
|
|
|
|
app.config.Section("password_resets").Key("email_text").SetValue(app.config.Section("password_resets").Key("email_text").MustString("jfa-go:" + "email.txt"))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("invite_emails").Key("email_html").SetValue(app.config.Section("invite_emails").Key("email_html").MustString("jfa-go:" + "invite-email.html"))
|
|
|
|
app.config.Section("invite_emails").Key("email_text").SetValue(app.config.Section("invite_emails").Key("email_text").MustString("jfa-go:" + "invite-email.txt"))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("email_confirmation").Key("email_html").SetValue(app.config.Section("email_confirmation").Key("email_html").MustString("jfa-go:" + "confirmation.html"))
|
|
|
|
app.config.Section("email_confirmation").Key("email_text").SetValue(app.config.Section("email_confirmation").Key("email_text").MustString("jfa-go:" + "confirmation.txt"))
|
2021-01-30 19:19:12 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("notifications").Key("expiry_html").SetValue(app.config.Section("notifications").Key("expiry_html").MustString("jfa-go:" + "expired.html"))
|
|
|
|
app.config.Section("notifications").Key("expiry_text").SetValue(app.config.Section("notifications").Key("expiry_text").MustString("jfa-go:" + "expired.txt"))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("notifications").Key("created_html").SetValue(app.config.Section("notifications").Key("created_html").MustString("jfa-go:" + "created.html"))
|
|
|
|
app.config.Section("notifications").Key("created_text").SetValue(app.config.Section("notifications").Key("created_text").MustString("jfa-go:" + "created.txt"))
|
2020-07-29 21:11:28 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("deletion").Key("email_html").SetValue(app.config.Section("deletion").Key("email_html").MustString("jfa-go:" + "deleted.html"))
|
|
|
|
app.config.Section("deletion").Key("email_text").SetValue(app.config.Section("deletion").Key("email_text").MustString("jfa-go:" + "deleted.txt"))
|
2020-09-17 22:50:07 +00:00
|
|
|
|
2021-01-31 23:12:50 +00:00
|
|
|
app.config.Section("welcome_email").Key("email_html").SetValue(app.config.Section("welcome_email").Key("email_html").MustString("jfa-go:" + "welcome.html"))
|
|
|
|
app.config.Section("welcome_email").Key("email_text").SetValue(app.config.Section("welcome_email").Key("email_text").MustString("jfa-go:" + "welcome.txt"))
|
2021-01-24 15:19:58 +00:00
|
|
|
|
2020-09-29 19:51:15 +00:00
|
|
|
app.config.Section("jellyfin").Key("version").SetValue(VERSION)
|
|
|
|
app.config.Section("jellyfin").Key("device").SetValue("jfa-go")
|
|
|
|
app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", VERSION, COMMIT))
|
|
|
|
|
2021-01-31 18:50:04 +00:00
|
|
|
if app.config.Section("email").Key("method").MustString("") == "" {
|
|
|
|
emailEnabled = false
|
|
|
|
} else {
|
|
|
|
emailEnabled = true
|
|
|
|
}
|
|
|
|
|
2021-01-10 15:51:04 +00:00
|
|
|
substituteStrings = app.config.Section("jellyfin").Key("substitute_jellyfin_strings").MustString("")
|
|
|
|
|
2021-01-12 23:37:22 +00:00
|
|
|
oldFormLang := app.config.Section("ui").Key("language").MustString("")
|
|
|
|
if oldFormLang != "" {
|
|
|
|
app.storage.lang.chosenFormLang = oldFormLang
|
|
|
|
}
|
|
|
|
newFormLang := app.config.Section("ui").Key("language-form").MustString("")
|
|
|
|
if newFormLang != "" {
|
|
|
|
app.storage.lang.chosenFormLang = newFormLang
|
|
|
|
}
|
|
|
|
app.storage.lang.chosenAdminLang = app.config.Section("ui").Key("language-admin").MustString("en-us")
|
2021-01-14 17:51:12 +00:00
|
|
|
app.storage.lang.chosenEmailLang = app.config.Section("email").Key("language").MustString("en-us")
|
|
|
|
|
|
|
|
app.email = NewEmailer(app)
|
2021-01-11 19:17:43 +00:00
|
|
|
|
2020-07-29 21:11:28 +00:00
|
|
|
return nil
|
|
|
|
}
|