30 lines
1.1 KiB
JavaScript
30 lines
1.1 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('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('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.
|
|
}
|
|
//}
|
|
});
|
|
|
|
return true;
|
|
}
|