🎉 Init
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
<template>
|
||||
<aside
|
||||
v-if="object"
|
||||
class="flex h-full w-96 shrink-0 flex-col border-l border-border bg-surface"
|
||||
>
|
||||
<div class="flex items-center justify-between border-b border-border px-5 py-4">
|
||||
<h2 class="text-sm font-semibold tracking-[0.06em] text-muted">OBJEKT</h2>
|
||||
<button type="button" class="text-muted transition-colors hover:text-text" @click="$emit('close')">
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 space-y-6 overflow-y-auto px-5 py-5">
|
||||
<div>
|
||||
<FieldLabel>Bucket</FieldLabel>
|
||||
<p class="mt-1 font-mono text-sm text-text">{{ bucket }}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FieldLabel>Objekt</FieldLabel>
|
||||
<p class="mt-1 break-all font-mono text-sm text-text">{{ object.key }}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FieldLabel>Chunks</FieldLabel>
|
||||
<div class="mt-2 flex items-center gap-3">
|
||||
<ChunkBar :parts="partCount(object.etag)" />
|
||||
<span class="text-sm text-muted">
|
||||
{{ partCount(object.etag) === 1 ? 'Single-Part-Upload' : `Multipart-Upload, ${partCount(object.etag)} Teile` }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FieldLabel>Größe</FieldLabel>
|
||||
<p class="mt-1 font-mono text-sm text-text">
|
||||
{{ formatBytes(object.size) }} <span class="text-muted">· {{ object.size.toLocaleString('de-DE') }} Bytes</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FieldLabel>Zuletzt geändert</FieldLabel>
|
||||
<p class="mt-1 font-mono text-sm text-text">{{ formatDateTime(object.lastModified) }}</p>
|
||||
</div>
|
||||
|
||||
<CopyField label="S3-URI" :value="`s3://${bucket}/${object.key}`" />
|
||||
<CopyField label="ETag" :value="object.etag" />
|
||||
|
||||
<div class="border-t border-border pt-6">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-center justify-center gap-2 rounded-md bg-red-500 px-3 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||||
@click="confirmDelete"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]">delete</span>
|
||||
Löschen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex shrink-0 gap-2 border-t border-border px-5 py-4">
|
||||
<button
|
||||
v-if="isTextFile"
|
||||
type="button"
|
||||
class="flex flex-1 items-center justify-center gap-2 rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
|
||||
@click="openPreview"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]">visibility</span>
|
||||
Anzeigen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex flex-1 items-center justify-center gap-2 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
|
||||
:disabled="downloading"
|
||||
@click="download"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': downloading }">{{ downloading ? 'progress_activity' : 'download' }}</span>
|
||||
{{ downloading ? 'Lädt herunter…' : 'Herunterladen' }}
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { partCount, formatBytes, formatDateTime, baseName } from '~/utils/format'
|
||||
import { Popup, PopupSize } from '~/utils/popup'
|
||||
import TextPreviewPopup from '~/components/popup/TextPreviewPopup.vue'
|
||||
import ConfirmPopup, { type ConfirmPayload } from '~/components/popup/ConfirmPopup.vue'
|
||||
import type { S3Object } from '~/utils/s3xml'
|
||||
|
||||
const props = defineProps<{ object: S3Object | null; bucket: string }>()
|
||||
const emit = defineEmits<{ close: []; error: [message: string]; deleted: [] }>()
|
||||
|
||||
const { downloadObject, deleteObject } = useS3Client()
|
||||
const downloading = ref(false)
|
||||
|
||||
const isTextFile = computed(() => props.object?.key.toLowerCase().endsWith('.txt') ?? false)
|
||||
|
||||
function openPreview() {
|
||||
if (!props.object) {
|
||||
return
|
||||
}
|
||||
usePopup().open(
|
||||
Popup.component(TextPreviewPopup)
|
||||
.setConfig({ heading: baseName(props.object.key), size: PopupSize.MEDIUM, closeOnOverlayClick: true })
|
||||
.setPayload({ bucket: props.bucket, key: props.object.key }),
|
||||
)
|
||||
}
|
||||
|
||||
function confirmDelete() {
|
||||
if (!props.object) {
|
||||
return
|
||||
}
|
||||
const key = props.object.key
|
||||
usePopup().open(
|
||||
Popup.component<ConfirmPayload>(ConfirmPopup)
|
||||
.setConfig({ heading: 'Objekt löschen', size: PopupSize.SMALL, closeOnOverlayClick: true, callback: () => emit('deleted') })
|
||||
.setPayload({
|
||||
message: `"${key}" wird unwiderruflich aus "${props.bucket}" gelöscht.`,
|
||||
confirmLabel: 'Löschen',
|
||||
onConfirm: () => deleteObject(props.bucket, key),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async function download() {
|
||||
if (!props.object) {
|
||||
return
|
||||
}
|
||||
downloading.value = true
|
||||
try {
|
||||
const blob = await downloadObject(props.bucket, props.object.key)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = baseName(props.object.key)
|
||||
link.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
catch {
|
||||
emit('error', `${baseName(props.object.key)} konnte nicht heruntergeladen werden.`)
|
||||
}
|
||||
finally {
|
||||
downloading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user