From b93cacdfccac2da274c03f7e12c2e191778ecaa8 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 7 Nov 2024 19:34:57 -0500 Subject: [PATCH] Wrapping up for the day. File uploads and deletes pretty much work now. Need to figure out whey the form does not refresh or just ignore? --- .../ae_archives__archive_content.ts | 18 +- .../ae_comp__hosted_files_upload.svelte | 305 ++++++++++++++++++ src/lib/ae_core/ae_core_functions.ts | 5 + src/lib/ae_core/core__hosted_files.ts | 59 ++++ src/lib/ae_stores.ts | 7 + ...a_comp__archive_content_obj_id_edit.svelte | 153 ++++++++- ...e_idaa_comp__archive_content_obj_li.svelte | 16 +- .../ae_idaa_comp__archive_obj_id_view.svelte | 2 + .../ae_idaa_comp__media_player.svelte | 2 +- 9 files changed, 540 insertions(+), 27 deletions(-) create mode 100644 src/lib/ae_core/ae_comp__hosted_files_upload.svelte create mode 100644 src/lib/ae_core/core__hosted_files.ts diff --git a/src/lib/ae_archives/ae_archives__archive_content.ts b/src/lib/ae_archives/ae_archives__archive_content.ts index ccb6ef3d..1c776664 100644 --- a/src/lib/ae_archives/ae_archives__archive_content.ts +++ b/src/lib/ae_archives/ae_archives__archive_content.ts @@ -33,11 +33,11 @@ export async function load_ae_obj_id__archive_content( params: params, log_lvl: log_lvl }) - .then(function (archive_content_obj_get_result) { + .then(async function (archive_content_obj_get_result) { if (archive_content_obj_get_result) { if (try_cache) { // This is expecting a list - db_save_ae_obj_li__archive_content({ + await db_save_ae_obj_li__archive_content({ obj_type: 'archive_content', obj_li: [archive_content_obj_get_result] @@ -104,10 +104,10 @@ export async function load_ae_obj_li__archive_content( params: params, log_lvl: log_lvl }) - .then(function (archive_content_obj_li_get_result) { + .then(async function (archive_content_obj_li_get_result) { if (archive_content_obj_li_get_result) { if (try_cache) { - db_save_ae_obj_li__archive_content({ + await db_save_ae_obj_li__archive_content({ obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result }); } @@ -158,9 +158,9 @@ export async function create_ae_obj__archive_content( return_obj: true, log_lvl: log_lvl }) - .then(function (archive_content_obj_create_result) { + .then(async function (archive_content_obj_create_result) { if (archive_content_obj_create_result) { - db_save_ae_obj_li__archive_content( + await db_save_ae_obj_li__archive_content( { obj_type: 'archive_content', obj_li: [archive_content_obj_create_result] @@ -214,10 +214,10 @@ export async function update_ae_obj__archive_content( return_obj: true, log_lvl: log_lvl }) - .then(function (archive_content_obj_update_result) { + .then(async function (archive_content_obj_update_result) { if (archive_content_obj_update_result) { if (try_cache) { - db_save_ae_obj_li__archive_content({ + await db_save_ae_obj_li__archive_content({ obj_type: 'archive_content', obj_li: [archive_content_obj_update_result] }); } @@ -241,7 +241,7 @@ export async function update_ae_obj__archive_content( // This function will loop through the archive_content_obj_li and save each one to the DB. // Updated 2024-09-25 -export function db_save_ae_obj_li__archive_content( +export async function db_save_ae_obj_li__archive_content( { obj_type, obj_li, diff --git a/src/lib/ae_core/ae_comp__hosted_files_upload.svelte b/src/lib/ae_core/ae_comp__hosted_files_upload.svelte new file mode 100644 index 00000000..2d936458 --- /dev/null +++ b/src/lib/ae_core/ae_comp__hosted_files_upload.svelte @@ -0,0 +1,305 @@ + + + + +
+ + {#await ae_promises.upload__hosted_file_obj} +
+ + + Uploading + {#if $ae_sess.api_upload_kv[task_id]} + {$ae_sess.api_upload_kv[task_id].percent_completed}% + {/if} + +
+ {/await} + + + + + + + + + diff --git a/src/lib/ae_core/ae_core_functions.ts b/src/lib/ae_core/ae_core_functions.ts index 558f4740..d86eaba7 100644 --- a/src/lib/ae_core/ae_core_functions.ts +++ b/src/lib/ae_core/ae_core_functions.ts @@ -38,6 +38,10 @@ import { load_ae_obj_li__country_subdivision } from "$lib/ae_core/core__country_subdivisions"; +import { + delete_ae_obj_id__hosted_file +} from "$lib/ae_core/core__hosted_files"; + let ae_promises: key_val = {}; // Promise; @@ -397,6 +401,7 @@ let export_obj = { load_ae_obj_li__time_zone: load_ae_obj_li__time_zone, load_ae_obj_li__country: load_ae_obj_li__country, load_ae_obj_li__country_subdivision: load_ae_obj_li__country_subdivision, + delete_ae_obj_id__hosted_file: delete_ae_obj_id__hosted_file, handle_load_ae_obj_id__site_domain: handle_load_ae_obj_id__site_domain, handle_load_ae_obj_code__data_store: handle_load_ae_obj_code__data_store, load_ae_obj_id__activity_log: load_ae_obj_id__activity_log, diff --git a/src/lib/ae_core/core__hosted_files.ts b/src/lib/ae_core/core__hosted_files.ts new file mode 100644 index 00000000..61e160c4 --- /dev/null +++ b/src/lib/ae_core/core__hosted_files.ts @@ -0,0 +1,59 @@ +import type { key_val } from '$lib/ae_stores'; +import { api } from '$lib/api'; + +// import { db_events } from "$lib/db_events"; + +let ae_promises: key_val = {}; + + +// Updated 2024-11-07 +export async function delete_ae_obj_id__hosted_file( + { + api_cfg, + hosted_file_id, + link_to_type, // Ideally this should be required... + link_to_id, // Ideally this should be required... + rm_orphan = false, + fake_delete = false, // Fake the delete result to "true" + params = {}, + log_lvl = 0 + }: { + api_cfg: any, + hosted_file_id: string, + link_to_type: string, + link_to_id: string, + rm_orphan?: boolean, + fake_delete?: boolean, + params?: key_val, + log_lvl?: number + } + ) { + if (log_lvl) { + console.log(`*** delete_ae_obj_id__hosted_file() *** hosted_file_id=${hosted_file_id}`); + } + + const endpoint = `/hosted_file/${hosted_file_id}`; + + params['link_to_type'] = link_to_type; + params['link_to_id'] = link_to_id; + params['rm_orphan'] = rm_orphan; // This is what actually allows the hosted file to be deleted from the server. + if (log_lvl) { + console.log(`delete_ae_obj_id__hosted_file() params=`, params); + } + + if (fake_delete) { + console.log(`*** FAKE DELETE!!! ***`); + ae_promises.delete__hosted_file_obj = true; + return ae_promises.delete__hosted_file_obj; + } + + ae_promises.delete__hosted_file_obj = await api.delete_object({ + api_cfg: api_cfg, + endpoint: endpoint, + params: params, + // return_meta: return_meta, + log_lvl: log_lvl + }); + + return ae_promises.delete__hosted_file_obj; +} \ No newline at end of file diff --git a/src/lib/ae_stores.ts b/src/lib/ae_stores.ts index 7f5c1144..bc3f4e3f 100644 --- a/src/lib/ae_stores.ts +++ b/src/lib/ae_stores.ts @@ -211,6 +211,13 @@ export let ae_app_session_data_struct: key_val = { }, 'ds_loaded': { }, + + 'files': { + disable_submit__hosted_file_obj: false, + processed_file_list: [], + submit_status: null, // 'saving', 'created', 'updated', 'saved' + }, + 'hub': { 'show_xyz': null, }, diff --git a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte index ab9446af..acedbce4 100644 --- a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte @@ -15,6 +15,7 @@ import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores'; import { archives_func } from '$lib/ae_archives/ae_archives_functions'; import Tiptap_editor from '$lib/element_tiptap_editor.svelte'; +import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte'; export let lq__archive_content_obj: any; @@ -22,7 +23,8 @@ let create_archive_content_obj_promise: any; let delete_archive_content_obj_promise: any; let update_archive_content_obj_promise: any; let upload__hosted_file_obj_promise: any; -let prom_api__archive_content_obj_v2: any; +let prom_api__archive_content_obj: any; +let prom_api__archive_content_obj__hosted_file: any; let disable_submit_btn = true; @@ -291,7 +293,7 @@ async function handle_submit_form(event) { return create_archive_content_obj_promise; } else { - prom_api__archive_content_obj_v2 = archives_func.update_ae_obj__archive_content({ + prom_api__archive_content_obj = archives_func.update_ae_obj__archive_content({ api_cfg: $ae_api, archive_content_id: $idaa_slct.archive_content_id, data_kv: archive_content_do, @@ -317,7 +319,7 @@ async function handle_submit_form(event) { // $idaa_sess.archives.show__modal_edit__archive_content_id = false; }); - return prom_api__archive_content_obj_v2; + return prom_api__archive_content_obj; } // update_archive_content_obj_promise = api.update_ae_obj_id_crud({ @@ -353,6 +355,36 @@ async function handle_submit_form(event) { // } } +$: if ($idaa_slct.archive_content_obj.upload_complete && $idaa_slct.archive_content_obj.hosted_file_id_li?.length && $idaa_slct.archive_content_obj.hosted_file_obj_li?.length) { + handle_hosted_files_uploaded($idaa_slct.archive_content_obj.hosted_file_id_li, $idaa_slct.archive_content_obj.hosted_file_obj_li); +} + + +async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_file_obj_li: any[]) { + console.log(`*** handle_hosted_files_uploaded() *** ${hosted_file_id_li}`); + + // We need to update the archive_content_obj with the new file (for now just the first one). + prom_api__archive_content_obj = archives_func.update_ae_obj__archive_content({ + api_cfg: $ae_api, + archive_content_id: $idaa_slct.archive_content_id, + data_kv: { + hosted_file_id_random: hosted_file_obj_li[0].hosted_file_id_random, + // file_path: hosted_file_obj_li[0].file_path, + filename: hosted_file_obj_li[0].filename, + file_extension: hosted_file_obj_li[0].extension, + archive_content_type: 'hosted_file', + }, + log_lvl: log_lvl + }) + .then(function (archive_content_obj_update_result) { + $idaa_slct.archive_content_obj = $lq__archive_content_obj; + }) + .catch(function (error) { + console.log('Something went wrong.'); + console.log(error); + return false; + }); +} @@ -446,9 +478,39 @@ async function handle_submit_form(event) { -->

File?

- {#if !$idaa_slct.archive_content_id} - FILE INPUT GOES HERE + {#if $ae_loc.trusted_access && $idaa_slct.archive_content_id} + + +
+ + Upload archive files +
+ + Aether hosted files only
+ Recommended: PowerPoint (pptx) or Keynote (key) or Adobe PDF
+ Media: Audio (mp3, m4a) and videos (mp4, mkv)
+ Supplemental files: Word Doc, Excel, txt, etc +
+
+
+ {/if} + + + + + {#if !$idaa_slct.archive_content_obj.hosted_file_id} + No file uploaded yet. + + + + +