Working on rewrite version 3. Focus on caching for now.

This commit is contained in:
Scott Idem
2022-03-07 18:21:05 -05:00
parent a72cb27ed8
commit 1d7c14dedb
16 changed files with 695 additions and 635 deletions

View File

@@ -15,7 +15,7 @@ body {
/* Display */
/* Center and scale the image nicely */
background-color: steelblue;
background-image: url('/static/images/site_background.webp'); /* "/static/images/site_background.webp" */
background-image: url('../static/images/site_background.svg');
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;

View File

@@ -1,7 +1,7 @@
body {
background-color: steelblue;
/* https://app.haikei.app/ */
background-image: url('/static/images/site_background.svg');
background-image: url('../static/images/site_background.svg');
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;

View File

@@ -109,7 +109,7 @@
let api_update_datetime = Date.now();
let waiting_on_api_token = false;
const secret_key = app_config.api_secret_key;
const api_secret_key = app_config.api_secret_key;
let api_temporary_token = null;
let api_base_url = null; // 'http://api.localhost:5001' 'https://api.oneskyit.com'
@@ -135,8 +135,8 @@
//console.log('****************** LOOP: API Token Loop ******************');
if (app_online && api_update_datetime < Date.now()) {
//let api_temporary_token_result = api_token_request_async(axios, secret_key)
api_temporary_token = await api_token_request_async(axios, secret_key)
//let api_temporary_token_result = api_token_request_async(axios, api_secret_key)
api_temporary_token = await api_token_request_async(axios, api_secret_key)
.then(function (result) {
if (result) {
console.log('Setting temporary API token to axios Authorization header: '+result);

View File

@@ -56,7 +56,8 @@
<script src="https://static.oneskyit.com/js/utilities.js"></script>
<script defer src="svelte/build/bundle.js" crossorigin></script>
<!-- <script defer src="svelte/build/bundle.js" crossorigin></script> -->
<script defer src="http://dev.oneskyit.local:5000/static/svelte/build/bundle.js" crossorigin></script>
<!-- JavaScript (JS) end -->
</head>
@@ -83,6 +84,7 @@
<!-- One Sky IT site custom JavaScript (JS) -->
<script>const app = require('./js/module_app');</script>
<script src="js/app_v3.js"></script>
<!-- <script src="js/app_api.js"></script> -->
<!-- <script src="js/app_idb.js"></script> -->
<!-- <script src="js/app_ui_misc.js"></script> -->
@@ -103,13 +105,16 @@ const app_env = 'development_local'; // 'development_local', 'development_remote
const api_env = 'development_local'; // 'development_local', 'development_remote'
const app_mode = 'onsite'; // null, 'default', 'onsite'
let account_id = app_config.account_id;
let client_account_id = app_config.account_id;
console.log(client_account_id);
let event_id = app_config.event_id;
let event_location_id = app_config.event_location_id;
const page_for = { 'event': event_id, 'event_location': event_location_id }; // Simple key value like object
console.log(page_for);
const host_file_cache_path = app_config.host_file_cache_path; // 'file_cache/'
/* ***** **** *** ** * ### * ** *** **** ***** */
@@ -121,7 +126,9 @@ console.log(page_for);
// let api_update_datetime = Date.now();
// let waiting_on_api_token = false;
const secret_key = app_config.api_secret_key;
const access_control_allow_origin = app_config.access_control_allow_origin;
const api_secret_key = app_config.api_secret_key;
console.log(api_secret_key);
let api_temporary_token = null;
let api_base_url = null;

20
app/js/app_v3.js Normal file
View File

@@ -0,0 +1,20 @@
const path = require('path');
const { ipcRenderer } = require('electron');
/* Updated 2022-03-07 */
// function open_local_file({hash, host_file_cache_path, filename}) {
function open_local_file({host_file_cache_path, hash, filename}) {
console.log('*** open_local_file() ***');
// hash = this.getAttribute('data-hash_sha256');
// let file_path = path.join(host_file_cache_path, hash);
// filename = this.getAttribute('data-filename');
console.log(host_file_cache_path);
console.log(hash);
// console.log(file_path);
console.log(filename);
// ipcRenderer.send('open_local_file', file_path, filename);
ipcRenderer.send('open_local_file', host_file_cache_path, hash, filename);
}

View File

@@ -15,7 +15,7 @@ if(fs.existsSync(filename)) {
})
}
//shell.openItem('test.txt');
//shell.openPath('test.txt');
/*
const path = './';

View File

@@ -69,6 +69,28 @@ exports.load_config = function () {
}
exports.check_file_cache_v3 = async function (host_file_cache_path, event_file_id, hash) {
console.log('**** *** ** * FUNCTION: check_file_cache_v3 * ** *** ****');
console.log('Checking the local file cache against the remote server.');
event_file_id; // NOTE: This 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);
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 endpoint = `/event/file/${event_file_id}/download`;
ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread.
}
return true;
}
exports.check_file_cache = async function () {
console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****');
console.log('Checking the local file cache against the remote server.');

BIN
app/static/images/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -94,16 +94,19 @@ app.on('activate', () => {
})
ipcMain.on('download_file', (event, api_base_url, api_endpoint, api_temporary_token, save_path) => {
console.log('ipcMain on download_file: api_base_url='+api_base_url+' | api_temporary_token='+api_temporary_token);
console.log(api_temporary_token);
// ipcMain.on('download_file', (event, api_base_url, api_endpoint, api_temporary_token, save_path) => {
ipcMain.on('download_file', (event, api_base_url, api_endpoint, save_path) => {
console.log('*** call IPC download_file() ***');
// console.log('ipcMain on download_file: api_base_url='+api_base_url+' | api_temporary_token='+api_temporary_token);
console.log('ipcMain on download_file: api_base_url='+api_base_url);
// console.log(api_temporary_token);
console.log('ipcMain download and save file: '+api_endpoint+' -> '+save_path);
axios.defaults.baseURL = api_base_url;
axios.defaults.headers.common['Access-Control-Allow-Origin'] = access_control_allow_origin;
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*'; // app_config.access_control_allow_origin;
axios.defaults.headers.common['content-type'] = 'application/json';
axios.defaults.headers.common['x-aether-api-key'] = api_secret_key;
axios.defaults.headers.common['x-account-id'] = account_id;
axios.defaults.headers.common['x-aether-api-key'] = 'dFP6J9DVj9hUgIMn-fNIqg'; // api_secret_key;
axios.defaults.headers.common['x-account-id'] = '_XY7DXtc9MY'; // account_id;
const url = api_endpoint;
@@ -118,12 +121,19 @@ ipcMain.on('download_file', (event, api_base_url, api_endpoint, api_temporary_to
ipcMain.on('open_local_file', (event, file_path, filename) => {
console.log('ipcMain open local file: '+file_path+' -> '+filename);
// ipcMain.on('open_local_file', (event, file_path, filename) => {
// ipcMain.on('open_local_file', ({host_file_cache_path, hash, filename}) => {
ipcMain.on('open_local_file', (event, host_file_cache_path, hash, filename) => {
console.log(host_file_cache_path);
console.log('ipcMain open local file: '+host_file_cache_path+' -> '+filename);
cache_file_path = path.join(process.cwd(), file_path);
let cache_file_path = path.join(process.cwd(), host_file_cache_path);
console.log(cache_file_path);
let hash_filename = hash+'.file';
let full_cache_file_path = path.join(cache_file_path, hash_filename);
console.log(full_cache_file_path);
open_file_path = path.join(process.cwd(), 'temp/', filename);
console.log(open_file_path);
@@ -136,11 +146,11 @@ ipcMain.on('open_local_file', (event, file_path, filename) => {
console.log('File copy already exists: '+open_file_path);
} else {
//console.log('Creating file link: '+open_file_path);
//fs.linkSync(cache_file_path, open_file_path);
//fs.linkSync(full_cache_file_path, open_file_path);
console.log('Copying file to temp: '+open_file_path);
fs.copyFileSync(cache_file_path, open_file_path);
fs.copyFileSync(full_cache_file_path, open_file_path);
}
shell.openItem(open_file_path);
shell.openPath(open_file_path);
//fs.open(open_file_path);
});