diff --git a/app/script.current.js b/app/script.current.js index 6b4257c..8164d03 100644 --- a/app/script.current.js +++ b/app/script.current.js @@ -513,7 +513,7 @@ exports.download_hash_file_to_cache = async function ({api_base_url, local_file_ // Download hash file to cache // Used by Svelte Event Launcher -// Updated 2022-10-12 +// Updated 2023-05-26 exports.download_hash_file_to_cache_v2 = async function ({api_base_url, api_base_url_backup, local_file_cache_path, event_file_id=null, hash=null, verify_hash=true, overwrite_existing=false}) { console.log('*** Aether App Native export: download_hash_file_to_cache_v2() ***'); console.log(`Base URL: ${api_base_url}; Base URL Backup: ${api_base_url_backup}; Host File Cache Path: ${local_file_cache_path}; Event File ID: ${event_file_id}; Hash: ${hash}`); @@ -568,15 +568,56 @@ exports.download_hash_file_to_cache_v2 = async function ({api_base_url, api_base } } + const tmp_full_save_path = full_cached_hash_path+'.tmp'; + + if (fs.existsSync(tmp_full_save_path)) { + console.log(`A temp download file was found! ${tmp_full_save_path}`); + + let stats = null; + try { + stats = fs.statSync(tmp_full_save_path); + + // console.log(`File Accessed Last: ${stats.atime}`); // File data last changed (actual contents) + console.log(`File Data Last Modified: ${stats.mtime}`); // File data last changed (actual contents) + console.log(`File Metadata Last Modified: ${stats.ctime}`); // File metadata last changed (filename, permissions, etc) + } catch (error) { + console.log(error); + } + + let current_datetime = new Date(); + let offset_minutes = 3; // In minutes. 5 minutes of no changes to the file content seems reasonable? Trying with 3 minutes 2022-10-12 + let offset_datetime = new Date(current_datetime.getTime() - offset_minutes*60000); + + // console.log(`Times: ${current_datetime} ${offset_datetime} | File ${stats.mtime}`); + if (stats.mtime < offset_datetime) { + // console.log(`Marking as expired temp file based on modified datetime. Expire after: ${offset_minutes} minutes`); + // overwrite_existing = true; + } else { + console.log(`Temp download file has not expired yet. Expire after: ${offset_minutes} minutes`); + // return false; + return 'tmp'; + } + } + + console.log(`Trying IPC API download from: ${api_base_url}`); let download_file_result = await ipcRenderer.invoke('download_file', api_base_url, endpoint, full_cached_hash_path, hash, verify_hash, overwrite_existing).then(async (result) => { + if (result) { - console.log('IPC download file process finished successfully'); + console.log(`IPC API download file process finished successfully: ${hash}`); return true; } else if (result == null) { - console.log('IPC Download Result (file not found?):', result); + console.log(`IPC API download result (file not found?):`, result); return null; + } else if (result === 'in_progress') { + console.log(`IPC API primary download IN PROGRESS: ${hash}`); + // return false; // Should return result instead??? + return result; + } else if (result === 'tmp') { + console.log(`IPC API primary download FOUND TMP: ${hash}`); + // return false; // Should return result instead??? + return result; } else { - console.log('IPC Download Result (file being downloaded or something went wrong):', result); + console.log(`IPC API download result (file being downloaded or something went wrong): ${hash}`, result); return false; // if (api_base_url_backup) { @@ -601,17 +642,19 @@ exports.download_hash_file_to_cache_v2 = async function ({api_base_url, api_base // }); }).then(async (result) => { if (result === false) { + console.log(`IPC API primary download FAILED!`); // Trying again with backup API server. API Backup: ${api_base_url_backup}`); if (api_base_url_backup) { - console.log(`IPC Download FAILED! Trying again with backup API server. API Backup: ${api_base_url_backup}`); + console.log(`IPC API primary download FAILED! Trying again with backup API server. API Backup: ${api_base_url_backup}`); + console.log(`Trying IPC API backup download from: ${api_base_url_backup}`); let download_backup_file_result = await ipcRenderer.invoke('download_file', api_base_url_backup, endpoint, full_cached_hash_path, hash, verify_hash, overwrite_existing).then((result_backup) => { if (result_backup) { - console.log('IPC download file (from backup) process finished successfully'); + console.log(`IPC API backup download file (from backup) process finished successfully: ${hash}`); return true; } else if (result_backup == null) { - console.log('IPC Download Result (from backup) (file not found?):', result_backup); + console.log('IPC API backup download result (file not found?):', result_backup); return null; } else { - console.log('IPC Download Result (from backup) (file being downloaded or something went wrong):', result_backup); + console.log(`IPC API backup download result (file being downloaded or something went wrong): ${hash}`, result_backup); return false; } }); @@ -621,6 +664,12 @@ exports.download_hash_file_to_cache_v2 = async function ({api_base_url, api_base return false; } + } else if (result === 'in_progress') { + console.log(`IPC API primary download IN PROGRESS: ${hash}`); + return false; // Should return result instead??? + } else if (result === 'tmp') { + console.log(`IPC API primary download FOUND TMP: ${hash}`); + return false; // Should return result instead??? } else { return result; } diff --git a/index.js b/index.js index 6dff36c..78b4fda 100644 --- a/index.js +++ b/index.js @@ -311,7 +311,8 @@ ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_s overwrite_existing = true; } else { console.log(`Temp download file has not expired yet. Expire after: ${offset_minutes} minutes`); - return false; + // return false; + return 'tmp'; } } if (fs.existsSync(full_save_path)) { @@ -339,7 +340,8 @@ ipcMain.handle('download_file', async (event, api_base_url, api_endpoint, full_s console.log('Endpoints in Progress:', endpoints_in_progress); if (endpoints_in_progress.includes(api_endpoint)) { console.log(`Endpoint already being downloaded: ${api_endpoint}`); - return false; + // return false; + return 'in_progress'; } // console.log(`Done with checks. Time to download! Endpoint: ${api_endpoint}`); endpoints_in_progress.push(api_endpoint);