A lot of work on the launcher. Moving things from Electron node.js to Svelte.
This commit is contained in:
@@ -167,11 +167,13 @@ exports.check_local_file = async function ({local_file_path, filename}) {
|
||||
|
||||
|
||||
// Check local hash file cache
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
|
||||
console.log('*** Electron framework export: check_hash_file_cache() ***');
|
||||
// console.log('*** Electron framework export: check_hash_file_cache() ***');
|
||||
// console.log('Check local hash file cache');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}`);
|
||||
console.log(`*** Electron framework export: check_hash_file_cache() *** Host File Cache Path: ${host_file_cache_path}; Hash: ${hash}`);
|
||||
|
||||
let hash_filename = `${hash}.file`;
|
||||
|
||||
@@ -187,7 +189,7 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
|
||||
// console.log(hash_file_cache_path);
|
||||
|
||||
if (fs.existsSync(hash_file_cache_path)) {
|
||||
console.log(`Hashed file exists in cache: ${hash_file_cache_path}`);
|
||||
// console.log(`Hashed file exists in cache: ${hash_file_cache_path}`);
|
||||
return true;
|
||||
} else {
|
||||
console.log(`Hashed file not found in cache: ${hash_file_cache_path}`);
|
||||
@@ -197,11 +199,12 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
|
||||
|
||||
|
||||
// Download hash file to cache
|
||||
// Used by Svelte Event Launcher
|
||||
// Updated 2022-05-06
|
||||
exports.download_hash_file_to_cache = async function ({host_file_cache_path, event_file_id=null, hash=null}) {
|
||||
console.log('*** Electron framework export: download_hash_file_to_cache() ***');
|
||||
exports.download_hash_file_to_cache = async function ({api_base_url, host_file_cache_path, event_file_id=null, hash=null}) {
|
||||
// console.log('*** Electron framework export: download_hash_file_to_cache() ***');
|
||||
// console.log('Download hash file to cache');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
console.log(`*** Electron framework export: download_hash_file_to_cache() *** Base URL: ${api_base_url}; Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
|
||||
@@ -216,27 +219,42 @@ exports.download_hash_file_to_cache = async function ({host_file_cache_path, eve
|
||||
}
|
||||
|
||||
let hash_file_cache_path = path.join(subdirectory_path, hash_filename);
|
||||
// console.log(hash_file_cache_path);
|
||||
if (fs.existsSync(hash_file_cache_path)) {
|
||||
if (check_hash) {
|
||||
const file_buffer = fs.readFileSync(hash_file_cache_path);
|
||||
const file_hash_sha256 = crypto.createHash('sha256');
|
||||
file_hash_sha256.update(file_buffer);
|
||||
|
||||
let download_file_result = await ipcRenderer.invoke('download_file', api_server_base_url, endpoint, hash_file_cache_path).then((result) => {
|
||||
console.log('IPC download file process finished');
|
||||
console.log(result);
|
||||
return true;
|
||||
});
|
||||
|
||||
// console.log(download_file_result);
|
||||
// console.log('End: download_hash_file_to_cache()');
|
||||
if (download_file_result) {
|
||||
console.log('File downloaded successfully');
|
||||
return true;
|
||||
} else {
|
||||
console.log('File was not downloaded successfully');
|
||||
return false;
|
||||
const file_hash_sha256_check = file_hash_sha256.digest('hex');S
|
||||
if (file_hash_sha256_check == hash) {
|
||||
console.log('File hash match', file_hash_sha256_check);
|
||||
return true;
|
||||
} else {
|
||||
// This should only happen if the file is actively being downloaded or it is corrupt.
|
||||
console.log('File hash does not match', file_hash_sha256_check);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(`!!!ABOUT TO CALL DOWNLOAD FILE HANDLER!!! exports.download_hash_file_to_cache(); Base URL: ${api_base_url}`);
|
||||
let download_file_result = await ipcRenderer.invoke('download_file', api_base_url, endpoint, hash_file_cache_path).then((result) => {
|
||||
if (result) {
|
||||
console.log('IPC download file process finished successfully');
|
||||
return true;
|
||||
} else {
|
||||
console.log('IPC Download Result:', result);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
// console.log(`!!!DONE WITH DOWNLOAD FILE HANDLER!!! exports.download_hash_file_to_cache(); Base URL: ${api_base_url}`);
|
||||
|
||||
return download_file_result;
|
||||
}
|
||||
|
||||
|
||||
// Open cached hash file after copying to temp directory
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-05-06
|
||||
exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework export: open_hash_file_to_temp() ***');
|
||||
@@ -273,6 +291,8 @@ exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, ho
|
||||
|
||||
|
||||
// Open local file
|
||||
// Used by Svelte Event Launcher
|
||||
// NOTE: Trying to replace this with something directly in the Svelte app part. 2022-10-11
|
||||
// Updated 2022-03-10
|
||||
exports.open_local_file = async function ({local_file_path, filename}) {
|
||||
console.log('*** Electron framework export: open_local_file() ***');
|
||||
@@ -307,65 +327,65 @@ exports.open_local_file = async function ({local_file_path, filename}) {
|
||||
}
|
||||
|
||||
|
||||
// Check local file cache and download from server if needed.
|
||||
// Updated 2022-03-09
|
||||
// exports.check_file_cache = async function ({host_file_cache_path, event_file_id, hash}) {
|
||||
exports.check_file_cache = async function ({host_file_cache_path, event_file_id, hash}) {
|
||||
console.log('*** Electron framework export: check_file_cache() ***');
|
||||
// console.log('Check local file cache and download from server if needed.');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
// // Check local file cache and download from server if needed.
|
||||
// // Updated 2022-03-09
|
||||
// // exports.check_file_cache = async function ({host_file_cache_path, event_file_id, hash}) {
|
||||
// exports.check_file_cache = async function ({api_base_url, host_file_cache_path, event_file_id, hash}) {
|
||||
// console.log('*** Electron framework export: check_file_cache() ***');
|
||||
// // console.log('Check local file cache and download from server if needed.');
|
||||
// console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
|
||||
// NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
let hash_filename = hash+'.file';
|
||||
// // NOTE: event_file_id is the event_file.id_random or event_file.event_file_id_random
|
||||
// let hash_filename = hash+'.file';
|
||||
|
||||
let save_path = path.join(host_file_cache_path, hash_filename);
|
||||
console.log(save_path);
|
||||
// let save_path = path.join(host_file_cache_path, hash_filename);
|
||||
// console.log(save_path);
|
||||
|
||||
if (fs.existsSync(save_path)) {
|
||||
console.log('Hashed file cache already exists: '+save_path);
|
||||
return true;
|
||||
} else {
|
||||
console.log('Hashed file not found in local cache. Downloading file: '+save_path);
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
let result = await ipcRenderer.send('download_file', api_server_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
console.log(result);
|
||||
// if (fs.existsSync(save_path)) {
|
||||
// console.log('Hashed file cache already exists: '+save_path);
|
||||
// return true;
|
||||
// } else {
|
||||
// console.log('Hashed file not found in local cache. Downloading file: '+save_path);
|
||||
// let endpoint = `/event/file/${event_file_id}/download`;
|
||||
// let result = await ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
// console.log(result);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once('download_file_reply', function(event, response){
|
||||
console.log(response);
|
||||
return response;
|
||||
})
|
||||
resolve(true);
|
||||
});
|
||||
// return new Promise((resolve, reject) => {
|
||||
// ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// console.log(response);
|
||||
// return response;
|
||||
// })
|
||||
// resolve(true);
|
||||
// });
|
||||
|
||||
// await ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// console.log(response);
|
||||
// return response;
|
||||
// });
|
||||
// // await ipcRenderer.once('download_file_reply', function(event, response){
|
||||
// // console.log(response);
|
||||
// // return response;
|
||||
// // });
|
||||
|
||||
// result.then(function (response) {
|
||||
// console.log('Downloaded!!!???');
|
||||
// return true;
|
||||
// }).catch(function (error) {
|
||||
// console.log(error);
|
||||
// return false;
|
||||
// });
|
||||
// // result.then(function (response) {
|
||||
// // console.log('Downloaded!!!???');
|
||||
// // return true;
|
||||
// // }).catch(function (error) {
|
||||
// // console.log(error);
|
||||
// // return false;
|
||||
// // });
|
||||
|
||||
// return result;
|
||||
// // return result;
|
||||
|
||||
// console.log(result);
|
||||
// if (result) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
}
|
||||
// // console.log(result);
|
||||
// // if (result) {
|
||||
// // return true;
|
||||
// // } else {
|
||||
// // return false;
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Check local file cache and download from server if needed. Must use IPC to Main to download file. Set a Promise to wait for download_file_reply.
|
||||
// Updated 2022-03-09
|
||||
async function check_file_cache({host_file_cache_path, event_file_id, hash}) {
|
||||
async function check_file_cache({api_base_url, host_file_cache_path, event_file_id, hash}) {
|
||||
console.log('*** Electron framework: check_file_cache() ***');
|
||||
// console.log('Check local file cache and download from server if needed.');
|
||||
console.log(`Host File Cache Path: ${host_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`);
|
||||
@@ -382,7 +402,7 @@ async function check_file_cache({host_file_cache_path, event_file_id, hash}) {
|
||||
} else {
|
||||
console.log('Hashed file not found in local cache. Downloading file: '+save_path);
|
||||
let endpoint = `/event/file/${event_file_id}/download`;
|
||||
let result = await ipcRenderer.send('download_file', api_server_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
let result = await ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread.
|
||||
console.log(result);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -436,6 +456,7 @@ async function open_local_file({host_file_cache_path, hash, host_file_temp_path,
|
||||
}
|
||||
|
||||
|
||||
// No longer needed? Not referenced as of 2022-10-11
|
||||
exports.check_file_cache_and_open_local_file = async function ({host_file_cache_path, event_file_id, hash, host_file_temp_path, filename}) {
|
||||
console.log('*** Electron framework: check_file_cache_and_open_local_file() ***');
|
||||
console.log('Checking the local file cache against the remote server and then opening the local file.');
|
||||
|
||||
Reference in New Issue
Block a user