272 lines
13 KiB
JavaScript
272 lines
13 KiB
JavaScript
const os = require('os');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const { ipcRenderer } = require('electron');
|
|
|
|
|
|
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, host_file_cache_path) {
|
|
if (typeof launcher.event === 'undefined') {
|
|
launcher.event = await api.get_event_details(axios, launcher.event_id);
|
|
tbl_event.setItem(launcher.event.id.toString(), launcher.event);
|
|
/*
|
|
.then(function (data) {
|
|
console.log(data.id);
|
|
idbKeyval.set(data.id, data, tbl_event);
|
|
//for (var i in response) {
|
|
//var event_record = data[i];
|
|
//idbKeyval.set(response[i].id, response[i], tbl_event);
|
|
//}
|
|
});
|
|
*/
|
|
|
|
}
|
|
|
|
if (typeof launcher.location === 'undefined') {
|
|
launcher.location = await api.get_event_location_details(axios, launcher.event_id, launcher.event_location_id);
|
|
tbl_event_location.setItem(launcher.location.id.toString(), launcher.location);
|
|
}
|
|
|
|
if (typeof launcher.event_files === 'undefined') {
|
|
console.log('Check for global event files.');
|
|
let for_id = launcher.event_id;
|
|
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
|
|
for (var i in launcher.event_files) {
|
|
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
|
|
tbl_event_file.setItem(launcher.event_files[i].event_file_id.toString(), launcher.event_files[i]);
|
|
|
|
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = launcher.event_files[i].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('No check for global event files');
|
|
}
|
|
|
|
|
|
if (typeof launcher.location_files === 'undefined') {
|
|
console.log('Check for location specific files.');
|
|
let for_id = launcher.event_location_id;
|
|
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
|
|
for (var i in launcher.location_files) {
|
|
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
|
|
tbl_event_file.setItem(launcher.location_files[i].event_file_id.toString(), launcher.location_files[i]);
|
|
|
|
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = launcher.location_files[i].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('No check for location specific files.');
|
|
}
|
|
|
|
|
|
if (typeof launcher.sessions === 'undefined') {
|
|
console.log('Check for location sessions.');
|
|
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
|
|
for (var i in launcher.sessions) {
|
|
console.log('*** '+launcher.sessions[i].name+' ***')
|
|
tbl_event_session.setItem(launcher.sessions[i].id.toString(), launcher.sessions[i]);
|
|
|
|
// Check for session files start
|
|
if (typeof launcher.sessions[i].files === 'undefined') {
|
|
console.log('Check for session files.');
|
|
let for_id = launcher.sessions[i].id;
|
|
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
|
|
if (launcher.sessions[i].files) {
|
|
console.log('Session files found.');
|
|
for (var j in launcher.sessions[i].files) {
|
|
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
|
|
tbl_event_file.setItem(launcher.sessions[i].files[j].event_file_id.toString(), launcher.sessions[i].files[j]);
|
|
|
|
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = launcher.sessions[i].files[j].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('No session files found.');
|
|
}
|
|
} else {
|
|
console.log('No check for session files.');
|
|
}
|
|
// Check for session files end
|
|
|
|
// Get session presentations and associated files
|
|
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
|
|
for (var j in launcher.sessions[i].presentations) {
|
|
console.log('* '+launcher.sessions[i].presentations[j].name);
|
|
tbl_event_presentation.setItem(launcher.sessions[i].presentations[j].id.toString(), launcher.sessions[i].presentations[j]);
|
|
|
|
// Check for presentation files start
|
|
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
|
|
console.log('Check for presentation files.');
|
|
let for_id = launcher.sessions[i].presentations[j].id;
|
|
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
|
|
if (launcher.sessions[i].presentations[j].files) {
|
|
console.log('Presentation files found.');
|
|
for (var k in launcher.sessions[i].presentations[j].files) {
|
|
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
|
|
tbl_event_file.setItem(launcher.sessions[i].presentations[j].files[k].event_file_id.toString(), launcher.sessions[i].presentations[j].files[k]);
|
|
|
|
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = launcher.sessions[i].presentations[j].files[k].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('No presentation files found.');
|
|
}
|
|
} else {
|
|
console.log('No check for presentation files.');
|
|
}
|
|
// Check for presentation files end
|
|
|
|
|
|
// Get session presentations presenters and associated files
|
|
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
|
|
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
|
|
for (var k in launcher.sessions[i].presentations[j].presenters) {
|
|
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
|
|
tbl_event_presenter.setItem(launcher.sessions[i].presentations[j].presenters[k].id.toString(), launcher.sessions[i].presentations[j].presenters[k]);
|
|
|
|
// Check for presenter files start
|
|
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
|
|
console.log('Check for presenter files.');
|
|
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
|
|
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
|
|
if (launcher.sessions[i].presentations[j].presenters[k].files) {
|
|
console.log('Presenter files found.');
|
|
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
|
|
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***');
|
|
tbl_event_file.setItem(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id.toString(), launcher.sessions[i].presentations[j].presenters[k].files[l]);
|
|
|
|
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].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('No presenter files found.');
|
|
}
|
|
} else {
|
|
console.log('No check for presenter files.');
|
|
}
|
|
// Check for presenter files end
|
|
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
console.log('No check for location sessions.');
|
|
}
|
|
|
|
console.log('Location cache check finished.');
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Updated 2019-12-19 */
|
|
function index_location_detail(class_name) {
|
|
var class_elements = document.getElementsByClassName(class_name);
|
|
|
|
for (var i = 0; i < class_elements.length; i++) {
|
|
class_elements[i].addEventListener( 'click', function() {view_session( this.getAttribute('data-session_id')) } );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/* Updated 2019-12-19 */
|
|
function view_session(session_id) {
|
|
var class_elements = document.getElementsByClassName('session_detail');
|
|
console.log('*** Session ID: '+session_id);
|
|
for (var i = 0; i < class_elements.length; i++) {
|
|
console.log('*** checking: '+class_elements[i].getAttribute('data-session_id'));
|
|
if (class_elements[i].getAttribute('data-session_id') == session_id) {
|
|
console.log('show');
|
|
class_elements[i].classList.remove('d-none');
|
|
class_elements[i].classList.add('d-block');
|
|
} else {
|
|
console.log('hide');
|
|
class_elements[i].classList.remove('d-block');
|
|
class_elements[i].classList.add('d-none');
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Updated 2019-12-20 */
|
|
function index_open_file_buttons(class_name) {
|
|
var class_elements = document.getElementsByClassName(class_name);
|
|
|
|
for (var i = 0; i < class_elements.length; i++) {
|
|
//class_elements[i].addEventListener( 'click', function() {open_local_file( this.getAttribute('data-filename')) } );
|
|
|
|
//let directory = 'file_cache/';
|
|
|
|
//directory_and_filename = path.join(directory, class_elements[i].getAttribute('data-filename'));
|
|
|
|
let file_path = path.join(host_file_cache_path, class_elements[i].getAttribute('data-hash_sha256'));
|
|
let filename = class_elements[i].getAttribute('data-filename');
|
|
|
|
class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } );
|
|
//ipcRenderer.send('open_local_file', this.getAttribute('data-filename')); // in render thread
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|