212 lines
8.0 KiB
JavaScript
212 lines
8.0 KiB
JavaScript
const os = require('os');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const { ipcRenderer } = require('electron');
|
|
|
|
|
|
exports.create_load_idb = async function create_load_idb() {
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
exports.idb_to_launcher = async function idb_to_launcher() {
|
|
//tbl_example.iterate(tbl_check, tbl_check_success, tbl_check_error); //tbl_check(value, key, iteration)
|
|
let launcher_new = new Object();
|
|
|
|
let tbl_event_complete = false;
|
|
let tbl_event_file_complete = false;
|
|
let tbl_event_location_complete = false;
|
|
let tbl_event_location_file_complete = false;
|
|
let tbl_event_session_complete = false;
|
|
let tbl_event_session_file_complete = false;
|
|
let tbl_event_presentation_complete = false;
|
|
let tbl_event_presentation_file_complete = false;
|
|
let tbl_event_presenter_complete = false;
|
|
let tbl_event_presenter_file_complete = false;
|
|
|
|
// Look for *events*
|
|
let tmp_event = [];
|
|
tbl_event.iterate(function(event_value, key, iteration) {
|
|
tmp_event.push(event_value);
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event complete')
|
|
tbl_event_complete = true;
|
|
});
|
|
launcher_new.event = tmp_event;
|
|
|
|
// Look for *event files*
|
|
let tmp_event_file = []
|
|
tbl_event_file.iterate(function(file_value, key, iteration) {
|
|
//console.log('event id: '+launcher_new.event[0].id+' -> file_id: '+file_value.id+'for type: '+file_value.for_type+' for id: '+file_value.id);
|
|
if (file_value.for_type == 'event' && launcher_new.event[0].id == file_value.for_id) {
|
|
tmp_event_file.push(file_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
|
tbl_event_file_complete = true;
|
|
});
|
|
launcher_new.event_file = tmp_event_file;
|
|
|
|
|
|
// Look for *locations*
|
|
let tmp_event_location = []
|
|
tbl_event_location.iterate(function(location_value, key, iteration) {
|
|
tmp_event_location.push(location_value);
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_location complete')
|
|
tbl_event_location_complete = true;
|
|
});
|
|
launcher_new.location = tmp_event_location;
|
|
|
|
// Look for *event location files*
|
|
let tmp_event_location_file = []
|
|
tbl_event_file.iterate(function(file_value, key, iteration) {
|
|
if (file_value.for_type == 'location' && launcher_new.location[0].id == file_value.for_id) {
|
|
tmp_event_location_file.push(file_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
|
tbl_event_location_file_complete = true;
|
|
});
|
|
launcher_new.location_file = tmp_event_location_file;
|
|
|
|
|
|
// Look for *sessions*
|
|
let tmp_event_session = []
|
|
tbl_event_session.iterate(function(session_value, session_key, session_iteration) {
|
|
//console.log('session id: '+session_value.id);
|
|
|
|
|
|
// Look for *session files*
|
|
session_value.file = [];
|
|
tbl_event_file.iterate(function(session_file_value, session_file_key, session_file_iteration) {
|
|
if (session_file_value.for_type == 'session' && session_value.id == session_file_value.for_id) {
|
|
//console.log('session id: '+session_value.id+' -> file id: '+session_file_value.id);
|
|
session_value.file.push(session_file_value)
|
|
//tmp_event_session_file.push(session_file_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
|
tbl_event_session_file_complete = true;
|
|
});
|
|
|
|
|
|
// Look for *presentations per session*
|
|
session_value.presentation = [];
|
|
tbl_event_presentation.iterate(function(presentation_value, presentation_key, presentation_iteration) {
|
|
if (session_value.id == presentation_value.event_session_id) {
|
|
//console.log('session id: '+session_value.id+' -> presentation id: '+presentation_value.id);
|
|
|
|
|
|
// Look for *presentation files*
|
|
presentation_value.file = [];
|
|
tbl_event_file.iterate(function(presentation_file_value, presentation_file_key, presentation_file_iteration) {
|
|
if (presentation_file_value.for_type == 'presentation' && presentation_value.id == presentation_file_value.for_id) {
|
|
presentation_value.file.push(presentation_file_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
|
tbl_event_presentation_file_complete = true;
|
|
});
|
|
|
|
|
|
// Look for *presenters per presentation*
|
|
presentation_value.presenter = [];
|
|
tbl_event_presenter.iterate(function(presenter_value, presenter_key, presenter_iteration) {
|
|
if (presentation_value.id == presenter_value.event_presentation_id) {
|
|
//console.log('presentation id: '+presentation_value.id+' -> presenter id: '+presenter_value.id);
|
|
|
|
// Look for *presenter files*
|
|
presenter_value.file = [];
|
|
tbl_event_file.iterate(function(presenter_file_value, presenter_file_key, presenter_file_iteration) {
|
|
if (presenter_file_value.for_type == 'presenter' && presenter_value.id == presenter_file_value.for_id) {
|
|
presenter_value.file.push(presenter_file_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
|
tbl_event_presenter_file_complete = true;
|
|
});
|
|
presentation_value.presenter.push(presenter_value);
|
|
}
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_presenter complete')
|
|
tbl_event_presenter_complete = true;
|
|
});
|
|
|
|
session_value.presentation.push(presentation_value);
|
|
}//);
|
|
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_presentation complete')
|
|
tbl_event_presentation_complete = true;
|
|
});
|
|
//});
|
|
|
|
tmp_event_session.push(session_value);
|
|
|
|
}).then(function() {
|
|
console.log('idb_to_launcher: Iterate tbl_event_session complete')
|
|
tbl_event_session_complete = true;
|
|
});
|
|
launcher_new.session = tmp_event_session;
|
|
|
|
/*
|
|
console.log('v2 idb to launcher object: ***');
|
|
console.log(launcher);
|
|
console.log('v2 idb to launcher object: ^^^');
|
|
*/
|
|
|
|
var creating_launcher_object_loop = setInterval(function() {
|
|
if (tbl_event_complete && tbl_event_file_complete && tbl_event_location_complete && tbl_event_location_file_complete && tbl_event_session_complete && tbl_event_session_file_complete && tbl_event_presentation_complete && tbl_event_presentation_file_complete && tbl_event_presenter_complete && tbl_event_presenter_file_complete) {
|
|
console.log('And DONE!!!');
|
|
console.log('v2 idb to launcher object: ***');
|
|
console.log(launcher_new);
|
|
console.log('v2 idb to launcher object: ^^^');
|
|
ui.render_launcher(launcher_new);
|
|
clearInterval(creating_launcher_object_loop);
|
|
return launcher_new;
|
|
} else {
|
|
console.log('Still building...');
|
|
}
|
|
}, 5);
|
|
//return launcher_new;
|
|
}
|
|
|
|
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.event_file_id; // NOTE: the .id is the hosted_file.id!
|
|
let filename = file_value.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;
|
|
}
|
|
|
|
|
|
function tbl_check(value, key, iteration) {
|
|
console.log(value);
|
|
}
|
|
|
|
function tbl_check_success(result) {
|
|
console.log(result);
|
|
}
|
|
function tbl_check_error(result) {
|
|
console.log(result);
|
|
}
|