1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

add jellyfin connection test, submission

fully functional now, but still need to add some sections (ombi mainly).
This commit is contained in:
Harvey Tindall 2021-01-27 12:55:39 +00:00
parent c7f5aa2e2b
commit 167fae9892
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
13 changed files with 97 additions and 25 deletions

6
api.go
View File

@ -1191,21 +1191,21 @@ func (app *appContext) ModifyConfig(gc *gin.Context) {
for setting, value := range settings.(map[string]interface{}) { for setting, value := range settings.(map[string]interface{}) {
if section == "ui" && setting == "language-form" { if section == "ui" && setting == "language-form" {
for key, lang := range app.storage.lang.Form { for key, lang := range app.storage.lang.Form {
if lang.Meta.Name == value.(string) { if lang.Meta.Name == value.(string) || value.(string) == key {
tempConfig.Section("ui").Key("language-form").SetValue(key) tempConfig.Section("ui").Key("language-form").SetValue(key)
break break
} }
} }
} else if section == "ui" && setting == "language-admin" { } else if section == "ui" && setting == "language-admin" {
for key, lang := range app.storage.lang.Admin { for key, lang := range app.storage.lang.Admin {
if lang.Meta.Name == value.(string) { if lang.Meta.Name == value.(string) || value.(string) == key {
tempConfig.Section("ui").Key("language-admin").SetValue(key) tempConfig.Section("ui").Key("language-admin").SetValue(key)
break break
} }
} }
} else if section == "email" && setting == "language" { } else if section == "email" && setting == "language" {
for key, lang := range app.storage.lang.Email { for key, lang := range app.storage.lang.Email {
if lang.Meta.Name == value.(string) { if lang.Meta.Name == value.(string) || value.(string) == key {
tempConfig.Section("email").Key("language").SetValue(key) tempConfig.Section("email").Key("language").SetValue(key)
break break
} }

View File

@ -133,7 +133,7 @@
<section class="section ~neutral banner footer flex-expand middle"> <section class="section ~neutral banner footer flex-expand middle">
<span class="button ~neutral !normal back">{{ .lang.Strings.back }}</span> <span class="button ~neutral !normal back">{{ .lang.Strings.back }}</span>
<div> <div>
<span class="button ~urge !normal">{{ .lang.JellyfinEmby.testConnection }}</span> <span class="button ~urge !normal" id="jellyfin-test-connection">{{ .lang.JellyfinEmby.testConnection }}</span>
<span class="button ~urge !normal next" disabled>{{ .lang.Strings.next }}</span> <span class="button ~urge !normal next" disabled>{{ .lang.Strings.next }}</span>
</div> </div>
</section> </section>

View File

@ -29,8 +29,6 @@
"commitNoun": "Commit", "commitNoun": "Commit",
"newUser": "Neuer Benutzer", "newUser": "Neuer Benutzer",
"profile": "Profil", "profile": "Profil",
"success": "Erfolg",
"error": "Fehler",
"unknown": "Unbekannt", "unknown": "Unbekannt",
"modifySettings": "Einstellungen ändern", "modifySettings": "Einstellungen ändern",
"modifySettingsDescription": "Wende Einstellungen von einem bestehenden Profil an, oder beziehe sie direkt von einem Benutzer.", "modifySettingsDescription": "Wende Einstellungen von einem bestehenden Profil an, oder beziehe sie direkt von einem Benutzer.",

View File

@ -29,8 +29,6 @@
"commitNoun": "Commit", "commitNoun": "Commit",
"newUser": "New User", "newUser": "New User",
"profile": "Profile", "profile": "Profile",
"success": "Success",
"error": "Error",
"unknown": "Unknown", "unknown": "Unknown",
"label": "Label", "label": "Label",
"modifySettings": "Modify Settings", "modifySettings": "Modify Settings",

View File

@ -30,8 +30,6 @@
"commitNoun": "Commettre", "commitNoun": "Commettre",
"newUser": "Nouvel utilisateur", "newUser": "Nouvel utilisateur",
"profile": "Profil", "profile": "Profil",
"success": "Succès",
"error": "Erreur",
"unknown": "Inconnu", "unknown": "Inconnu",
"modifySettings": "Modifier les paramètres", "modifySettings": "Modifier les paramètres",
"modifySettingsDescription": "Appliquez les paramètres à partir d'un profil existant ou obtenez-les directement auprès d'un utilisateur.", "modifySettingsDescription": "Appliquez les paramètres à partir d'un profil existant ou obtenez-les directement auprès d'un utilisateur.",

View File

@ -29,8 +29,6 @@
"commitNoun": "Commit", "commitNoun": "Commit",
"newUser": "Nieuwe gebruiker", "newUser": "Nieuwe gebruiker",
"profile": "Profiel", "profile": "Profiel",
"success": "Success",
"error": "Fout",
"unknown": "Onbekend", "unknown": "Onbekend",
"modifySettings": "Instellingen aanpassen", "modifySettings": "Instellingen aanpassen",
"modifySettingsDescription": "Pas instellingen van een bestaand profiel toe, of neem ze direct over van een gebruiker.", "modifySettingsDescription": "Pas instellingen van een bestaand profiel toe, of neem ze direct over van een gebruiker.",

View File

@ -6,6 +6,8 @@
"username": "Benutzername", "username": "Benutzername",
"password": "Passwort", "password": "Passwort",
"emailAddress": "E-Mail-Adresse", "emailAddress": "E-Mail-Adresse",
"submit": "Absenden" "submit": "Absenden",
"success": "Erfolg",
"error": "Fehler"
} }
} }

View File

@ -6,6 +6,8 @@
"username": "Username", "username": "Username",
"password": "Password", "password": "Password",
"emailAddress": "Email Address", "emailAddress": "Email Address",
"submit": "Submit" "submit": "Submit",
"success": "Success",
"error": "Error"
} }
} }

