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

Use bs5-jf on setup, fix bugs

No longer quits if the program times out connecting to the given
jellyfin host.
This commit is contained in:
Harvey Tindall 2020-08-30 18:09:06 +01:00
parent c6f845296a
commit 1c980cf7cd
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 68 additions and 42 deletions

View File

@ -104,16 +104,34 @@ var jfValid = false
document.getElementById('jfTestButton').onclick = function() { document.getElementById('jfTestButton').onclick = function() {
var testButton = document.getElementById('jfTestButton'); var testButton = document.getElementById('jfTestButton');
var nextButton = document.getElementById('jfNextButton'); var nextButton = document.getElementById('jfNextButton');
var jfData = {};
jfData['jfHost'] = document.getElementById('jfHost').value;
jfData['jfUser'] = document.getElementById('jfUser').value;
jfData['jfPassword'] = document.getElementById('jfPassword').value;
let valid = true;
for (val in jfData) {
if (jfData[val] == "") {
valid = false;
}
}
if (!valid) {
if (!testButton.classList.contains('btn-danger')) {
testButton.classList.add('btn-danger');
testButton.textContent = 'Fill out fields above.';
setTimeout(function() {
if (testButton.classList.contains('btn-danger')) {
testButton.classList.remove('btn-danger');
testButton.textContent = 'Test';
}
}, 2000);
}
} else {
testButton.disabled = true; testButton.disabled = true;
testButton.innerHTML = testButton.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' + '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Testing...'; 'Testing...';
nextButton.classList.add('disabled'); nextButton.classList.add('disabled');
nextButton.setAttribute('aria-disabled', 'true'); nextButton.setAttribute('aria-disabled', 'true');
var jfData = {};
jfData['jfHost'] = document.getElementById('jfHost').value;
jfData['jfUser'] = document.getElementById('jfUser').value;
jfData['jfPassword'] = document.getElementById('jfPassword').value;
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("POST", "/testJF", true); req.open("POST", "/testJF", true);
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
@ -134,6 +152,7 @@ document.getElementById('jfTestButton').onclick = function() {
}; };
}; };
req.send(JSON.stringify(jfData)); req.send(JSON.stringify(jfData));
}
}; };
document.getElementById('submitButton').onclick = function() { document.getElementById('submitButton').onclick = function() {

View File

@ -3,12 +3,10 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <link rel="stylesheet" href="bs5-jf.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.5.0/jquery.serialize-object.min.js" integrity="sha256-E8KRdFk/LTaaCBoQIV/rFNc0s3ICQQiOHFT4Cioifa8=" crossorigin="anonymous"></script>
<style> <style>
.card-body { .card-body {
width: 100%; width: 100%;
@ -110,16 +108,17 @@
You should create a separate account for it, checking 'Allow this user to manage the server'. You can disable everything else. Once done, enter the credentials here. You should create a separate account for it, checking 'Allow this user to manage the server'. You can disable everything else. Once done, enter the credentials here.
<div class="form-group"> <div class="form-group">
<label for="jfHost">Host</label> <label for="jfHost">Host</label>
<input type="url" class="form-control" id="jfHost" placeholder="http://jellyf.in:443"> <input type="url" class="form-control" id="jfHost" placeholder="http://jellyf.in:443" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="jfUser">Username</label> <label for="jfUser">Username</label>
<input type="text" class="form-control" id="jfUser" placeholder="Username"> <input type="text" class="form-control" id="jfUser" placeholder="Username" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="jfPassword">Password</label> <label for="jfPassword">Password</label>
<input type="password" class="form-control" id="jfPassword" placeholder="Password"> <input type="password" class="form-control" id="jfPassword" placeholder="Password" required>
</div> </div>
<div style="margin-top: 1rem;">
<button class="btn btn-secondary" id="jfTestButton">Test</button> <button class="btn btn-secondary" id="jfTestButton">Test</button>
<div class="btn-group float-right" role="group" aria-label="Back/Next buttons"> <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
<a class="btn btn-secondary backButton" href="#page-2">Back</a> <a class="btn btn-secondary backButton" href="#page-2">Back</a>
@ -127,6 +126,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="slide card" id="page-4"> <div class="slide card" id="page-4">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Email</h5> <h5 class="card-title">Email</h5>
@ -152,9 +152,9 @@
</div> </div>
</div> </div>
<div id="emailSMTPArea"> <div id="emailSMTPArea">
<div class="form-group form-check"> <div class="form-group form-check form-switch">
<input type="checkbox" class="custom-control-input" id="emailSSL_TLS" checked> <input type="checkbox" class="form-check-input" id="emailSSL_TLS" checked>
<label for="emailSSL_TLS" class="custom-control-label" id="emailSSL_TLSLabel">Use SSL/TLS</label> <label for="emailSSL_TLS" class="form-check-label" id="emailSSL_TLSLabel">Use SSL/TLS</label>
<small class="form-text text-muted">Note: SSL/TLS usually uses port 465, whereas STARTTLS usually uses 587.</small> <small class="form-text text-muted">Note: SSL/TLS usually uses port 465, whereas STARTTLS usually uses 587.</small>
</div> </div>
<div class="form-group form-row"> <div class="form-group form-row">

View File

@ -40,11 +40,17 @@ type Jellyfin struct {
userCache []map[string]interface{} userCache []map[string]interface{}
cacheExpiry time.Time cacheExpiry time.Time
cacheLength int cacheLength int
noFail bool
} }
func (jf *Jellyfin) timeoutHandler() { func (jf *Jellyfin) timeoutHandler() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Fatalf("Failed to authenticate with Jellyfin @ %s: Timed out", jf.server) out := fmt.Sprintf("Failed to authenticate with Jellyfin @ %s: Timed out", jf.server)
if jf.noFail {
log.Printf(out)
} else {
log.Fatalf(out)
}
} }
} }

View File

@ -15,6 +15,7 @@ func (app *appContext) TestJF(gc *gin.Context) {
gc.BindJSON(&req) gc.BindJSON(&req)
tempjf := Jellyfin{} tempjf := Jellyfin{}
tempjf.init(req.Host, "jfa-go-setup", app.version, "auth", "auth") tempjf.init(req.Host, "jfa-go-setup", app.version, "auth", "auth")
tempjf.noFail = true
_, 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)