Skip to content
Snippets Groups Projects

Resolve "Fetch Objects directly from S3 Endpoint instead of S3 proxy"

12 files
+ 373
272
Compare changes
  • Side-by-side
  • Inline
Files
12
<script setup lang="ts">
import type { S3Client } from "@aws-sdk/client-s3";
import { CopyObjectCommand } from "@aws-sdk/client-s3";
import BootstrapModal from "@/components/modals/BootstrapModal.vue";
import { Modal, Toast } from "bootstrap";
import { onMounted, reactive, watch } from "vue";
import type { S3ObjectMetaInformation } from "@/client/s3proxy";
import dayjs from "dayjs";
import type { _Object as S3Object } from "@aws-sdk/client-s3";
import { useBucketStore } from "@/stores/buckets";
import { useS3ObjectStore } from "@/stores/s3objects";
const objectRepository = useS3ObjectStore();
const props = defineProps<{
modalID: string;
sourceObject: S3ObjectMetaInformation;
s3Client: S3Client;
srcObject: S3Object;
srcBucket: string;
}>();
const formState = reactive<{
@@ -25,39 +25,32 @@ const formState = reactive<{
});
const bucketRepository = useBucketStore();
const emit = defineEmits<{
(e: "object-copied", object: S3ObjectMetaInformation): void;
}>();
const randomIDSuffix = Math.random().toString(16).substring(2, 8);
let copyModal: Modal | null = null;
let successToast: Toast | null = null;
let errorToast: Toast | null = null;
function getFileName(key: string): string {
function getFileName(key?: string): string {
if (key == undefined) {
return "";
}
const splittedKey = key.split("/");
return splittedKey[splittedKey.length - 1];
}
function copyObject() {
const command = new CopyObjectCommand({
Bucket: formState.destBucket,
CopySource: encodeURI(
`/${props.sourceObject.bucket}/${props.sourceObject.key}`,
),
Key: formState.destKey,
});
if (props.srcObject.Key == undefined) {
return;
}
formState.uploading = true;
props.s3Client
.send(command)
objectRepository
.copyObject(
props.srcBucket,
props.srcObject,
formState.destBucket,
formState.destKey,
)
.then(() => {
emit("object-copied", {
key: formState.destKey,
bucket: formState.destBucket,
size: props.sourceObject.size,
last_modified: dayjs().toISOString(),
content_type: props.sourceObject.content_type,
});
copyModal?.hide();
successToast?.show();
formState.destBucket = "";
@@ -76,9 +69,9 @@ function modalClosed() {
}
watch(
() => props.sourceObject.key,
() => props.srcObject.Key,
(newKey) => {
formState.destKey = newKey;
formState.destKey = newKey ?? "";
},
);
@@ -140,7 +133,7 @@ onMounted(() => {
v-on="{ 'hidden.bs.modal': modalClosed }"
>
<template v-slot:header>
<h4>Copy file {{ getFileName(props.sourceObject.key) }}</h4>
<h4>Copy file {{ getFileName(props.srcObject.Key) }}</h4>
</template>
<template v-slot:body>
<div class="container-fluid">
Loading