Better handling of file types (extensions)
This commit is contained in:
@@ -40,7 +40,7 @@ let {
|
|||||||
link_to_type,
|
link_to_type,
|
||||||
link_to_id,
|
link_to_id,
|
||||||
display_mode = 'default',
|
display_mode = 'default',
|
||||||
max_file_count = 19,
|
max_file_count = 49,
|
||||||
file_type = 'all',
|
file_type = 'all',
|
||||||
slct_hosted_file_kv = $bindable({}),
|
slct_hosted_file_kv = $bindable({}),
|
||||||
slct_hosted_file_id = $bindable(null),
|
slct_hosted_file_id = $bindable(null),
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ interface Props {
|
|||||||
allow_basic?: boolean; // Not used yet
|
allow_basic?: boolean; // Not used yet
|
||||||
allow_moderator?: boolean; // Not used yet
|
allow_moderator?: boolean; // Not used yet
|
||||||
display_mode?: string; // 'default', 'compact', 'minimal', 'launcher'
|
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_kv?: key_val;
|
||||||
slct_hosted_file_id?: any;
|
slct_hosted_file_id?: any;
|
||||||
slct_hosted_file_obj?: any;
|
slct_hosted_file_obj?: any;
|
||||||
@@ -38,6 +40,8 @@ let {
|
|||||||
allow_basic = false,
|
allow_basic = false,
|
||||||
allow_moderator = false,
|
allow_moderator = false,
|
||||||
display_mode = 'default',
|
display_mode = 'default',
|
||||||
|
max_file_count = 49,
|
||||||
|
file_type = 'all',
|
||||||
slct_hosted_file_kv = $bindable({}),
|
slct_hosted_file_kv = $bindable({}),
|
||||||
slct_hosted_file_id = $bindable(null),
|
slct_hosted_file_id = $bindable(null),
|
||||||
slct_hosted_file_obj = $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 () => {
|
let lq__hosted_file_obj_li = $derived(liveQuery(async () => {
|
||||||
// console.log(`dq__where_val: ${dq__where_val}`);
|
// console.log(`dq__where_val: ${dq__where_val}`);
|
||||||
// console.log(`dq__where_eq_val: ${dq__where_eq_val}`);
|
// console.log(`dq__where_eq_val: ${dq__where_eq_val}`);
|
||||||
let results = await db_core.file
|
let results = null;
|
||||||
.where(dq__where_val)
|
if (file_type == 'all' || !file_type) {
|
||||||
// .where('account_id')
|
results = await db_core.file
|
||||||
.equals(dq__where_eq_val)
|
.where(dq__where_val)
|
||||||
// .equals('Q8lR8Ai8hx2FjbQ3C_EH1Q')
|
.equals(dq__where_eq_val)
|
||||||
// .reverse()
|
.sortBy('created_on');
|
||||||
.sortBy('created_on')
|
} else if (file_type == 'video') {
|
||||||
// .toArray()
|
// 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;
|
return results;
|
||||||
}));
|
}));
|
||||||
</script>
|
</script>
|
||||||
@@ -101,6 +148,8 @@ let lq__hosted_file_obj_li = $derived(liveQuery(async () => {
|
|||||||
class_li_default={class_li_default}
|
class_li_default={class_li_default}
|
||||||
class_li={class_li}
|
class_li={class_li}
|
||||||
display_mode={display_mode}
|
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_kv={slct_hosted_file_kv}
|
||||||
bind:slct_hosted_file_id={slct_hosted_file_id}
|
bind:slct_hosted_file_id={slct_hosted_file_id}
|
||||||
bind:slct_hosted_file_obj={slct_hosted_file_obj}
|
bind:slct_hosted_file_obj={slct_hosted_file_obj}
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ onMount(() => {
|
|||||||
allow_basic={true}
|
allow_basic={true}
|
||||||
allow_moderator={true}
|
allow_moderator={true}
|
||||||
class_li={''}
|
class_li={''}
|
||||||
|
max_file_count={39}
|
||||||
|
file_type={'video'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user