Work on file uploads and manage.
This commit is contained in:
@@ -108,7 +108,7 @@ $effect(() => {
|
||||
});
|
||||
}}
|
||||
|
||||
title={`Download this file:\n${filename ?? hosted_file_obj.filename}\n[API] SHA256: ${hosted_file_obj?.hash_sha256.slice(0, 10)}...\nHosted ID: ${hosted_file_obj.hosted_file_id_random}\n Linked to: ${linked_to_type} ID: ${linked_to_id}`}
|
||||
title={`Download this file:\n${filename ?? hosted_file_obj?.filename}\n[API] SHA256: ${hosted_file_obj?.hash_sha256?.slice(0, 10)}...\nHosted ID: ${hosted_file_obj?.hosted_file_id_random}\n Linked to: ${linked_to_type} ID: ${linked_to_id}`}
|
||||
>
|
||||
{#await ae_promises[hosted_file_obj.hosted_file_id_random]}
|
||||
<span class="fas fa-spinner fa-spin mx-1"></span>
|
||||
|
||||
@@ -166,12 +166,20 @@ async function handle_input_upload_files(
|
||||
hosted_file_obj_li.push(hosted_file_obj);
|
||||
|
||||
let hosted_file_data: key_val = {};
|
||||
hosted_file_data['id'] = hosted_file_id;
|
||||
hosted_file_data['hosted_file_id'] = hosted_file_id;
|
||||
hosted_file_data['hosted_file_id_random'] = hosted_file_id;
|
||||
hosted_file_data['for_type'] = link_to_type;
|
||||
hosted_file_data['for_id'] = link_to_id;
|
||||
hosted_file_data['for_id_random'] = link_to_id;
|
||||
hosted_file_data['hash_sha256'] = hosted_file_obj.hash_sha256;
|
||||
hosted_file_data['filename'] = hosted_file_obj.filename;
|
||||
hosted_file_data['extension'] = hosted_file_obj.extension;
|
||||
hosted_file_data['content_type'] = hosted_file_obj.content_type;
|
||||
hosted_file_data['size'] = hosted_file_obj.size;
|
||||
hosted_file_data['enable'] = true;
|
||||
hosted_file_data['created_on'] = hosted_file_obj.created_on;
|
||||
hosted_file_data['updated_on'] = hosted_file_obj.updated_on;
|
||||
console.log(hosted_file_data);
|
||||
|
||||
hosted_file_obj_kv[hosted_file_id] = hosted_file_data;
|
||||
|
||||
@@ -69,7 +69,8 @@ let lq__hosted_file_obj_li = $derived(liveQuery(async () => {
|
||||
results = await db_core.file
|
||||
.where(dq__where_val)
|
||||
.equals(dq__where_eq_val)
|
||||
.sortBy('created_on');
|
||||
.sortBy('created_on')
|
||||
;
|
||||
} else if (file_type == 'video') {
|
||||
// Handle video/mp4, video/mov, video/webm. If the content type is prefixed with "video/", then it is a video file.
|
||||
let extension = 'mp4';
|
||||
|
||||
@@ -10,6 +10,7 @@ import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
|
||||
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
|
||||
import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte';
|
||||
import { keymap } from '@codemirror/view';
|
||||
|
||||
|
||||
interface Props {
|
||||
@@ -29,8 +30,8 @@ let {
|
||||
let ae_promises: key_val = $state({});
|
||||
let hosted_file_kv: key_val = $state($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}); // WARNING: This does no seem to set soon enough. Added an effect to set it as a backup.
|
||||
// let hosted_file_li: [string, any][] = $state([]);
|
||||
let hosted_file_obj_li: any[] = $state($lq__journal_entry_obj?.data_json?.hosted_file_obj_li ?? []);
|
||||
let hosted_file_id_li: string[] = $state([]);
|
||||
let slct_hosted_file_obj_li: any[] = $state($lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li ?? []);
|
||||
let slct_hosted_file_id_li: string[] = $state([]);
|
||||
let upload_complete: boolean = $state(false);
|
||||
|
||||
let slct_hosted_file_kv: key_val = $state({});
|
||||
@@ -41,7 +42,7 @@ let rem_hosted_file_id: string|null = $state(null);
|
||||
|
||||
async function update_journal_entry() {
|
||||
// hosted_file_kv = lq__journal_entry_obj.data_json.hosted_file_kv;
|
||||
// hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.hosted_file_obj_li];
|
||||
// slct_hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li];
|
||||
// hosted_file_kv = {
|
||||
// ...$lq__journal_entry_obj?.data_json?.hosted_file_kv,
|
||||
// };
|
||||
@@ -54,7 +55,7 @@ async function update_journal_entry() {
|
||||
// hosted_file_kv: {
|
||||
// ...slct_hosted_file_kv,
|
||||
// },
|
||||
// hosted_file_obj_li: hosted_file_obj_li
|
||||
// slct_hosted_file_obj_li: slct_hosted_file_obj_li
|
||||
};
|
||||
console.log('data_kv', data_kv);
|
||||
|
||||
@@ -89,7 +90,11 @@ $effect(() => {
|
||||
hosted_file_kv = $lq__journal_entry_obj?.data_json?.hosted_file_kv;
|
||||
}
|
||||
|
||||
// This is for the Select file option
|
||||
if ($lq__journal_entry_obj && slct_hosted_file_id && slct_hosted_file_obj) {
|
||||
if (log_lvl) {
|
||||
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
|
||||
}
|
||||
hosted_file_kv = {
|
||||
...hosted_file_kv,
|
||||
[slct_hosted_file_id]: slct_hosted_file_obj
|
||||
@@ -99,16 +104,44 @@ $effect(() => {
|
||||
|
||||
update_journal_entry();
|
||||
|
||||
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
|
||||
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
|
||||
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
|
||||
}
|
||||
|
||||
// This is for the Upload file option
|
||||
if ($lq__journal_entry_obj && slct_hosted_file_id_li && slct_hosted_file_id_li.length && upload_complete) {
|
||||
if (log_lvl) {
|
||||
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
|
||||
}
|
||||
|
||||
hosted_file_kv = {
|
||||
...hosted_file_kv,
|
||||
// ...keymap
|
||||
// ...slct_hosted_file_kv
|
||||
...Object.fromEntries(slct_hosted_file_id_li.map(id => [id, slct_hosted_file_kv[id]]))
|
||||
};
|
||||
slct_hosted_file_id = null;
|
||||
slct_hosted_file_obj = null;
|
||||
slct_hosted_file_id_li = [];
|
||||
|
||||
upload_complete = false;
|
||||
|
||||
update_journal_entry();
|
||||
|
||||
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
|
||||
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($lq__journal_entry_obj && rem_hosted_file_id) {
|
||||
console.log('rem_hosted_file_id', rem_hosted_file_id);
|
||||
if (log_lvl) {
|
||||
console.log(`rem_hosted_file_id=${rem_hosted_file_id}`);
|
||||
}
|
||||
|
||||
delete hosted_file_kv[rem_hosted_file_id];
|
||||
rem_hosted_file_id = null;
|
||||
update_journal_entry();
|
||||
update_journal_entry(); // Should we use await here?
|
||||
}
|
||||
});
|
||||
|
||||
@@ -154,8 +187,9 @@ $effect(() => {
|
||||
class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200"
|
||||
link_to_type={link_to_type}
|
||||
link_to_id={link_to_id}
|
||||
bind:hosted_file_id_li={hosted_file_id_li}
|
||||
bind:hosted_file_obj_li={hosted_file_obj_li}
|
||||
bind:hosted_file_id_li={slct_hosted_file_id_li}
|
||||
bind:hosted_file_obj_li={slct_hosted_file_obj_li}
|
||||
bind:hosted_file_obj_kv={slct_hosted_file_kv}
|
||||
bind:upload_complete={upload_complete}
|
||||
log_lvl={log_lvl}
|
||||
>
|
||||
@@ -236,10 +270,10 @@ $effect(() => {
|
||||
<button
|
||||
disabled={!$ae_loc.administrator_access}
|
||||
type="button"
|
||||
onclick={() => {
|
||||
onclick={async () => {
|
||||
if (confirm('Are you sure you want to remove the file?')) {
|
||||
// First - Attempt to delete the hosted file
|
||||
ae_promises.journal_entry_obj__hosted_file = core_func.delete_ae_obj_id__hosted_file({
|
||||
ae_promises.journal_entry_obj__hosted_file = await core_func.delete_ae_obj_id__hosted_file({
|
||||
api_cfg: $ae_api,
|
||||
hosted_file_id: hosted_file_id,
|
||||
link_to_type: link_to_type,
|
||||
@@ -252,7 +286,7 @@ $effect(() => {
|
||||
// Second - If deleted, then update the journal_entry_obj
|
||||
console.log(`File removed. Now update the journal_entry_obj`);
|
||||
|
||||
rem_hosted_file_id = hosted_file_id;
|
||||
rem_hosted_file_id = hosted_file_id; // Should we use await here?
|
||||
// update_journal_entry();
|
||||
})
|
||||
.catch(function (error) {
|
||||
|
||||
@@ -35,14 +35,14 @@ import E_app_codemirror_v5 from '$lib/e_app_codemirror_v5.svelte';
|
||||
// *** Import Aether specific variables and functions
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
import { api } from '$lib/api';
|
||||
// import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
// import { api } from '$lib/api';
|
||||
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
|
||||
import { journals_loc, journals_sess, journals_slct, journals_trig, journals_prom } from '$lib/ae_journals/ae_journals_stores';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
import Comp_journal_entry_file_li from './ae_comp__journal_entry_obj_file_li.svelte';
|
||||
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
|
||||
import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte';
|
||||
// import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
|
||||
// import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte';
|
||||
import Comp_hosted_files_download_button from '$lib/ae_core/ae_comp__hosted_files_download_button.svelte';
|
||||
|
||||
interface Props {
|
||||
|
||||
Reference in New Issue
Block a user