setup: add descriptive "test connection" messages; disable next button

for #129.
pull/163/head
Harvey Tindall 3 years ago
parent 6551eeb938
commit 27ad7a4cf7
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -15,7 +15,11 @@
"serverAddress": "Server Address",
"emailSubject": "Email Subject",
"URL": "URL",
"apiKey": "API Key"
"apiKey": "API Key",
"errorInvalidUserPass": "Invalid username/password.",
"errorNotAdmin": "User is not allowed to manage server.",
"errorUserDisabled": "User may be disabled.",
"error404": "404, check the internal URL."
},
"startPage": {
"welcome": "Welcome!",

@ -55,15 +55,35 @@ type testReq struct {
func (app *appContext) TestJF(gc *gin.Context) {
var req testReq
gc.BindJSON(&req)
if !(strings.HasPrefix(req.Server, "http://") || strings.HasPrefix(req.Server, "https://")) {
req.Server = "http://" + req.Server
}
serverType := mediabrowser.JellyfinServer
if req.ServerType == "emby" {
serverType = mediabrowser.EmbyServer
}
tempjf, _ := mediabrowser.NewServer(serverType, req.Server, "jfa-go-setup", app.version, "auth", "auth", mediabrowser.NewNamedTimeoutHandler("authJF", req.Server, true), 30)
_, status, err := tempjf.Authenticate(req.Username, req.Password)
user, status, err := tempjf.Authenticate(req.Username, req.Password)
if !(status == 200 || status == 204) || err != nil {
msg := ""
switch status {
case 401:
msg = "errorInvalidUserPass"
case 403:
msg = "errorUserDisabled"
case 404:
msg = "error404"
}
app.info.Printf("Auth failed with code %d (%s)", status, err)
gc.JSON(401, map[string]bool{"success": false})
if msg != "" {
respond(status, msg, gc)
} else {
respondBool(status, false, gc)
}
return
}
if !user.Policy.IsAdministrator {
respond(403, "errorNotAdmin", gc)
return
}
gc.JSON(200, map[string]bool{"success": true})

@ -461,18 +461,22 @@ window.onpopstate = (event: PopStateEvent) => {
}
window.scrollTo(0, 0);
}); }
if (next) { next.addEventListener("click", () => {
let found = false;
for (let ind = 0; ind < cards.length; ind++) {
cards[ind].classList.add("unfocused");
if (ind > i && !(cards[ind].classList.contains("hidden")) && !found) {
cards[ind].classList.remove("unfocused");
changePage(pageNames[ind][0], pageNames[ind][1]);
found = true;
if (next) {
const func = () => {
if (next.hasAttribute("disabled")) return;
let found = false;
for (let ind = 0; ind < cards.length; ind++) {
cards[ind].classList.add("unfocused");
if (ind > i && !(cards[ind].classList.contains("hidden")) && !found) {
cards[ind].classList.remove("unfocused");
changePage(pageNames[ind][0], pageNames[ind][1]);
found = true;
}
}
}
window.scrollTo(0, 0);
}); }
window.scrollTo(0, 0);
};
next.addEventListener("click", func)
}
}
})();
@ -491,20 +495,8 @@ window.onpopstate = (event: PopStateEvent) => {
_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 {
if (req.status != 200) {
nextButton.setAttribute("disabled", "");
button.textContent = window.lang.strings("error");
button.classList.add("~critical");
button.classList.remove("~urge");
setTimeout(() => {
@ -512,7 +504,23 @@ window.onpopstate = (event: PopStateEvent) => {
button.classList.add("~urge");
button.classList.remove("~critical");
}, 5000);
const errorMsg = req.response["error"] as string;
if (!errorMsg) {
button.textContent = window.lang.strings("error");
} else {
button.textContent = window.lang.strings(errorMsg);
}
return;
}
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);
}
}, true, () => {});
};

Loading…
Cancel
Save