Files
OSIT-AE-App-Native-Electron/app/js/module_app_idb.js
2020-03-06 15:34:15 -05:00

41 lines
1.5 KiB
JavaScript

const os = require('os');
const path = require('path');
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.');
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.
let filename = file_value.hosted_file_hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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;
}