Files
2026-08-21 15:29:01 +02:00

186 lines
5.8 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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 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"
@select="selectedObject = $event"
@upload="openUploadPopup"
@retry="retryLoadObjects"
/>
</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 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 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
}
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 }),
)
}
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>