Making more fields us the LiveQuery. Migrated format bytes function. General clean up.

This commit is contained in:
Scott Idem
2024-06-27 10:57:19 -04:00
parent 20e1c46461
commit 8c8748b571
5 changed files with 176 additions and 64 deletions

View File

@@ -269,6 +269,7 @@ export function handle_db_save_ae_obj_li__event_file(
filename_no_ext: obj.filename_no_ext,
filename_w_ext: obj.filename_w_ext,
hosted_file_content_type: obj.hosted_file_content_type,
file_size: obj.file_size,
hosted_file_size: obj.hosted_file_size,
});
// console.log(`Put obj with ID: ${obj.event_file_id_random} or ${id_random}`);

View File

@@ -137,6 +137,22 @@ export let iso_datetime_formatter = function iso_datetime_formatter(
}
function format_bytes(
bytes: number,
decimals: number = 2
) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
/* This utility function will add commas to a number. */
function number_w_commas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
@@ -993,6 +1009,7 @@ function return_obj_type_path({obj_type=null, obj_type_prop_name=null}) {
export let ae_util = {
iso_datetime_formatter: iso_datetime_formatter,
format_bytes: format_bytes,
number_w_commas: number_w_commas,
extract_prefixed_form_data: extract_prefixed_form_data,
process_data_string: process_data_string,

View File

@@ -204,39 +204,40 @@ export interface File {
hosted_file_id_random: string;
hash_sha256: string;
for_type: string;
for_id: string;
for_id_random: string;
for_type?: string;
for_id?: string;
for_id_random?: string;
event_id_random: string;
event_session_id_random: string;
event_presentation_id_random: string;
event_presenter_id_random: string;
event_location_id_random: string;
event_session_id_random?: string;
event_presentation_id_random?: string;
event_presenter_id_random?: string;
event_location_id_random?: string;
filename: string;
extension: string;
open_in_os: null|string; // null, empty, 'mac', or 'win'
open_in_os?: null|string; // null, empty, 'mac', or 'win'
lu_file_purpose_id: string;
lu_event_file_purpose_name: string;
file_purpose: string;
enable: null|boolean;
hide: null|boolean;
priority: null|boolean
sort: null|number;
group: null|string;
notes: null|string;
hide?: null|boolean;
priority?: null|boolean
sort?: null|number;
group?: null|string;
notes?: null|string;
created_on: Date;
updated_on: null|Date;
updated_on?: null|Date;
// Additional fields for convenience (database views)
filename_no_ext: string;
filename_w_ext: string;
hosted_file_content_type: string;
hosted_file_size: number; // In bytes
file_size: number; // In bytes
hosted_file_size?: number; // In bytes
}