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:
parent
c7f5aa2e2b
commit
167fae9892
6
api.go
6
api.go
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
@ -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.",
|
||||||
|
@ -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",
|
||||||
|
@ -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.",
|
||||||
|
@ -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.",
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
setup.go
13
setup.go
@ -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)
|
||||||
|
@ -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);
|
||||||
|
71
ts/setup.ts
71
ts/setup.ts
@ -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");
|
||||||
|
Loading…
Reference in New Issue
Block a user