Mehrfachauswahl in der Objekttabelle (Checkboxen + Alle-auswählen), neues Popup zum Verschieben in einen anderen Bucket, Move via Copy+Delete gegen die bestehende S3-Schnittstelle. sigv4 kann jetzt zusätzliche Header signieren (x-amz-copy-source), sonst nix am Backend angefasst wie gewünscht.
260 lines
8.4 KiB
Vue
260 lines
8.4 KiB
Vue
<template>
|
||
<div class="flex h-screen flex-col bg-bg text-text">
|
||
<NuxtRouteAnnouncer />
|
||
|
||
<header class="flex h-14 shrink-0 items-center justify-between border-b border-border bg-surface px-4">
|
||
<div class="flex items-center gap-2.5">
|
||
<span class="material-symbols-outlined text-accent">storage</span>
|
||
<span class="text-sm font-semibold tracking-[0.04em]">r9t</span>
|
||
</div>
|
||
<div class="flex items-center gap-2 rounded-full border border-border bg-surface-raised px-3 py-1 text-xs text-muted">
|
||
<span class="material-symbols-outlined !text-[15px]">vpn_key</span>
|
||
<span class="font-mono">{{ accessKey }}</span>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="flex min-h-0 flex-1">
|
||
<BucketList :buckets="buckets" :selected="selectedBucket" @select="selectBucket" @create="mockAction" />
|
||
|
||
<main class="flex min-w-0 flex-1 flex-col">
|
||
<div class="flex shrink-0 items-center justify-between gap-4 border-b border-border px-5 py-3.5">
|
||
<div class="flex items-center gap-1.5 text-sm">
|
||
<span class="text-muted">Bucket</span>
|
||
<span class="material-symbols-outlined !text-[16px] text-muted">chevron_right</span>
|
||
<span class="font-medium">{{ selectedBucket ?? '–' }}</span>
|
||
<span v-if="selectedBucket" class="ml-1 rounded-full bg-surface-raised px-2 py-0.5 text-xs text-muted">
|
||
{{ objects.length }} Objekte
|
||
</span>
|
||
</div>
|
||
|
||
<div class="flex items-center gap-2">
|
||
<div v-if="selectedKeys.size" class="flex items-center gap-2 rounded-md border border-border bg-surface-raised px-2.5 py-1.5">
|
||
<span class="text-sm text-muted">{{ selectedKeys.size }} ausgewählt</span>
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||
@click="openMovePopup"
|
||
>
|
||
<span class="material-symbols-outlined !text-[18px]">drive_file_move</span>
|
||
Verschieben
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="text-muted transition-colors hover:text-text"
|
||
title="Auswahl aufheben"
|
||
@click="clearSelection"
|
||
>
|
||
<span class="material-symbols-outlined !text-[18px]">close</span>
|
||
</button>
|
||
</div>
|
||
<div class="flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5">
|
||
<span class="material-symbols-outlined !text-[16px] text-muted">search</span>
|
||
<input
|
||
v-model="search"
|
||
type="text"
|
||
placeholder="Key filtern…"
|
||
class="w-40 bg-transparent text-sm text-text placeholder:text-muted focus:outline-none"
|
||
>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
class="flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||
@click="openUploadPopup"
|
||
>
|
||
<span class="material-symbols-outlined !text-[18px]">upload</span>
|
||
Hochladen
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<p v-if="errorMessage" class="shrink-0 border-b border-border bg-surface px-5 py-2 text-sm text-accent">
|
||
{{ errorMessage }}
|
||
</p>
|
||
|
||
<ObjectTable
|
||
:objects="filteredObjects"
|
||
:loading="loadingObjects"
|
||
:has-search="search.length > 0"
|
||
:search-term="search"
|
||
:error="objectsError"
|
||
:selected-keys="selectedKeys"
|
||
@select="selectedObject = $event"
|
||
@upload="openUploadPopup"
|
||
@retry="retryLoadObjects"
|
||
@toggle="toggleSelection"
|
||
@toggle-all="toggleSelectAll"
|
||
/>
|
||
</main>
|
||
|
||
<ObjectDetail
|
||
:object="selectedObject"
|
||
:bucket="selectedBucket ?? ''"
|
||
@close="selectedObject = null"
|
||
@error="notify"
|
||
@deleted="handleObjectDeleted"
|
||
/>
|
||
</div>
|
||
<AppToast :message="toastMessage" />
|
||
<PopupSlot />
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, computed, watch, onMounted } from 'vue'
|
||
import { Popup, PopupSize } from '~/utils/popup'
|
||
import UploadPopup from '~/components/popup/UploadPopup.vue'
|
||
import MoveObjectsPopup, { type MoveObjectsPayload } from '~/components/popup/MoveObjectsPopup.vue'
|
||
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
||
|
||
useHead({ title: 'r9t · Object Storage' })
|
||
|
||
const config = useRuntimeConfig()
|
||
const accessKey = config.public.s3AccessKey
|
||
|
||
const { listBuckets, listObjects } = useS3Client()
|
||
|
||
const buckets = ref<S3Bucket[]>([])
|
||
const objects = ref<S3Object[]>([])
|
||
const selectedBucket = ref<string | null>(null)
|
||
const selectedObject = ref<S3Object | null>(null)
|
||
const search = ref('')
|
||
const loadingObjects = ref(false)
|
||
const errorMessage = ref<string | null>(null)
|
||
const objectsError = ref<string | null>(null)
|
||
const toastMessage = ref<string | null>(null)
|
||
const selectedKeys = ref<Set<string>>(new Set())
|
||
|
||
const filteredObjects = computed(() => {
|
||
if (!search.value) {
|
||
return objects.value
|
||
}
|
||
const needle = search.value.toLowerCase()
|
||
return objects.value.filter((object) => object.key.toLowerCase().includes(needle))
|
||
})
|
||
|
||
function selectBucket(name: string) {
|
||
selectedBucket.value = name
|
||
selectedObject.value = null
|
||
clearSelection()
|
||
}
|
||
|
||
function toggleSelection(key: string) {
|
||
const next = new Set(selectedKeys.value)
|
||
if (next.has(key)) {
|
||
next.delete(key)
|
||
}
|
||
else {
|
||
next.add(key)
|
||
}
|
||
selectedKeys.value = next
|
||
}
|
||
|
||
function toggleSelectAll() {
|
||
const allSelected = filteredObjects.value.length > 0
|
||
&& filteredObjects.value.every((object) => selectedKeys.value.has(object.key))
|
||
selectedKeys.value = allSelected ? new Set() : new Set(filteredObjects.value.map((object) => object.key))
|
||
}
|
||
|
||
function clearSelection() {
|
||
selectedKeys.value = new Set()
|
||
}
|
||
|
||
function notify(message: string) {
|
||
toastMessage.value = message
|
||
setTimeout(() => { toastMessage.value = null }, 2500)
|
||
}
|
||
|
||
function mockAction() {
|
||
notify('Noch nicht verdrahtet — nur Lesezugriff in diesem UI.')
|
||
}
|
||
|
||
function handleObjectDeleted() {
|
||
selectedObject.value = null
|
||
notify('Objekt gelöscht.')
|
||
if (selectedBucket.value) {
|
||
loadObjects(selectedBucket.value)
|
||
}
|
||
}
|
||
|
||
function openUploadPopup() {
|
||
if (!selectedBucket.value) {
|
||
return
|
||
}
|
||
usePopup().open(
|
||
Popup.component(UploadPopup)
|
||
.setConfig({ heading: 'Hochladen', size: PopupSize.MEDIUM, closeOnOverlayClick: false, callback: () => loadObjects(selectedBucket.value!) })
|
||
.setPayload({ bucket: selectedBucket.value }),
|
||
)
|
||
}
|
||
|
||
function openMovePopup() {
|
||
if (!selectedBucket.value || !selectedKeys.value.size) {
|
||
return
|
||
}
|
||
usePopup().open(
|
||
Popup.component<MoveObjectsPayload>(MoveObjectsPopup)
|
||
.setConfig({
|
||
heading: 'Objekte verschieben',
|
||
size: PopupSize.MEDIUM,
|
||
closeOnOverlayClick: false,
|
||
callback: (payload) => handleObjectsMoved(payload as string[]),
|
||
})
|
||
.setPayload({ sourceBucket: selectedBucket.value, keys: [...selectedKeys.value], buckets: buckets.value }),
|
||
)
|
||
}
|
||
|
||
function handleObjectsMoved(movedKeys: string[]) {
|
||
const next = new Set(selectedKeys.value)
|
||
for (const key of movedKeys) {
|
||
next.delete(key)
|
||
}
|
||
selectedKeys.value = next
|
||
notify(movedKeys.length === 1 ? 'Objekt verschoben.' : `${movedKeys.length} Objekte verschoben.`)
|
||
if (selectedBucket.value) {
|
||
loadObjects(selectedBucket.value)
|
||
}
|
||
}
|
||
|
||
async function loadBuckets() {
|
||
errorMessage.value = null
|
||
try {
|
||
buckets.value = await listBuckets()
|
||
if (buckets.value.length && !selectedBucket.value) {
|
||
selectBucket(buckets.value[0]!.name)
|
||
}
|
||
}
|
||
catch {
|
||
errorMessage.value = 'Buckets konnten nicht geladen werden. Läuft der Server auf Port 8080?'
|
||
}
|
||
}
|
||
|
||
async function loadObjects(bucket: string) {
|
||
loadingObjects.value = true
|
||
objectsError.value = null
|
||
try {
|
||
objects.value = await listObjects(bucket)
|
||
}
|
||
catch {
|
||
objectsError.value = `Objekte für "${bucket}" konnten nicht geladen werden.`
|
||
objects.value = []
|
||
}
|
||
finally {
|
||
loadingObjects.value = false
|
||
}
|
||
}
|
||
|
||
function retryLoadObjects() {
|
||
if (selectedBucket.value) {
|
||
loadObjects(selectedBucket.value)
|
||
}
|
||
}
|
||
|
||
watch(selectedBucket, (bucket) => {
|
||
if (bucket) {
|
||
loadObjects(bucket)
|
||
}
|
||
})
|
||
|
||
onMounted(loadBuckets)
|
||
</script>
|