1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

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

for #129.
This commit is contained in:
Harvey Tindall 2021-07-24 14:15:10 +01:00
parent 6551eeb938
commit 27ad7a4cf7
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 59 additions and 27 deletions

View File

@ -15,7 +15,11 @@
"serverAddress": "Server Address", "serverAddress": "Server Address",
"emailSubject": "Email Subject", "emailSubject": "Email Subject",
"URL": "URL", "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": { "startPage": {
"welcome": "Welcome!", "welcome": "Welcome!",

View File

@ -55,15 +55,35 @@ type testReq struct {
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)
if !(strings.HasPrefix(req.Server, "http://") || strings.HasPrefix(req.Server, "https://")) {
req.Server = "http://" + req.Server
}
serverType := mediabrowser.JellyfinServer serverType := mediabrowser.JellyfinServer
if req.ServerType == "emby" { if req.ServerType == "emby" {
serverType = mediabrowser.EmbyServer serverType = mediabrowser.EmbyServer
} }
tempjf, _ := mediabrowser.NewServer(serverType, req.Server, "jfa-go-setup", app.version, "auth", "auth", mediabrowser.NewNamedTimeoutHandler("authJF", req.Server, true), 30) 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 { 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) 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 return
} }
gc.JSON(200, map[string]bool{"success": true}) gc.JSON(200, map[string]bool{"success": true})

View File

@ -461,7 +461,9 @@ window.onpopstate = (event: PopStateEvent) => {
} }
window.scrollTo(0, 0); window.scrollTo(0, 0);
}); } }); }
if (next) { next.addEventListener("click", () => { if (next) {
const func = () => {
if (next.hasAttribute("disabled")) return;
let found = false; let found = false;
for (let ind = 0; ind < cards.length; ind++) { for (let ind = 0; ind < cards.length; ind++) {
cards[ind].classList.add("unfocused"); cards[ind].classList.add("unfocused");
@ -472,7 +474,9 @@ window.onpopstate = (event: PopStateEvent) => {
} }
} }
window.scrollTo(0, 0); window.scrollTo(0, 0);
}); } };
next.addEventListener("click", func)
}
} }
})(); })();
@ -491,8 +495,23 @@ window.onpopstate = (event: PopStateEvent) => {
_post("/jellyfin/test", send, (req: XMLHttpRequest) => { _post("/jellyfin/test", send, (req: XMLHttpRequest) => {
if (req.readyState == 4) { if (req.readyState == 4) {
toggleLoader(button); toggleLoader(button);
const success = req.response["success"] as boolean; if (req.status != 200) {
if (success) { nextButton.setAttribute("disabled", "");
button.classList.add("~critical");
button.classList.remove("~urge");
setTimeout(() => {
button.textContent = ogText;
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"); nextButton.removeAttribute("disabled");
button.textContent = window.lang.strings("success"); button.textContent = window.lang.strings("success");
button.classList.add("~positive"); button.classList.add("~positive");
@ -502,17 +521,6 @@ window.onpopstate = (event: PopStateEvent) => {
button.classList.add("~urge"); button.classList.add("~urge");
button.classList.remove("~positive"); button.classList.remove("~positive");
}, 5000); }, 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, () => {});
}; };