Trying to improve the hosted file manage.

This commit is contained in:
Scott Idem
2025-01-07 20:22:44 -05:00
parent 641c6b28c3
commit f8e88b0355
11 changed files with 1027 additions and 394 deletions

View File

@@ -0,0 +1,47 @@
/** @type {import('./$types').LayoutLoad} */
console.log(`IDAA BB - [account_id] +layout.ts start`);
import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
import { core_func } from '$lib/ae_core/ae_core_functions';
export async function load({ params, parent }) { // route
let log_lvl: number = 0;
let data = await parent();
data.log_lvl = log_lvl;
let account_id = data.account_id;
let ae_acct = data[account_id];
// console.log(`ae_acct = `, ae_acct);
if (!account_id) {
console.log(`ae Core - [account_id] +page.ts: The account_id was not found!!!`);
error(404, {
message: 'Account ID not found'
});
}
ae_acct.slct.account_id = account_id;
if (browser) {
let load_hosted_file_obj_li = core_func.load_ae_obj_li__hosted_file({
api_cfg: ae_acct.api,
for_obj_type: 'account',
for_obj_id: account_id,
enabled: 'enabled',
hidden: 'not_hidden',
limit: 99,
order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'},
try_cache: true,
log_lvl: log_lvl
});
console.log(`load_hosted_file_obj_li = `, load_hosted_file_obj_li);
ae_acct.slct.hosted_file_obj_li = load_hosted_file_obj_li;
}
// WARNING: Precaution against shared data between sites and sessions.
data[account_id] = ae_acct;
return data;
}

View File

