Most of the key features work at this point.

This commit is contained in:
Scott Idem
2020-03-06 15:34:15 -05:00
parent 37b708047f
commit 2ddcde1642
7 changed files with 213 additions and 134 deletions

View File

@@ -5,28 +5,29 @@ async function api_token_request_async(axios, secret_key) {
console.log('Already waiting on an API token request. Not starting another until finished.');
return false;
} else {
waiting_on_api_token = true;
const url = '/api_token_request';
let data = { secret_key: secret_key };
const result = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return false;
});
waiting_on_api_token = false;
return result;
}
waiting_on_api_token = true;
const url = '/api_token_request';
let data = { secret_key: secret_key };
const result = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return false;
});
waiting_on_api_token = false;
return result;
return false;
}

View File

@@ -2,6 +2,7 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.load_config = function () {
console.log('CWD: '+process.cwd());
@@ -67,24 +68,70 @@ exports.load_config = function () {
return config;
}
exports.check_file_cache = async function () {
console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****');
console.log('Checking the local file cache against the remote server.');
if (api_base_url && api_temporary_token) {
tbl_event_file.iterate(function(file_value, key, iteration) {
//if (file_value.event_location_id == event_location_id) {
//console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***')
let file_id = file_value.id; // NOTE: This is the event_file.id or event_file_id.
let filename = file_value.hosted_file_hash_sha256+'.file';
let save_path = path.join(host_file_cache_path, filename);
//console.log(save_path);
if (fs.existsSync(save_path)) {
//console.log('Local file already exists: '+save_path);
} else {
console.log('File not found locally. Downloading file: '+save_path);
let api_endpoint = '/event/file/'+file_id+'/download';
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread.
}
});
} else {
console.log('The api_base_url or api_temporary_token has not been set.');
console.log(api_base_url);
console.log(api_temporary_token);
return false;
}
return true;
}
exports.currently_online = function() {
//alert('You are currently online');
console.log('Currently online');
app_online = true;
document.getElementById('network_status1').classList.remove('btn-warning');
document.getElementById('network_status1').classList.add('btn-success');
document.getElementById('network_status1').innerHTML = '<span class="fas fa-check"></span> <span class="fas fa-globe"></span> Currently Online';
//document.getElementById('network_status1').innerHTML('Currently Online');
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('warning');
//document.getElementById('app_network_status').classList.remove('alert-warning');
//document.getElementById('app_network_status').classList.add('success');
//document.getElementById('app_network_status').classList.add('alert-success');
document.getElementById('app_network_status').classList.remove('app_warning');
//document.getElementById('app_network_status').classList.add('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-check"></span> <span class="fas fa-globe"></span> Currently Online';
//document.getElementById('app_network_status').innerHTML('Currently Online');
}
exports.currently_offline = function() {
//alert('You are currently offline');
console.log('Currently offline');
app_online = false;
document.getElementById('network_status1').classList.remove('btn-success');
document.getElementById('network_status1').classList.add('btn-warning');
document.getElementById('network_status1').innerHTML = '<span class="fas fa-exclamation"></span> <span class="fas fa-globe"></span> Currently Offline';
//document.getElementById('network_status1').innerHTML('Currently Offline');
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('success');
//document.getElementById('app_network_status').classList.remove('alert-success');
//document.getElementById('app_network_status').classList.add('warning');
//document.getElementById('app_network_status').classList.add('alert-warning');
document.getElementById('app_network_status').classList.add('app_warning');
//document.getElementById('app_network_status').classList.remove('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-exclamation"></span> <span class="fas fa-globe"></span> Currently Offline';
//document.getElementById('app_network_status').innerHTML('Currently Offline');
}
//window.addEventListener('online', currently_online);

View File

@@ -5,9 +5,15 @@ const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.check_file_cache = async function () {
console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****');
console.log('Checking the local file cache against the remote server.');
tbl_event_file.iterate(function(file_value, key, iteration) {
//if (file_value.event_location_id == event_location_id) {
console.log(api_base_url);
console.log(api_temporary_token);
//console.log(save_path);
if (api_base_url && api_temporary_token) {
tbl_event_file.iterate(function(file_value, key, iteration) {
//if (file_value.event_location_id == event_location_id) {
//console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***')
file_id = file_value.id; // NOTE: This is the event_file.id or event_file_id.
@@ -22,8 +28,13 @@ exports.check_file_cache = async function () {
let api_endpoint = '/event/file/'+file_id+'/download';
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread.
}
//}
});
});
} else {
console.log('The api_base_url or api_temporary_token has not been set.');
console.log(api_base_url);
console.log(api_temporary_token);
return false;
}
return true;
}