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{}) {
if section == "ui" && setting == "language-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)
break
}
}
} else if section == "ui" && setting == "language-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)
break
}
}
} else if section == "email" && setting == "language" {
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)
break
}

View File

@ -133,7 +133,7 @@
<section class="section ~neutral banner footer flex-expand middle">
<span class="button ~neutral !normal back">{{ .lang.Strings.back }}</span>
<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>
</div>
</section>

View File

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

View File

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

View File

@ -30,8 +30,6 @@
"commitNoun": "Commettre",
"newUser": "Nouvel utilisateur",
"profile": "Profil",
"success": "Succès",
"error": "Erreur",
"unknown": "Inconnu",
"modifySettings": "Modifier les paramètres",
"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",
"newUser": "Nieuwe gebruiker",
"profile": "Profiel",
"success": "Success",
"error": "Fout",
"unknown": "Onbekend",
"modifySettings": "Instellingen aanpassen",
"modifySettingsDescription": "Pas instellingen van een bestaand profiel toe, of neem ze direct over van een gebruiker.",

View File

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

View File

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

View File

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

View File

@ -6,6 +6,8 @@
"username": "Gebruikersnaam",
"password": "Wachtwoord",
"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 {
Host string `json:"jfHost"`
Username string `json:"jfUser"`
Password string `json:"jfPassword"`
ServerType string `json:"type"`
Server string `json:"server"`
Username string `json:"username"`
Password string `json:"password"`
}
func (app *appContext) TestJF(gc *gin.Context) {
var req testReq
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)
if !(status == 200 || status == 204) || err != nil {
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));
};
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();
req.open("POST", window.URLBase + url, true);
if (response) {
@ -77,10 +77,10 @@ export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHt
req.setRequestHeader("Authorization", "Bearer " + window.token);
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.onreadystatechange = () => {
if (req.status == 0) {
if (req.status == 0 && !noErrorHandler) {
window.notifications.connectionError();
return;
} else if (req.status == 401) {
} else if (req.status == 401 && !noErrorHandler) {
window.notifications.customError("401Error", window.lang.notif("error401Unauthorized"));
}
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";
interface sWindow extends Window {
@ -6,6 +6,7 @@ interface sWindow extends Window {
}
declare var window: sWindow;
window.URLBase = "";
const get = (id: string): HTMLElement => document.getElementById(id);
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 emailMethodChange = () => {
const val = settings["email"]["method"].value;
@ -372,6 +397,48 @@ window.onpopstate = (event: PopStateEvent) => {
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");