mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
setup: add descriptive "test connection" messages; disable next button
for #129.
This commit is contained in:
parent
6551eeb938
commit
27ad7a4cf7
@ -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!",
|
||||
|
24
setup.go
24
setup.go
@ -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})
|
||||
|
38
ts/setup.ts
38
ts/setup.ts
@ -461,7 +461,9 @@ window.onpopstate = (event: PopStateEvent) => {
|
||||
}
|
||||
window.scrollTo(0, 0);
|
||||
}); }
|
||||
if (next) { next.addEventListener("click", () => {
|
||||
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");
|
||||
@ -472,7 +474,9 @@ window.onpopstate = (event: PopStateEvent) => {
|
||||
}
|
||||
}
|
||||
window.scrollTo(0, 0);
|
||||
}); }
|
||||
};
|
||||
next.addEventListener("click", func)
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@ -491,8 +495,23 @@ 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) {
|
||||
if (req.status != 200) {
|
||||
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");
|
||||
button.textContent = window.lang.strings("success");
|
||||
button.classList.add("~positive");
|
||||
@ -502,17 +521,6 @@ window.onpopstate = (event: PopStateEvent) => {
|
||||
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, () => {});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user