1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

converted /lg POST to jquery ajax

This commit is contained in:
checktheroads
2019-05-13 10:37:33 -07:00
parent 419fe7b5db
commit 3133891b19
18 changed files with 34 additions and 61 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -147,8 +147,9 @@ def lg():
except:
raise RuntimeError("Unable to add output to cache.", 415, *value_params)
# If 200, return output
response = cache.get(cache_key)
if value_code == 200:
return Response(cache.get(cache_key))
return Response(cache.get(cache_key), value_code)
# If 400 error, return error message and code
elif value_code in [405, 415]:
return Response(cache.get(cache_key), value_code)
@@ -156,7 +157,7 @@ def lg():
else:
logger.info(f"Cache match for: {cache_key}, returning cached entry...")
try:
return Response(cache.get(cache_key))
return Response(cache.get(cache_key), value_code)
except:
id = 4152
raise RuntimeError(

View File

@@ -4,13 +4,6 @@ var progress = ($('#progress'));
var resultsbox = ($('#resultsbox'));
resultsbox.hide();
progress.hide();
clientIP ();
function clientIP () {
$.getJSON("https://jsonip.com?callback=?", function(data) {
clientip = data.ip
});
};
$( document ).ready(function(){
var defaultasn = $ ( "#network" ).val();
@@ -189,58 +182,37 @@ var submitForm = function() {
</div>
`)
var xhr = new XMLHttpRequest();
xhr.open('POST', '/lg', true);
resultsbox.show()
progress.show()
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
xhr.send(JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}))
console.log(JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}));
/////////////////////////////////////////////////////////////
xhr_timer = window.setInterval(function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
progress.hide();
window.clearTimeout(xhr_timer);
$.ajax({
url: `/lg`,
type: 'POST',
data: JSON.stringify({router: router, cmd: cmd, ipprefix: ipprefix}),
contentType: "application/json; charset=utf-8",
readyState: resultsbox.show() && progress.show(),
statusCode: {
200: function(response, code) {
console.log(code, response);
progress.hide();
$('#output').html(`<br><div class="content"><p class="query-output" id="output">${response}</p></div>`);
},
405: function(response, code) {
console.log(code, response);
progress.hide();
$('#ipprefix').addClass('is-warning');
$('#output').html(`<br><div class="notification is-warning" id="output">${response.responseText}</div>`);
},
415: function(response, code) {
console.log(code, response);
progress.hide();
$('#ipprefix').addClass('is-danger');
$('#output').html(`<br><div class="notification is-danger" id="output">${response.responseText}</div>`);
},
429: function(response, code) {
console.log(code, response);
progress.hide();
$("#ratelimit").addClass("is-active");
}
}
var output = document.getElementById('output')
if (xhr.status == 415){
console.log(XMLHttpRequest.status, 'error')
var output = document.getElementById('output')
$('#ipprefix').addClass('is-danger')
output.innerHTML =
'<br>' +
'<div class="notification is-danger" id="output">' +
xhr.responseText +
'</div>'
}
if (xhr.status == 405){
console.log(XMLHttpRequest.status, 'error')
var output = document.getElementById('output')
$('#ipprefix').addClass('is-warning')
output.innerHTML =
'<br>' +
'<div class="notification is-warning" id="output">' +
xhr.responseText +
'</div>'
}
else if (xhr.status == 200){
console.log(xhr.status, 'success')
var output = document.getElementById('output')
output.innerHTML =
'<br>' +
'<div class="content">' +
'<p class="query-output" id="output">' +
xhr.responseText +
'</p>' +
'</div>'
}
else if (xhr.status == 429){
console.log(xhr.status, 'rate limit reached');
$("#ratelimit").addClass("is-active");
}
}, 500);
xhr.addEventListener("error", function(e) {
console.log("error: " + e);
});
})
}