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,36 +104,55 @@ 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');
testButton.disabled = true;
testButton.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Testing...';
nextButton.classList.add('disabled');
nextButton.setAttribute('aria-disabled', 'true');
var jfData = {}; var jfData = {};
jfData['jfHost'] = document.getElementById('jfHost').value; jfData['jfHost'] = document.getElementById('jfHost').value;
jfData['jfUser'] = document.getElementById('jfUser').value; jfData['jfUser'] = document.getElementById('jfUser').value;
jfData['jfPassword'] = document.getElementById('jfPassword').value; jfData['jfPassword'] = document.getElementById('jfPassword').value;
var req = new XMLHttpRequest(); let valid = true;
req.open("POST", "/testJF", true); for (val in jfData) {
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); if (jfData[val] == "") {
req.responseType = 'json'; valid = false;
req.onreadystatechange = function() { }
if (this.readyState == 4) { }
testButton.disabled = false; if (!valid) {
testButton.className = ''; if (!testButton.classList.contains('btn-danger')) {
if (this.response['success'] == true) { testButton.classList.add('btn-danger');
testButton.classList.add('btn', 'btn-success'); testButton.textContent = 'Fill out fields above.';
testButton.textContent = 'Success'; setTimeout(function() {
nextButton.classList.remove('disabled'); if (testButton.classList.contains('btn-danger')) {
nextButton.setAttribute('aria-disabled', 'false'); testButton.classList.remove('btn-danger');
} else { testButton.textContent = 'Test';
testButton.classList.add('btn', 'btn-danger'); }
testButton.textContent = 'Failed'; }, 2000);
}
} else {
testButton.disabled = true;
testButton.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Testing...';
nextButton.classList.add('disabled');
nextButton.setAttribute('aria-disabled', 'true');
var req = new XMLHttpRequest();
req.open("POST", "/testJF", true);
req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
req.responseType = 'json';
req.onreadystatechange = function() {
if (this.readyState == 4) {
testButton.disabled = false;
testButton.className = '';
if (this.response['success'] == true) {
testButton.classList.add('btn', 'btn-success');
testButton.textContent = 'Success';
nextButton.classList.remove('disabled');
nextButton.setAttribute('aria-disabled', 'false');
} else {
testButton.classList.add('btn', 'btn-danger');
testButton.textContent = 'Failed';
};
}; };
}; };
}; 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,20 +108,22 @@
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>
<button class="btn btn-secondary" id="jfTestButton">Test</button> <div style="margin-top: 1rem;">
<div class="btn-group float-right" role="group" aria-label="Back/Next buttons"> <button class="btn btn-secondary" id="jfTestButton">Test</button>
<a class="btn btn-secondary backButton" href="#page-2">Back</a> <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
<a class="btn btn-primary nextButton disabled" id="jfNextButton" aria-disabled="true" href="#page-4">Next</a> <a class="btn btn-secondary backButton" href="#page-2">Back</a>
<a class="btn btn-primary nextButton disabled" id="jfNextButton" aria-disabled="true" href="#page-4">Next</a>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -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)