refactor(lib): standardize helpers and format shared components

- Applied snake_case helper standardization and formatting to element_input_file, hosted_files_clip_video, and websocket_v2.
- Cleaned up deprecated legacy imports.
This commit is contained in:
Scott Idem
2026-02-06 14:49:36 -05:00
parent 969e5610bb
commit 67752ccdfe
3 changed files with 131 additions and 47 deletions

View File

@@ -7,7 +7,14 @@
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { api } from '$lib/api';
import { check_hosted_file_obj_w_hash } from '$lib/ae_core/core__check_hosted_file_obj_w_hash';
import { ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
import {
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
const dispatch = createEventDispatcher();
@@ -37,7 +44,16 @@
multiple = true,
required = true,
accept = 'audio/*, image/*, video/*, .bak, .cfg, .css, .csv, .doc, .docx, .gz, .htm, .html, .ini, .iso, .j2, .json, .key, .keynote, .md, .pdf, .ppt, .pptx, .rar, .rtf, .sql, .svelte, ttf, .txt, .xls, .xlsx, .xz, .zip, .bin, .dmg, .exe, .js, .msi, .php, .py, .sh',
untrusted_extension_list = ['bin', 'dmg', 'exe', 'js', 'msi', 'php', 'py', 'sh'],
untrusted_extension_list = [
'bin',
'dmg',
'exe',
'js',
'msi',
'php',
'py',
'sh'
],
legacy_extension_list = ['avi', 'doc', 'ppt', 'xls', 'wmv'],
use_selected_file_table = true,
file_list_status = $bindable(null),
@@ -74,7 +90,9 @@
// console.log('*** Start ***');
// for (let [i, file_item] of file_list.entries()) { // Not sure why this does not work???
for await (const [i, file_item] of Array.prototype.entries.call(file_list)) {
for await (const [i, file_item] of Array.prototype.entries.call(
file_list
)) {
console.log(i, file_item);
// NOTE: The file list is readonly. The filenames can not be changed here.
@@ -208,7 +226,8 @@
} else {
}
file_data['warning_untrusted_extension'] = warning_untrusted_extension;
file_data['warning_untrusted_extension'] =
warning_untrusted_extension;
file_data['warning_legacy_extension'] = warning_legacy_extension;
file_data['warning_size'] = warning_size;
@@ -226,7 +245,9 @@
let file_hash = null;
// Only hash files less than 2 GB (2147483648 bytes)!!!
console.log(`File size: ${file_size_bytes / 1048576} MB (${file_size_bytes} bytes)`);
console.log(
`File size: ${file_size_bytes / 1048576} MB (${file_size_bytes} bytes)`
);
if (file_size_bytes < 2000000000) {
// > 2 GB 2 147 483 648
file_hash = await ae_util.get_file_hash(file_item);
@@ -243,10 +264,11 @@
);
file_data['hash_sha256'] = file_hash;
let check_hosted_file_obj_w_hash_result = await check_hosted_file_obj_w_hash({
api_cfg: $ae_api,
hosted_file_hash: file_hash
});
let check_hosted_file_obj_w_hash_result =
await check_hosted_file_obj_w_hash({
api_cfg: $ae_api,
hosted_file_hash: file_hash
});
// console.log(check_hosted_file_obj_w_hash_result);
@@ -282,7 +304,9 @@
const dt = new DataTransfer();
// let input = document.getElementById(input_element_id);
let input_element = document.querySelector('input[type="file"].svelte_input_file_element');
let input_element = document.querySelector(
'input[type="file"].svelte_input_file_element'
);
if (!input_element) {
console.error('Could not find the input element.');
@@ -370,7 +394,8 @@
<div
class="file_list_status ae_warning preset-tonal-warning border border-warning-500 p-1 m-1"
>
<span class="fas fa-spinner fa-spin m-1"></span> Processing selected file list...
<span class="fas fa-spinner fa-spin m-1"></span> Processing selected file
list...
</div>
{/if}
@@ -406,9 +431,13 @@
</button>
</td>
<td class="file_filename">{file_list_item.filename}</td>
<td class="file_last_modified">{file_list_item.modified_datetime_string}</td
<td class="file_last_modified"
>{file_list_item.modified_datetime_string}</td
>
<td
class="file_size"
class:bg-pink-200={file_list_item.warning_size}
>
<td class="file_size" class:bg-pink-200={file_list_item.warning_size}>
{file_list_item.file_size_string}
<!-- {#if $ae_sess.api_upload_kv[link_to_id]}
<span class="text-xs">({$ae_sess.api_upload_kv[link_to_id].percent_completed}%)</span>

View File

@@ -87,16 +87,24 @@
function ws_connect_group_id({ group_id, client_id }) {
if (!group_id) {
group_id = 'ae-grp-99';
console.log(`WS: No group_id specified! Setting to default: ${group_id}`);
console.log(
`WS: No group_id specified! Setting to default: ${group_id}`
);
return false;
}
if (!client_id) {
client_id = Date.now();
console.log(`WS: No client_id specified! Setting to current timestamp: ${client_id}`);
console.log(
`WS: No client_id specified! Setting to current timestamp: ${client_id}`
);
// return false;
}
console.log(`WS Connect URL: ${base_url}/group/${group_id}/client/${client_id}`);
let ws_connection = new WebSocket(`${base_url}/group/${group_id}/client/${client_id}`);
console.log(
`WS Connect URL: ${base_url}/group/${group_id}/client/${client_id}`
);
let ws_connection = new WebSocket(
`${base_url}/group/${group_id}/client/${client_id}`
);
ws_connection.onopen = function () {
console.log('WS: connected');
@@ -225,7 +233,10 @@
setTimeout(function () {
console.log('WS: Disconnected... Try again!');
ws_retry_count += 1;
ws_connect_group_id({ group_id: group_id, client_id: client_id });
ws_connect_group_id({
group_id: group_id,
client_id: client_id
});
console.log('WS: Again done?');
}, ws_retry_delay);
}
@@ -303,7 +314,10 @@
$effect(() => {
if (ws_connect && group_id) {
console.log('HERE!!!!!');
ws_group = ws_connect_group_id({ group_id: group_id, client_id: client_id });
ws_group = ws_connect_group_id({
group_id: group_id,
client_id: client_id
});
// } else if (!ws_connect) {
// console.log('HERE!!!!!');
// log_lvl = 1;
@@ -316,7 +330,9 @@
console.log('HERE!!!!!');
log_lvl = 1;
if (log_lvl) {
console.log(`WS: Not connecting. ws_connect=${ws_connect} group_id=${group_id}`);
console.log(
`WS: Not connecting. ws_connect=${ws_connect} group_id=${group_id}`
);
}
ws_group?.close();
ws_connect_status = 'disconnected';
@@ -485,7 +501,9 @@
class="input text-xs w-96"
/>
<button type="submit" class="btn btn-sm preset-tonal-warning">Send Group</button>
<button type="submit" class="btn btn-sm preset-tonal-warning"
>Send Group</button
>
</form>
{/if}
@@ -498,7 +516,9 @@ ae_open:event_file=Kljq0uiTlXt (video)
<!-- <hr> -->
<section class:hidden={hide__ws_messages}>
<h2 class="text-center underline">Messages [grp, client, target, type]</h2>
<h2 class="text-center underline">
Messages [grp, client, target, type]
</h2>
<ol class="list-decimal list-outside max-h-24 overflow-y-auto messages">
{#each ws_received_list_other as msg_entry, index (index)}
@@ -506,7 +526,8 @@ ae_open:event_file=Kljq0uiTlXt (video)
<div class="flex flex-row justify-between gap-1 w-full">
<span>
[{msg_entry.group_id || 'No Group ID'}]
{msg_entry.client_id.toString().slice(-5) || 'No Client ID'}
{msg_entry.client_id.toString().slice(-5) ||
'No Client ID'}
{msg_entry.target || 'No Target'}
|
@@ -535,7 +556,8 @@ ae_open:event_file=Kljq0uiTlXt (video)
<div class="flex flex-row justify-between gap-1 w-full">
<span>
[{cmd_entry.group_id || 'No Group ID'}]
{cmd_entry.client_id.toString().slice(-5) || 'No Client ID'}
{cmd_entry.client_id.toString().slice(-5) ||
'No Client ID'}
{cmd_entry.target || 'No Target'}
|