View File

@ -7,6 +7,8 @@
"username": "Nom d'utilisateur", "username": "Nom d'utilisateur",
"password": "Mot de passe", "password": "Mot de passe",
"emailAddress": "Addresse Email", "emailAddress": "Addresse Email",
"submit": "Soumettre" "submit": "Soumettre",
"success": "Succès",
"error": "Erreur"
} }
} }

View File

@ -6,6 +6,8 @@
"username": "Gebruikersnaam", "username": "Gebruikersnaam",
"password": "Wachtwoord", "password": "Wachtwoord",
"emailAddress": "E-mailadres", "emailAddress": "E-mailadres",
"submit": "Verstuur" "submit": "Verstuur",
"success": "Success",
"error": "Fout"
} }
} }

View File

@ -47,15 +47,20 @@ func (app *appContext) ServeSetup(gc *gin.Context) {
} }
type testReq struct { type testReq struct {
Host string `json:"jfHost"` ServerType string `json:"type"`
Username string `json:"jfUser"` Server string `json:"server"`
Password string `json:"jfPassword"` Username string `json:"username"`
Password string `json:"password"`
} }
func (app *appContext) TestJF(gc *gin.Context) { func (app *appContext) TestJF(gc *gin.Context) {
var req testReq var req testReq
gc.BindJSON(&req) gc.BindJSON(&req)
tempjf, _ := mediabrowser.NewServer(mediabrowser.JellyfinServer, req.Host, "jfa-go-setup", app.version, "auth", "auth", common.NewTimeoutHandler("authJF", req.Host, true), 30) serverType := mediabrowser.JellyfinServer
if req.ServerType == "emby" {
serverType = mediabrowser.EmbyServer
}
tempjf, _ := mediabrowser.NewServer(serverType, req.Server, "jfa-go-setup", app.version, "auth", "auth", common.NewTimeoutHandler("authJF", req.Server, true), 30)
_, status, err := tempjf.Authenticate(req.Username, req.Password) _, status, err := tempjf.Authenticate(req.Username, req.Password)
if !(status == 200 || status == 204) || err != nil { if !(status == 200 || status == 204) || err != nil {
app.info.Printf("Auth failed with code %d (%s)", status, err) app.info.Printf("Auth failed with code %d (%s)", status, err)

View File

@ -68,7 +68,7 @@ export const _get = (url: string, data: Object, onreadystatechange: (req: XMLHtt
req.send(JSON.stringify(data)); req.send(JSON.stringify(data));
}; };
export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, response?: boolean): void => { export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, response?: boolean, noErrorHandler?: boolean): void => {
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.open("POST", window.URLBase + url, true); req.open("POST", window.URLBase + url, true);
if (response) { if (response) {
@ -77,10 +77,10 @@ export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHt
req.setRequestHeader("Authorization", "Bearer " + window.token); req.setRequestHeader("Authorization", "Bearer " + window.token);
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.onreadystatechange = () => { req.onreadystatechange = () => {
if (req.status == 0) { if (req.status == 0 && !noErrorHandler) {
window.notifications.connectionError(); window.notifications.connectionError();
return; return;
} else if (req.status == 401) { } else if (req.status == 401 && !noErrorHandler) {
window.notifications.customError("401Error", window.lang.notif("error401Unauthorized")); window.notifications.customError("401Error", window.lang.notif("error401Unauthorized"));
} }
onreadystatechange(req); onreadystatechange(req);

View File

@ -1,4 +1,4 @@
import { _get, _post } from "./modules/common.js"; import { _get, _post, toggleLoader } from "./modules/common.js";
import { lang, LangFile, loadLangSelector } from "./modules/lang.js"; import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
interface sWindow extends Window { interface sWindow extends Window {
@ -6,6 +6,7 @@ interface sWindow extends Window {
} }
declare var window: sWindow; declare var window: sWindow;
window.URLBase = "";
const get = (id: string): HTMLElement => document.getElementById(id); const get = (id: string): HTMLElement => document.getElementById(id);
const text = (id: string, val: string) => { document.getElementById(id).textContent = val; }; const text = (id: string, val: string) => { document.getElementById(id).textContent = val; };
@ -270,6 +271,30 @@ const settings = {
}, },
}; };
const restartButton = document.getElementById("restart") as HTMLSpanElement;
const serialize = () => {
toggleLoader(restartButton);
let config = {};
for (let section in settings) {
config[section] = {};
for (let setting in settings[section]) {
if (settings[section][setting].value) {
config[section][setting] = settings[section][setting].value;
}
}
}
config["restart-program"] = true;
_post("/config", config, (req: XMLHttpRequest) => {
if (req.readyState == 4) {
toggleLoader(restartButton);
restartButton.classList.add("~positive");
restartButton.classList.remove("~urge");
restartButton.textContent = window.lang.strings("success");
}
}, true, true);
}
restartButton.onclick = serialize;
const relatedToEmail = Array.from(document.getElementsByClassName("related-to-email")); const relatedToEmail = Array.from(document.getElementsByClassName("related-to-email"));
const emailMethodChange = () => { const emailMethodChange = () => {
const val = settings["email"]["method"].value; const val = settings["email"]["method"].value;
@ -372,6 +397,48 @@ window.onpopstate = (event: PopStateEvent) => {
window.scrollTo(0, 0); window.scrollTo(0, 0);
}); } }); }
} }
})() })();
(() => {
const button = document.getElementById("jellyfin-test-connection") as HTMLSpanElement;
const ogText = button.textContent;
const nextButton = button.parentElement.querySelector("span.next") as HTMLSpanElement;
button.onclick = () => {
toggleLoader(button);
let send = {
"type": settings["jellyfin"]["type"].value,
"server": settings["jellyfin"]["server"].value,
"username": settings["jellyfin"]["username"].value,
"password": settings["jellyfin"]["password"].value
};
_post("/jellyfin/test", send, (req: XMLHttpRequest) => {
if (req.readyState == 4) {
toggleLoader(button);
const success = req.response["success"] as boolean;
if (success) {
nextButton.removeAttribute("disabled");
button.textContent = window.lang.strings("success");
button.classList.add("~positive");
button.classList.remove("~urge");
setTimeout(() => {
button.textContent = ogText;
button.classList.add("~urge");
button.classList.remove("~positive");
}, 5000);
} else {
nextButton.setAttribute("disabled", "");
button.textContent = window.lang.strings("error");
button.classList.add("~critical");
button.classList.remove("~urge");
setTimeout(() => {
button.textContent = ogText;
button.classList.add("~urge");
button.classList.remove("~critical");
}, 5000);
}
}
}, true, true);
};
})();
loadLangSelector("setup"); loadLangSelector("setup");