Skip to content
Snippets Groups Projects

Resolve "Fetch S3 Object Meta information dynamically"

6 files
+ 127
24
Compare changes
  • Side-by-side
  • Inline
Files
6
<script setup lang="ts">
<script setup lang="ts">
import BootstrapModal from "@/components/modals/BootstrapModal.vue";
import BootstrapModal from "@/components/modals/BootstrapModal.vue";
import type { _Object as S3Object } from "@aws-sdk/client-s3";
import dayjs from "dayjs";
import dayjs from "dayjs";
import { filesize } from "filesize";
import { filesize } from "filesize";
 
import { computed, onMounted, watch, reactive } from "vue";
 
import { useS3ObjectStore } from "@/stores/s3objects";
 
 
const objectRepository = useS3ObjectStore();
const props = defineProps<{
const props = defineProps<{
modalID: string;
modalID: string;
s3Object: S3Object;
objectKey: string | undefined;
bucket: string;
bucket: string;
}>();
}>();
 
 
const detailState = reactive<{
 
loading: boolean;
 
error: boolean;
 
}>({
 
loading: true,
 
error: false,
 
});
 
 
const metaIdentifier = computed<string>(() => {
 
return props.bucket + "/" + props.objectKey;
 
});
 
 
watch(props, (newProps) => {
 
detailState.loading = true;
 
if (newProps.objectKey) {
 
fetchMetaInfo(newProps.bucket, newProps.objectKey);
 
}
 
});
 
 
function fetchMetaInfo(bucket: string, key: string) {
 
detailState.loading = true;
 
detailState.error = false;
 
objectRepository
 
.fetchS3ObjectMeta(bucket, key, () => {
 
detailState.loading = false;
 
})
 
.catch(() => {
 
detailState.error = true;
 
});
 
}
 
 
onMounted(() => {
 
if (props.objectKey) {
 
fetchMetaInfo(props.bucket, props.objectKey);
 
}
 
});
</script>
</script>
<template>
<template>
@@ -30,32 +70,63 @@ const props = defineProps<{
@@ -30,32 +70,63 @@ const props = defineProps<{
</tr>
</tr>
<tr>
<tr>
<th scope="row">Name</th>
<th scope="row">Name</th>
<td>{{ props.s3Object.Key }}</td>
<td>{{ props.objectKey }}</td>
</tr>
</tr>
<tr>
<tr>
<th scope="row">Size</th>
<th scope="row">Size</th>
<td>
<td v-if="detailState.error">N/A</td>
 
<td v-else-if="detailState.loading" class="placeholder-glow">
 
<span class="placeholder col-2"></span>
 
</td>
 
<td v-else>
{{
{{
filesize(props.s3Object.Size ?? 0, {
filesize(
base: 2,
objectRepository.objectMetaMapping[metaIdentifier]
standard: "jedec",
.ContentLength ?? 0,
})
{
 
base: 2,
 
standard: "jedec",
 
},
 
)
}}
}}
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<th scope="row">Timestamp</th>
<th scope="row">Timestamp</th>
<td>
<td v-if="detailState.error">N/A</td>
 
<td v-else-if="detailState.loading" class="placeholder-glow">
 
<span class="placeholder col-6"></span>
 
</td>
 
<td v-else>
{{
{{
dayjs(props.s3Object.LastModified).format(
dayjs(
"YYYY-MM-DD HH:mm:ss",
objectRepository.objectMetaMapping[metaIdentifier]
)
.LastModified,
 
).format("YYYY-MM-DD HH:mm:ss")
}}
}}
</td>
</td>
</tr>
</tr>
<tr>
<tr>
<th scope="row">Content Type</th>
<th scope="row">Content Type</th>
<td>binary/octet-stream</td>
<td v-if="detailState.error">N/A</td>
 
<td v-else-if="detailState.loading" class="placeholder-glow">
 
<span class="placeholder col-5"></span>
 
</td>
 
<td v-else>
 
{{
 
objectRepository.objectMetaMapping[metaIdentifier].ContentType
 
}}
 
</td>
 
</tr>
 
<tr>
 
<th scope="row">ETag</th>
 
<td v-if="detailState.error">N/A</td>
 
<td v-else-if="detailState.loading" class="placeholder-glow">
 
<span class="placeholder col-10"></span>
 
</td>
 
<td v-else>
 
{{ objectRepository.objectMetaMapping[metaIdentifier].ETag }}
 
</td>
</tr>
</tr>
</tbody>
</tbody>
</table>
</table>
Loading