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",
|
"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!",
|
||||||
|
24
setup.go
24
setup.go
@ -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})
|
||||||
|
56
ts/setup.ts
56
ts/setup.ts
@ -461,18 +461,22 @@ window.onpopstate = (event: PopStateEvent) => {
|
|||||||
}
|
}
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
}); }
|
}); }
|
||||||
if (next) { next.addEventListener("click", () => {
|
if (next) {
|
||||||
let found = false;
|
const func = () => {
|
||||||
for (let ind = 0; ind < cards.length; ind++) {
|
if (next.hasAttribute("disabled")) return;
|
||||||
cards[ind].classList.add("unfocused");
|
let found = false;
|
||||||
if (ind > i && !(cards[ind].classList.contains("hidden")) && !found) {
|
for (let ind = 0; ind < cards.length; ind++) {
|
||||||
cards[ind].classList.remove("unfocused");
|
cards[ind].classList.add("unfocused");
|
||||||
changePage(pageNames[ind][0], pageNames[ind][1]);
|
if (ind > i && !(cards[ind].classList.contains("hidden")) && !found) {
|
||||||
found = true;
|
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) => {
|
_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.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", "");
|
nextButton.setAttribute("disabled", "");
|
||||||
button.textContent = window.lang.strings("error");
|
|
||||||
button.classList.add("~critical");
|
button.classList.add("~critical");
|
||||||
button.classList.remove("~urge");
|
button.classList.remove("~urge");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -512,7 +504,23 @@ window.onpopstate = (event: PopStateEvent) => {
|
|||||||
button.classList.add("~urge");
|
button.classList.add("~urge");
|
||||||
button.classList.remove("~critical");
|
button.classList.remove("~critical");
|
||||||
}, 5000);
|
}, 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, () => {});
|
}, true, () => {});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user