const os = require('os'); const path = require('path'); const fs = require('fs'); let request_waiting = false; setInterval(async function() { if (typeof axios.defaults.headers.common['Authorization'] !== 'undefined' && axios.defaults.headers.common['Authorization'] != null) { if (typeof launcher.sessions === 'undefined') { console.log('Check for location files.'); let for_id = launcher.event_location_id; launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id); for (var i in launcher.files) { console.log('f: ('+launcher.files[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***') file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id! filename = launcher.files[i].hash_sha256+'.file'; save_path = path.join(file_cache_path, filename); //console.log(directory_and_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); ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread. //response.data.pipe(fs.createWriteStream(directory_and_filename)); } //let results = await api.download_file_id(axios, file_id, hash_sha256); } } else { console.log('No check for location 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+' ***') // 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+' ***'); file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id! hash_sha256 = launcher.sessions[i].files[j].hash_sha256+'.file'; let results = await api.download_file_id(axios, file_id, hash_sha256); } } 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); // 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+' ***'); file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id! hash_sha256 = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file'; let results = await api.download_file_id(axios, file_id, hash_sha256); } } 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) // 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+' ***') file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id! hash_sha256 = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file'; let results = await api.download_file_id(axios, file_id, hash_sha256); } } 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.'); } /* if (launcher.sessions) { console.log('Check for session files.'); let for_id = launcher.event_location_id; launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id); for (var i in launcher.sessions) { console.log('f: ('+launcher.sessions[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***') file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id! let results = await api.download_file_id(axios, file_id); } } else { console.log('No check for location files.'); } */ } else { console.log('Waiting a few more seconds to see if Authorization header is set.'); } }, 5000);