@@ -12,9 +12,14 @@ import type { key_val } from '$lib/ae_stores';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
import Comp_hosted_files_clip_video from '$lib/ae_core/ae_comp__hosted_files_clip_video.svelte';
import Comp_hosted_files_clip_video_li from '$lib/ae_core/ae_comp__hosted_files_clip_video_li.svelte';
import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte';
let log_lvl = 1;
let ae_promises: key_val = {};
// export let container_class_li = [];
let file_uploads_post_promise;
@@ -31,9 +36,53 @@ let hosted_file_upload: key_val = {
// link_to_id: ae_loc.account_id,
hosted_file_id_li: [],
hosted_file_obj_li: [],
clip_complete: false,
upload_complete: false,
submit_status: null,
};
let hosted_file_clip: key_val = {
video_clip_file_kv: {},
clip_complete: false,
submit_status: null,
};
if (!$ae_loc.files) {
$ae_loc.files = {};
$ae_loc.files.processed_file_kv = {};
$ae_loc.files.uploaded_file_kv = {};
$ae_loc.files.video_clip_file_kv = {};
// $ae_loc.files.uploaded_file_list = [];
// $ae_loc.files.video_clip_file_list = [];
}
if (!$ae_loc.files.processed_file_kv) {
$ae_loc.files.processed_file_kv = {};
}
$: if ($ae_sess.files.upload_complete && $ae_sess.files.uploaded_file_li) {
// Append this list to the $ae_loc.files.uploaded_file_li list
$ae_loc.files.uploaded_file_li = [
...$ae_loc.files.uploaded_file_li,
...$ae_sess.files.uploaded_file_li
];
}
$: if ($ae_sess.files.upload_complete && $ae_sess.files.uploaded_file_kv) {
// Add this key-value pair to the $ae_loc.files.uploaded_file_kv object
$ae_loc.files.uploaded_file_kv = {
...$ae_loc.files.uploaded_file_kv,
...$ae_sess.files.uploaded_file_kv
};
}
$: if ($ae_sess.files.clip_complete && $ae_sess.files.video_clip_file_kv) {
// Add this key-value pair to the $ae_loc.files.video_clip_file_kv object
$ae_loc.files.video_clip_file_kv = {
...$ae_loc.files.video_clip_file_kv,
...$ae_sess.files.video_clip_file_kv
};
}
onMount(() => {
console.log('Hosted Files: AV Utilities +page.svelte');
});
@@ -170,7 +219,7 @@ function handle_submit_form(event) {
<section
class="ae__hosted_files__av_util container space-y-4"
class="ae__hosted_files__av_util container space-y-4 pb-20"
>
<div class="border border-gray-200 p-2 rounded-lg">
@@ -184,7 +233,8 @@ function handle_submit_form(event) {
link_to_id={$ae_loc.account_id}
bind:hosted_file_id_li={hosted_file_upload.hosted_file_id_li}
bind:hosted_file_obj_li={hosted_file_upload.hosted_file_obj_li}
bind:upload_complete={hosted_file_upload.upload_complete}
bind:hosted_file_obj_kv={$ae_sess.files.uploaded_file_kv}
bind:upload_complete={$ae_sess.files.upload_complete}
log_lvl={log_lvl}
>
<span slot="label">
@@ -199,22 +249,80 @@ function handle_submit_form(event) {
</span>
</Comp_hosted_files_upload>
<h2 class="h2">Step 2: Clip Video</h2>
{#if hosted_file_upload.upload_complete}
<Comp_hosted_files_clip_video
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="account"
link_to_id={$ae_loc.account_id}
bind:hosted_file_id_li={hosted_file_upload.hosted_file_id_li}
bind:hosted_file_obj_li={hosted_file_upload.hosted_file_obj_li}
bind:upload_complete={hosted_file_upload.upload_complete}
log_lvl={log_lvl}
>
</Comp_hosted_files_clip_video>
{#if $ae_loc.files.uploaded_file_kv && Object.entries($ae_loc.files.uploaded_file_kv).length > 0}
<button
type="button"
onclick={() => {
$ae_loc.files.uploaded_file_kv = {};
}}
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning float-right"
>
<span class="fas fa-broom"></span>
Clear Upload History
</button>
<Comp_hosted_files_clip_video
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="account"
link_to_id={$ae_loc.account_id}
bind:hosted_file_id_li={hosted_file_clip.hosted_file_id_li}
bind:hosted_file_obj_li={hosted_file_clip.hosted_file_obj_li}
bind:hosted_file_obj_kv={$ae_loc.files.uploaded_file_kv}
bind:video_clip_file_kv={$ae_loc.files.video_clip_file_kv}
bind:clip_complete={$ae_sess.files.clip_complete}
bind:submit_status={hosted_file_clip.submit_status}
log_lvl={log_lvl}
>
</Comp_hosted_files_clip_video>
{:else}
<p>Upload a video file to clip.</p>
<p>Upload a video file to clip first.</p>
{/if}
<h2 class="h2">Step 3: Download Video Clips</h2>
{#if $ae_loc.files.video_clip_file_kv && Object.entries($ae_loc.files.video_clip_file_kv).length > 0}
<button
type="button"
onclick={() => {
$ae_loc.files.video_clip_file_kv = {};
}}
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning float-right"
>
<span class="fas fa-broom"></span>
Clear Clip History
</button>
<Comp_hosted_files_clip_video_li
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
link_to_type="account"
link_to_id={$ae_loc.account_id}
bind:video_clip_file_kv={$ae_loc.files.video_clip_file_kv}
log_lvl={log_lvl}
>
</Comp_hosted_files_clip_video_li>
{:else}
<p>Clip a video file first.</p>
{/if}
<!-- <hr /> -->
<!-- {$ae_sess.files?.uploaded_file_li?.length}&times; Files Upload History
History:
{#each Object.entries($ae_loc.files.uploaded_file_kv) as [hosted_file_id, hosted_file_obj]}
<div>
<span>{hosted_file_obj.hosted_file_id_random}</span>
<span>{hosted_file_obj.filename}</span>
<span>{hosted_file_obj.extension}</span>
<button
type="button"
class="btn btn-sm btn-primary"
>
Clip Video
</button>
</div>
{/each} -->
<!-- <form on:submit|preventDefault={handle_submit_form_clip} class="av_util_mp4_clip form space-y-4"> -->
<!-- <label class="label">Start time (HH:MM:SS) <input type="text" name="start_time" value="00:00:00" placeholder="HH:MM:SS (00:01:30)" class="input w-32" /></label>
@@ -251,11 +359,12 @@ function handle_submit_form(event) {
</div>
{#if 1===2}
<div class="border border-gray-200 p-2 rounded-lg hidden">
<h2 class="h2">Convert mp3 to mp4</h2>
<p>This AV utility will take an mp3 audio file and a static image template and create a mp4 video file. This process may take a few seconds to a handful of minutes. Please be patient while it is processing.</p>
<form on:submit|preventDefault={handle_submit_form} class="av_util_mp3_to_mp4 space-y-4">
<form onsubmit={handle_submit_form} class="av_util_mp3_to_mp4 space-y-4">
<input type="text" name="title_part_1" value="Title Part 1" placeholder="Title Part 1" class="input" />
<input type="text" name="title_part_2" value="Title Part 2" placeholder="Title Part 2" class="input" />
@@ -297,8 +406,22 @@ function handle_submit_form(event) {
{/await}
</div>
{/if}
<!-- Show files for this account -->
<Element_manage_hosted_file_li_wrap
link_to_type={'account'}
link_to_id={$ae_loc?.account_id}
allow_basic={true}
allow_moderator={true}
container_class_li={''}
/>
The end
</section>