Better handling of file types (extensions)

This commit is contained in:
Scott Idem
2025-03-18 17:33:27 -04:00
parent 253a1c59d6
commit 0f22ad0584
3 changed files with 60 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ let {
link_to_type,
link_to_id,
display_mode = 'default',
max_file_count = 19,
max_file_count = 49,
file_type = 'all',
slct_hosted_file_kv = $bindable({}),
slct_hosted_file_id = $bindable(null),

View File

@@ -25,6 +25,8 @@ interface Props {
allow_basic?: boolean; // Not used yet
allow_moderator?: boolean; // Not used yet
display_mode?: string; // 'default', 'compact', 'minimal', 'launcher'
max_file_count?: number;
file_type?: string; // 'image', 'video', 'audio', 'document', 'other'
slct_hosted_file_kv?: key_val;
slct_hosted_file_id?: any;
slct_hosted_file_obj?: any;
@@ -38,6 +40,8 @@ let {
allow_basic = false,
allow_moderator = false,
display_mode = 'default',
max_file_count = 49,
file_type = 'all',
slct_hosted_file_kv = $bindable({}),
slct_hosted_file_id = $bindable(null),
slct_hosted_file_obj = $bindable(null)
@@ -62,15 +66,58 @@ let dq__where_eq_val: string = link_to_id;
let lq__hosted_file_obj_li = $derived(liveQuery(async () => {
// console.log(`dq__where_val: ${dq__where_val}`);
// console.log(`dq__where_eq_val: ${dq__where_eq_val}`);
let results = await db_core.file
.where(dq__where_val)
// .where('account_id')
.equals(dq__where_eq_val)
// .equals('Q8lR8Ai8hx2FjbQ3C_EH1Q')
// .reverse()
.sortBy('created_on')
// .toArray()
let results = null;
if (file_type == 'all' || !file_type) {
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
.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';
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
// .and((x) => (x.extension == extension))
// .and((x) => (x.content_type == `video/${extension}`))
.and((x) => (x.content_type.startsWith('video/')))
// .reverse()
.sortBy('created_on')
// .toArray()
;
} else if (file_type == 'audio') {
// Handle audio/mp3, audio/wav, audio/ogg. If the content type is prefixed with "audio/", then it is an audio file.
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
.and((x) => (x.content_type.startsWith('audio/')))
.sortBy('created_on')
;
} else if (file_type == 'image') {
// Handle image/jpeg, image/png, image/gif. If the content type is prefixed with "image/", then it is an image file.
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
.and((x) => (x.content_type.startsWith('image/')))
.sortBy('created_on')
;
} else if (file_type == 'document') {
// Handle application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation. If the content type is prefixed with "application/", then it is a document file.
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
.and((x) => (x.content_type.startsWith('application/')))
.sortBy('created_on')
;
} else {
results = await db_core.file
.where(dq__where_val)
.equals(dq__where_eq_val)
// .reverse()
.sortBy('created_on')
;
}
return results;
}));
</script>
@@ -101,6 +148,8 @@ let lq__hosted_file_obj_li = $derived(liveQuery(async () => {
class_li_default={class_li_default}
class_li={class_li}
display_mode={display_mode}
bind:max_file_count={max_file_count}
bind:file_type={file_type}
bind:slct_hosted_file_kv={slct_hosted_file_kv}
bind:slct_hosted_file_id={slct_hosted_file_id}
bind:slct_hosted_file_obj={slct_hosted_file_obj}

View File

@@ -181,6 +181,8 @@ onMount(() => {
allow_basic={true}
allow_moderator={true}
class_li={''}
max_file_count={39}
file_type={'video'}
/>
</div>