<commit_before>function saveCredentials() {
	localStorage.setItem('user-key', $('#user-key').val());
	localStorage.setItem('user-secret', $('#user-secret').val());
}

function tryLoadingCredentials() {
	$('#user-key').val(localStorage.getItem('user-key'));
	$('#user-secret').val(localStorage.getItem('user-secret'));
}

function makeRequest(data, url) {
	var key =  $('#user-key').val();
	var secret = $('#user-secret').val();

	// if(key.length != 32 || secret.length != 32) {
	// 	return null;
	// }

	var data = $.extend({}, data, {
			'gondola-user': key,
			'gondola-time': Math.floor(Date.now()/1000),
			'gondola-url': url
		});
	
	data = JSON.stringify(data);
	
	var hash = CryptoJS.HmacSHA256(data, secret).toString();

	var response = $.ajax({
		type: 'POST',
		url: 'http://'+$('#dashboard-address').val()+url,
		contentType: 'application/json',
		data: data,
		headers: {
			'gondola-hash': hash
		},
		async: false
	});

	if(response.status == 200) {
		response.json = JSON.parse(response.responseText);
	}

	return response;
}


function loadApplications() {
	if($('#applications').children().length > 0) {
		return;
	}

	var data = makeRequest({}, '/applications/');
	
	if(data.json.applications.length>0) {
		saveCredentials();
	}

	$.each(data.json.applications, function(i, e) {
		var option = $('<option>');
		$(option).text(e.name);
		$(option).attr('value', e.key);
		$('#applications').append(option);
	});	

	applicationChange();
}

function applicationChange() {
	runDashboard();
}

function runDashboard() {
	var application = $('#applications').val();

	var data = makeRequest({'gondola-application': application}, '/terminal/');

	$('#debug-console').empty();

	if(data.json.log.length == 0){
		$('#debug-console').append($('<p class="bg-warning">This application has no logs.</p>'));
		return;
	}

	

	$.each(data.json.log, function(i, e) {
		if(e.length == 0)
			return;

		var entry = JSON.parse(e);
		
		var item = $('<div>');
		var pre = $('<pre>');

		var request = $('<code class="request json">'+JSON.stringify(entry.request, null, 4)+'</code>');
		var response = $('<code class="response json">'+JSON.stringify(entry.response, null, 4)+'</code>');

		$(request).appendTo(pre);
		$(response).appendTo(pre);
		$(pre).appendTo(item);

		$('#debug-console').append(item);

	});

	$('code').each(function(i,e){
		hljs.highlightBlock(e);
	});

}

function authenticate() {
	loadApplications();
}


$(document).ready(function() {
	tryLoadingCredentials();
	$('#applications').change(applicationChange);

})<commit_msg>Removed complete address from API calls in dashboard.<commit_after>function saveCredentials() {
	localStorage.setItem('user-key', $('#user-key').val());
	localStorage.setItem('user-secret', $('#user-secret').val());
}

function tryLoadingCredentials() {
	$('#user-key').val(localStorage.getItem('user-key'));
	$('#user-secret').val(localStorage.getItem('user-secret'));
}

function makeRequest(data, url) {
	var key =  $('#user-key').val();
	var secret = $('#user-secret').val();

	// if(key.length != 32 || secret.length != 32) {
	// 	return null;
	// }

	var data = $.extend({}, data, {
			'gondola-user': key,
			'gondola-time': Math.floor(Date.now()/1000),
			'gondola-url': url
		});
	
	data = JSON.stringify(data);
	
	var hash = CryptoJS.HmacSHA256(data, secret).toString();

	var response = $.ajax({
		type: 'POST',
		url: url,
		contentType: 'application/json',
		data: data,
		headers: {
			'gondola-hash': hash
		},
		async: false
	});

	if(response.status == 200) {
		response.json = JSON.parse(response.responseText);
	}

	return response;
}


function loadApplications() {
	if($('#applications').children().length > 0) {
		return;
	}

	var data = makeRequest({}, '/applications/');
	
	if(data.json.applications.length>0) {
		saveCredentials();
	}

	$.each(data.json.applications, function(i, e) {
		var option = $('<option>');
		$(option).text(e.name);
		$(option).attr('value', e.key);
		$('#applications').append(option);
	});	

	applicationChange();
}

function applicationChange() {
	runDashboard();
}

function runDashboard() {
	var application = $('#applications').val();

	var data = makeRequest({'gondola-application': application}, '/terminal/');

	$('#debug-console').empty();

	if(data.json.log.length == 0){
		$('#debug-console').append($('<p class="bg-warning">This application has no logs.</p>'));
		return;
	}

	

	$.each(data.json.log, function(i, e) {
		if(e.length == 0)
			return;

		var entry = JSON.parse(e);
		
		var item = $('<div>');
		var pre = $('<pre>');

		var request = $('<code class="request json">'+JSON.stringify(entry.request, null, 4)+'</code>');
		var response = $('<code class="response json">'+JSON.stringify(entry.response, null, 4)+'</code>');

		$(request).appendTo(pre);
		$(response).appendTo(pre);
		$(pre).appendTo(item);

		$('#debug-console').append(item);

	});

	$('code').each(function(i,e){
		hljs.highlightBlock(e);
	});

}

function authenticate() {
	loadApplications();
}


$(document).ready(function() {
	tryLoadingCredentials();
	$('#applications').change(applicationChange);

})

{'fraction_non_alphanumeric': 0.22836962919364331, 'fraction_numerical': 0.007847753580537572, 'mean_word_length': 4.505399568034557, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2216162', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1745, 'n_words': 305}