More work on the posters and Websockets

This commit is contained in:
Scott Idem
2025-10-13 17:19:32 -04:00
parent de071dae49
commit 8f7c1bf428
7 changed files with 108 additions and 52 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
interface Props {
log_lvl?: number;
// *** Export/Exposed variables and functions for component
event_file_id: string;
event_file_obj: any;
// export let os: string = null;
max_filename_length?: number;
@@ -16,11 +16,16 @@ interface Props {
session_type?: string; // oral, poster, workshop, symposium, roundtable, other
open_method?: null|string; // modal, download, native open (download, cache, copy, open), URL
modal_title?: string;
modal__title?: any;
modal__open_event_file_id?: any;
modal__event_file_obj?: any;
}
let {
log_lvl = 0,
event_file_obj,
event_file_id,
event_file_obj = $bindable({}),
max_filename_length = 50,
hide_launch_icon = false,
hide_meta = false,
@@ -31,7 +36,11 @@ let {
btn_size = 'btn_md',
session_type = 'oral',
open_method = 'download',
modal_title = $bindable('')
modal_title = $bindable(''),
modal__title = $bindable(''),
modal__open_event_file_id = $bindable(null),
modal__event_file_obj = $bindable(null),
}: Props = $props();
// *** Import Svelte specific
@@ -51,6 +60,7 @@ import { events_loc, events_sess, events_slct, events_trigger } from '$lib/ae_ev
import { events_func } from '$lib/ae_events_functions';
import Element_ae_crud from '$lib/element_ae_crud.svelte';
import { modal } from 'flowbite-svelte';
// *** Functions and Logic
@@ -71,9 +81,9 @@ let screen_saver_exts = ['jpg', 'png', 'PNG', 'webp'];
if (screen_saver_exts.includes(event_file_obj.extension)) {
// $events_loc.launcher.screen_saver_img_kv.push(event_file_obj);
// $events_loc.launcher.screen_saver_img_kv[event_file_obj.event_file_id_random] = event_file_obj;
// $events_loc.launcher.screen_saver_img_kv[event_file_id] = event_file_obj;
$events_loc.launcher.screen_saver_img_kv[event_file_obj.event_file_id_random] = Object.create(event_file_obj);
$events_loc.launcher.screen_saver_img_kv[event_file_id] = Object.create(event_file_obj);
// let temp_obj = Object.create(event_file_obj)
@@ -87,7 +97,7 @@ onMount(() => {
console.log(`Session Type: ${session_type}; Open Method: ${open_method}`);
if (screen_saver_exts.includes(event_file_obj.extension)) {
// $events_loc.launcher.screen_saver_img_kv[event_file_obj.event_file_id_random] = event_file_obj;
// $events_loc.launcher.screen_saver_img_kv[event_file_id] = event_file_obj;
let temp_obj = Object.create(event_file_obj)
@@ -151,7 +161,7 @@ async function handle_open_file() {
console.log(`Cached hash file not found. Need to download from API server. Base URL ${$events_loc.launcher.api.base_url}`);
open_file_status = 'downloading_file';
open_file_status_message = 'Downloading file...';
let download_hash_file_to_cache_result = await native_app.download_hash_file_to_cache_v2({api_base_url: $events_loc.launcher.api.base_url, api_base_url_backup: $events_loc.launcher.api.base_url_backup, local_file_cache_path: $events_loc.launcher.local_file_cache_path, event_file_id: event_file_obj.event_file_id_random, hash: event_file_obj.hash_sha256, verify_hash: true, overwrite_existing: false});
let download_hash_file_to_cache_result = await native_app.download_hash_file_to_cache_v2({api_base_url: $events_loc.launcher.api.base_url, api_base_url_backup: $events_loc.launcher.api.base_url_backup, local_file_cache_path: $events_loc.launcher.local_file_cache_path, event_file_id: event_file_id, hash: event_file_obj.hash_sha256, verify_hash: true, overwrite_existing: false});
// console.log(download_hash_file_to_cache_result);
if (download_hash_file_to_cache_result) {
console.log('Hash file downloaded to cache.');
@@ -238,7 +248,7 @@ async function handle_open_file() {
// $events_loc.launcher.event_poster_file_type = 'video';
// }
// $events_loc.launcher.poster_src = `/event/file/${event_file_obj.event_file_id_random}/download`;
// $events_loc.launcher.poster_src = `/event/file/${event_file_id}/download`;
// $events_loc.launcher.modal_title = modal_title;
// }
</script>
@@ -293,7 +303,7 @@ async function handle_open_file() {
<!-- First [WORKING!] - Handle opening using a modal. This applies to all Launcher app modes (default, onsite, native) -->
{#if (session_type == 'poster' || open_method == 'modal')}
<!-- <a
href="/event/file/{event_file_obj.event_file_id_random}/download"
href="/event/file/{event_file_id}/download"
download
class="ae_btn btn_info {btn_size}"
on:click|preventDefault={() => {handle_open_method_poster();}}
@@ -306,19 +316,28 @@ async function handle_open_file() {
<button
type="button"
onclick={() => {
$events_sess.launcher.modal__open = event_file_obj.event_file_id_random;
if (!modal_title) {
modal_title = event_file_obj.filename;
}
$events_sess.launcher.modal__title = modal_title;
// $events_sess.launcher.modal__img_src = `/event/file/${event_file_obj.event_file_id_random}/download`;
// modal__title = modal_title;
modal__open_event_file_id = event_file_id;
modal__event_file_obj = event_file_obj;
$events_slct.event_file_id = event_file_obj.event_file_id_random;
// $events_sess.launcher.modal__open_event_file_id = event_file_id;
// $events_sess.launcher.modal__open = event_file_id;
// $events_sess.launcher.modal__open_event_file_id = event_file_id;
// $events_sess.launcher.modal__event_file_obj = event_file_obj;
if (!modal__title) {
modal__title = event_file_obj.filename;
}
// $events_sess.launcher.modal__title = modal__title;
// $events_sess.launcher.modal__img_src = `/event/file/${event_file_id}/download`;
$events_slct.event_file_id = event_file_id;
$events_slct.event_file_obj = event_file_obj;
// let as_modal_result = open_event_file_as_modal({
// event_file_id: event_file_obj.event_file_id_random,
// event_file_id: event_file_id,
// filename: event_file_obj.filename,
// extension: event_file_obj.extension,
// modal_title: modal_title
@@ -331,8 +350,8 @@ async function handle_open_file() {
// }
if ($events_loc.launcher.controller == 'local_push') {
console.log(`Local Push Controller Command: ae_open:event_file=${event_file_obj.event_file_id_random}`);
$events_sess.launcher.controller_cmd = `ae_open:event_file=${event_file_obj.event_file_id_random}`;
console.log(`Local Push Controller Command: ae_open:event_file=${event_file_id}`);
$events_sess.launcher.controller_cmd = `ae_open:event_file=${event_file_id}`;
$events_sess.launcher.controller_trigger_send = true;
// tick();
@@ -343,10 +362,10 @@ async function handle_open_file() {
data_kv: {
name: `Open Poster: ${event_file_obj.filename}`,
object_type: 'event_file',
object_id_random: event_file_obj.event_file_id_random,
object_id_random: event_file_id,
action: 'open_poster_w_controller',
meta_json: {
event_file_id: event_file_obj.event_file_id_random,
event_file_id: event_file_id,
filename: event_file_obj.filename,
extension: event_file_obj.extension,
modal_title: modal_title
@@ -361,15 +380,16 @@ async function handle_open_file() {
preset-tonal-primary border border-primary-500
min-w-96
"
title={`Open this file in a modal window:\n${event_file_obj.filename}\n[API] SHA256: ${event_file_obj.hash_sha256.slice(0, 10)}...\nHosted ID: ${event_file_obj.hosted_file_id_random} Event File ID: ${event_file_obj.event_file_id_random}`}
title={`Open this file in a modal window:\n${event_file_obj.filename}\n[API] SHA256: ${event_file_obj.hash_sha256.slice(0, 10)}...\nHosted ID: ${event_file_obj.hosted_file_id_random} Event File ID: ${event_file_id}`}
>
{#if (screen_saver_exts.includes(event_file_obj.extension))}
<span class="fas fa-chart-bar m-1" class:hidden="{hide_launch_icon}"></span>
Open Poster {event_file_obj.event_file_id}
Open Poster {event_file_id}
{:else}
<span class="fas fa-paper-plane m-1" class:hidden="{hide_launch_icon}"></span>
{ae_util.shorten_filename({filename: event_file_obj.filename, max_length: max_filename_length})}
{/if}
{$events_sess.launcher.modal__open_event_file_id ?? '-- not set --'}
</button>
@@ -377,7 +397,7 @@ async function handle_open_file() {
<!-- Second [NOT WORKING!!!] - Handle opening a file. This applies to all Launcher app modes (default, onsite, native) -->
{:else if ($events_loc.launcher.app_mode == 'native')}
<a
href="/event/file/{event_file_obj.event_file_id_random}/download?use_os=true"
href="/event/file/{event_file_id}/download?use_os=true"
download
class="ae_btn btn_info {btn_size}"
onclick={preventDefault(() => {handle_open_file();})}
@@ -392,7 +412,7 @@ async function handle_open_file() {
<!-- Third [NOT WORKING!!!] - Handle opening a file. This applies to all Launcher app modes (default, onsite, native) -->
<!-- {:else if ($events_loc.launcher.app_mode == 'onsite' && (event_file_obj.extension == 'ppt' || event_file_obj.extension == 'pptx') && event_file_obj.open_in_os == 'win')}
<a
href="/event/file/{event_file_obj.event_file_id_random}/download?use_os=true" download
href="/event/file/{event_file_id}/download?use_os=true" download
class="ae_btn btn_info {btn_size}"
on:click={() => {handle_open_file();}}
data-hash_sha256={event_file_obj.hash_sha256}
@@ -415,8 +435,8 @@ async function handle_open_file() {
new_filename = event_file_obj.filename + 'win';
}
// ae_promises[event_file_obj.event_file_id_random]
ae_promises[event_file_obj.event_file_id_random] = api.download_hosted_file({
// ae_promises[event_file_id]
ae_promises[event_file_id] = api.download_hosted_file({
api_cfg: $ae_api,
hosted_file_id: event_file_obj.hosted_file_id_random, // +'x'
return_file: true,
@@ -425,7 +445,7 @@ async function handle_open_file() {
log_lvl: 1
});
// window.postMessage({ type: 'download_event_file', event_file_id: event_file_obj.event_file_id_random, filename: event_file_obj.filename, auto_download: true }, '*');
// window.postMessage({ type: 'download_event_file', event_file_id: event_file_id, filename: event_file_obj.filename, auto_download: true }, '*');
if ($events_loc.launcher.controller == 'local_push') {
console.log(`Local Push Controller Command: ae_download:hosted_file=${event_file_obj.hosted_file_id_random}`);
@@ -439,9 +459,9 @@ async function handle_open_file() {
preset-tonal-primary border border-primary-500
min-w-72 lg:min-w-96
"
title={`Download this file:\n${event_file_obj.filename}\n[API] SHA256: ${event_file_obj.hash_sha256.slice(0, 10)}...\nHosted ID: ${event_file_obj.hosted_file_id_random} Event File ID: ${event_file_obj.event_file_id_random}`}
title={`Download this file:\n${event_file_obj.filename}\n[API] SHA256: ${event_file_obj.hash_sha256.slice(0, 10)}...\nHosted ID: ${event_file_obj.hosted_file_id_random} Event File ID: ${event_file_id}`}
>
{#await ae_promises[event_file_obj.event_file_id_random]}
{#await ae_promises[event_file_id]}
<span class="text-sm">
<span class="fas fa-spinner fa-spin mx-0.5"></span>
<span class="">
@@ -503,8 +523,8 @@ async function handle_open_file() {
// new_filename = event_file_obj.filename + 'win';
// }
// ae_promises[event_file_obj.event_file_id_random]
ae_promises[event_file_obj.event_file_id_random] = api.download_hosted_file({
// ae_promises[event_file_id]
ae_promises[event_file_id] = api.download_hosted_file({
api_cfg: $ae_api,
hosted_file_id: event_file_obj.hosted_file_id_random, // +'x'
return_file: true,
@@ -513,7 +533,7 @@ async function handle_open_file() {
log_lvl: 1
});
// window.postMessage({ type: 'download_event_file', event_file_id: event_file_obj.event_file_id_random, filename: event_file_obj.filename, auto_download: true }, '*');
// window.postMessage({ type: 'download_event_file', event_file_id: event_file_id, filename: event_file_obj.filename, auto_download: true }, '*');
}}
class="event_file_os"
class:hidden="{hide_os || 1==1}"
@@ -532,7 +552,7 @@ async function handle_open_file() {
trigger_patch={ae_triggers.open_in_os}
api_cfg={$ae_api}
object_type={'event_file'}
object_id={event_file_obj.event_file_id_random}
object_id={event_file_id}
field_name={'open_in_os'}
field_type={'button'}
field_value={ae_tmp.value__open_in_os}
@@ -643,9 +663,9 @@ async function handle_open_file() {
<!-- {#if ($events_loc.launcher.app_mode == 'native' || $events_loc.launcher.app_mode == 'onsite')} -->
<!-- {#if (show_bak_download)} -->
<!-- <a href="/event/file/{event_file_obj.event_file_id_random}/download" class="event_file_download" class:hidden="{!show_bak_download}" title="Download with original filename and extension"><span class="fas fa-download"></span></a> -->
<!-- <a href="/event/file/{event_file_id}/download" class="event_file_download" class:hidden="{!show_bak_download}" title="Download with original filename and extension"><span class="fas fa-download"></span></a> -->
<!-- <a href="/event/file/{event_file_obj.event_file_id_random}/download?filename={event_file_obj.filename}&use_os=true" class="ae_btn btn_info {btn_size}">{event_file_obj.filename}</a> -->
<!-- <a href="/event/file/{event_file_id}/download?filename={event_file_obj.filename}&use_os=true" class="ae_btn btn_info {btn_size}">{event_file_obj.filename}</a> -->
<!-- {/if} -->
</span>
@@ -656,7 +676,7 @@ async function handle_open_file() {
// if (!confirm('Download file from API server?')) {
// return false;
// }
download_event_file({ 'event_file_id': event_file_obj.event_file_id_random, 'return_file': true, filename: event_file_obj.filename, auto_download: true, log_lvl: 1 });
download_event_file({ 'event_file_id': event_file_id, 'return_file': true, filename: event_file_obj.filename, auto_download: true, log_lvl: 1 });
}}
title="Download file from API server?"
>