🎉 Init

This commit is contained in:
2026-08-21 15:29:01 +02:00
commit 02e5b1f4e4
33 changed files with 11392 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<template>
<Transition
enter-active-class="transition duration-200 ease-out"
enter-from-class="translate-y-2 opacity-0"
enter-to-class="translate-y-0 opacity-100"
leave-active-class="transition duration-150 ease-in"
leave-from-class="translate-y-0 opacity-100"
leave-to-class="translate-y-2 opacity-0"
>
<div
v-if="message"
class="fixed bottom-6 left-1/2 z-50 flex -translate-x-1/2 items-center gap-2 rounded-lg border border-border bg-surface-raised px-4 py-2.5 text-sm text-text shadow-lg shadow-black/40"
>
<span class="material-symbols-outlined text-accent">info</span>
{{ message }}
</div>
</Transition>
</template>
<script setup lang="ts">
defineProps<{ message: string | null }>()
</script>
+66
View File
@@ -0,0 +1,66 @@
<template>
<aside class="flex w-60 shrink-0 flex-col border-r border-border bg-surface">
<div class="flex items-center justify-between px-4 pb-2 pt-5">
<span class="text-xs font-semibold tracking-[0.14em] text-muted">BUCKETS</span>
<span class="rounded-full bg-surface-raised px-2 py-0.5 text-[11px] font-semibold text-muted">
{{ buckets.length }}
</span>
</div>
<nav class="sidebar-scroll flex-1 space-y-0.5 overflow-y-auto px-2.5 pt-1">
<button
v-for="bucket in buckets"
:key="bucket.name"
type="button"
class="group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-sm transition-all duration-150"
:class="bucket.name === selected
? 'bg-accent-dim text-text shadow-[inset_0_0_0_1px_rgba(234,88,12,0.25)]'
: 'text-muted hover:translate-x-0.5 hover:bg-surface-raised hover:text-text'"
@click="$emit('select', bucket.name)"
>
<span
class="flex size-6 shrink-0 items-center justify-center rounded-md transition-colors"
:class="bucket.name === selected ? 'bg-accent text-white' : 'bg-surface-raised text-muted group-hover:text-text'"
>
<span class="material-symbols-outlined !text-[15px]">folder</span>
</span>
<span class="truncate font-medium">{{ bucket.name }}</span>
</button>
<p v-if="!buckets.length" class="px-2.5 py-2 text-sm text-muted">
Keine Buckets gefunden.
</p>
</nav>
<div class="mx-2.5 mb-3 mt-2 border-t border-dashed border-border pt-2.5">
<button
type="button"
class="flex w-full items-center gap-2 rounded-lg border border-dashed border-border px-2.5 py-2 text-sm text-muted transition-colors hover:border-accent hover:text-accent"
@click="$emit('create')"
>
<span class="material-symbols-outlined !text-[18px]">add</span>
Bucket
</button>
</div>
</aside>
</template>
<script setup lang="ts">
import type { S3Bucket } from '~/utils/s3xml'
defineProps<{ buckets: S3Bucket[]; selected: string | null }>()
defineEmits<{ select: [name: string]; create: [] }>()
</script>
<style scoped>
.sidebar-scroll::-webkit-scrollbar {
width: 6px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
background-color: var(--color-border);
border-radius: 999px;
}
.sidebar-scroll::-webkit-scrollbar-track {
background-color: transparent;
}
</style>
+16
View File
@@ -0,0 +1,16 @@
<template>
<div class="flex items-center gap-2" :title="`${parts} part${parts === 1 ? '' : 's'}`">
<div class="flex h-2 w-16 gap-[2px]">
<div
v-for="n in parts"
:key="n"
class="flex-1 rounded-[1px] bg-accent"
/>
</div>
<span class="font-mono text-[11px] tabular-nums text-muted">{{ parts }}×</span>
</div>
</template>
<script setup lang="ts">
defineProps<{ parts: number }>()
</script>
+29
View File
@@ -0,0 +1,29 @@
<template>
<div>
<FieldLabel>{{ label }}</FieldLabel>
<div class="mt-1 flex items-center gap-2">
<p class="break-all font-mono text-sm text-text">{{ value }}</p>
<button
type="button"
class="shrink-0 text-muted transition-colors hover:text-accent"
:title="`${label} kopieren`"
@click="copy"
>
<span class="material-symbols-outlined !text-[16px]">{{ copied ? 'check' : 'content_copy' }}</span>
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const props = defineProps<{ label: string; value: string }>()
const copied = ref(false)
async function copy() {
await navigator.clipboard.writeText(props.value)
copied.value = true
setTimeout(() => { copied.value = false }, 1500)
}
</script>
+5
View File
@@ -0,0 +1,5 @@
<template>
<p class="text-xs font-semibold tracking-[0.1em] text-muted">
<slot />
</p>
</template>
+95
View File
@@ -0,0 +1,95 @@
<template>
<div class="badge-halo" :style="{ '--hue': fileType.hue, '--sat': fileType.sat + '%' }">
<span class="badge-mark">
<svg class="badge-mark-shape" viewBox="0 -960 960 960">
<path d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640v400q0 33-23.5 56.5T800-160H160Z" />
</svg>
<span class="badge-letter">{{ fileType.letter }}</span>
</span>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps<{ filename: string }>()
interface FileType {
letter: string
hue: number
sat: number
}
const FILE_TYPES: Record<string, FileType> = {
zip: { letter: 'Z', hue: 275, sat: 68 },
yaml: { letter: 'Y', hue: 175, sat: 62 },
yml: { letter: 'Y', hue: 175, sat: 62 },
json: { letter: 'J', hue: 42, sat: 78 },
txt: { letter: 'T', hue: 220, sat: 10 },
csv: { letter: 'C', hue: 145, sat: 55 },
log: { letter: 'L', hue: 210, sat: 65 },
md: { letter: 'M', hue: 255, sat: 55 },
sql: { letter: 'S', hue: 330, sat: 60 },
pdf: { letter: 'P', hue: 5, sat: 68 },
enc: { letter: 'E', hue: 25, sat: 88 },
}
const FALLBACK_HUE = 220
const FALLBACK_SAT = 8
const fileType = computed<FileType>(() => {
const dotIndex = props.filename.lastIndexOf('.')
const extension = dotIndex === -1 ? '' : props.filename.slice(dotIndex + 1).toLowerCase()
const known = FILE_TYPES[extension]
if (known) {
return known
}
if (!extension) {
return { letter: '·', hue: FALLBACK_HUE, sat: FALLBACK_SAT }
}
return { letter: extension[0]!.toUpperCase(), hue: FALLBACK_HUE, sat: FALLBACK_SAT }
})
</script>
<style scoped>
.badge-halo {
width: 34px;
height: 34px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
flex: none;
background: hsl(var(--hue) var(--sat) 50% / 14%);
border: 1.5px solid hsl(var(--hue) var(--sat) 46% / 40%);
}
.badge-mark {
position: relative;
width: 27px;
height: 27px;
}
.badge-mark-shape {
width: 100%;
height: 100%;
display: block;
filter: drop-shadow(0 1px 1.5px hsl(var(--hue) var(--sat) 30% / 45%));
}
.badge-mark-shape path {
fill: hsl(var(--hue) calc(var(--sat) * 0.45) 60%);
}
.badge-letter {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
padding-top: 5.5px;
color: #fff;
font-size: 10px;
font-weight: 800;
}
</style>
+148
View File
@@ -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>
+128
View File
@@ -0,0 +1,128 @@
<template>
<div class="flex-1 overflow-auto">
<table v-if="loading || objects.length" class="w-full border-collapse text-sm">
<thead class="sticky top-0 bg-bg">
<tr class="border-b border-border text-left text-xs tracking-[0.08em] text-muted">
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'size' ? sortDir : null" @click="toggleSort('size')">SIZE</SortHeader>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'lastModified' ? sortDir : null" @click="toggleSort('lastModified')">MODIFIED</SortHeader>
</th>
</tr>
</thead>
<tbody>
<template v-if="loading">
<tr v-for="n in 5" :key="n" class="border-b border-border/60">
<td class="px-4 py-3" colspan="3">
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
</td>
</tr>
</template>
<tr
v-for="object in sortedObjects"
v-else
:key="object.key"
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
@click="$emit('select', object)"
>
<td class="px-4 py-[5px]">
<div class="flex items-center gap-2.5">
<FileTypeBadge :filename="object.key" />
<PathBreadcrumb :path="object.key" />
</div>
</td>
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">{{ formatBytes(object.size) }}</td>
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">
<div class="flex items-center gap-2">
<span>{{ formatDate(object.lastModified) }} {{ formatTime(object.lastModified) }}</span>
<span
v-if="isToday(object.lastModified)"
class="rounded bg-surface-raised px-1 py-0.5 font-sans text-[11.5px] font-medium normal-case tracking-normal text-muted"
>Heute</span>
</div>
</td>
</tr>
</tbody>
</table>
<div v-else class="flex h-full flex-col items-center justify-center gap-3 px-6 text-center">
<template v-if="error">
<span class="material-symbols-outlined !text-[40px] text-accent">error</span>
<p class="text-text">Objekte konnten nicht geladen werden</p>
<p class="max-w-xs text-sm text-muted">{{ error }}</p>
<button
type="button"
class="mt-1 flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
@click="$emit('retry')"
>
<span class="material-symbols-outlined !text-[18px]">refresh</span>
Erneut versuchen
</button>
</template>
<template v-else>
<span class="material-symbols-outlined !text-[40px] text-muted">{{ hasSearch ? 'search_off' : 'inventory_2' }}</span>
<p class="text-text">{{ hasSearch ? 'Keine Treffer' : 'Dieser Bucket ist leer' }}</p>
<p class="max-w-xs text-sm text-muted">
{{ hasSearch
? `Keine Objekte passen zu "${searchTerm}".`
: 'Objekte, die du hier hochlädst, tauchen in dieser Liste auf.' }}
</p>
<button
v-if="!hasSearch"
type="button"
class="mt-1 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="$emit('upload')"
>
<span class="material-symbols-outlined !text-[18px]">upload</span>
Hochladen
</button>
</template>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
import type { S3Object } from '~/utils/s3xml'
const props = defineProps<{
objects: S3Object[]
loading: boolean
hasSearch: boolean
searchTerm: string
error?: string | null
}>()
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
type SortKey = 'key' | 'size' | 'lastModified'
const sortKey = ref<SortKey>('lastModified')
const sortDir = ref<'asc' | 'desc'>('desc')
function toggleSort(key: SortKey) {
if (sortKey.value === key) {
sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc'
return
}
sortKey.value = key
sortDir.value = 'asc'
}
const sortedObjects = computed(() => {
const factor = sortDir.value === 'asc' ? 1 : -1
return [...props.objects].sort((a, b) => {
if (sortKey.value === 'key') {
return a.key.localeCompare(b.key) * factor
}
if (sortKey.value === 'size') {
return (a.size - b.size) * factor
}
return (new Date(a.lastModified).getTime() - new Date(b.lastModified).getTime()) * factor
})
})
</script>
+20
View File
@@ -0,0 +1,20 @@
<template>
<span class="truncate">
<template v-for="(dir, i) in segments.dirs" :key="i">
<span class="text-muted">{{ dir }}</span><span class="mx-1.5 text-[17px] font-semibold text-text">›</span>
</template>
<span class="font-semibold text-text">{{ segments.file }}</span>
</span>
</template>
<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps<{ path: string }>()
const segments = computed(() => {
const parts = props.path.split('/')
const file = parts.pop() ?? props.path
return { dirs: parts, file }
})
</script>
+20
View File
@@ -0,0 +1,20 @@
<template>
<button type="button" class="inline-flex items-center gap-0.5 transition-colors hover:text-text" @click="$emit('click')">
<slot />
<span class="flex flex-col">
<span
class="material-symbols-outlined !text-[18px] leading-[8px]"
:class="active === 'asc' ? 'text-accent' : 'text-muted/40'"
>arrow_drop_up</span>
<span
class="material-symbols-outlined !text-[18px] leading-[8px] -mt-2.5"
:class="active === 'desc' ? 'text-accent' : 'text-muted/40'"
>arrow_drop_down</span>
</span>
</button>
</template>
<script setup lang="ts">
defineProps<{ active: 'asc' | 'desc' | null }>()
defineEmits<{ click: [] }>()
</script>
+56
View File
@@ -0,0 +1,56 @@
<template>
<div class="space-y-5">
<p class="text-sm text-text">{{ payload.message }}</p>
<p v-if="error" class="text-sm text-red-500">{{ error }}</p>
<div class="flex justify-end gap-2">
<button
type="button"
class="rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
@click="usePopup().close()"
>
Abbrechen
</button>
<button
type="button"
class="flex items-center gap-2 rounded-md bg-red-500 px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
:disabled="loading"
@click="confirm"
>
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': loading }">
{{ loading ? 'progress_activity' : 'delete' }}
</span>
{{ payload.confirmLabel ?? 'Löschen' }}
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
export interface ConfirmPayload {
message: string
confirmLabel?: string
onConfirm: () => Promise<void> | void
}
const payload = usePopup().require<ConfirmPayload>().payload!
const loading = ref(false)
const error = ref<string | null>(null)
async function confirm() {
loading.value = true
error.value = null
try {
await payload.onConfirm()
usePopup().callback()
usePopup().close()
}
catch {
error.value = 'Das hat nicht geklappt. Versuch es nochmal.'
}
finally {
loading.value = false
}
}
</script>
+67
View File
@@ -0,0 +1,67 @@
<template>
<Transition
enter-active-class="transition duration-150 ease-out"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="transition duration-100 ease-in"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-if="popup?.config"
class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-[2px]"
@click="closeOutside"
>
<div
class="flex max-h-[calc(100vh-4rem)] w-full flex-col rounded-lg border border-border bg-surface shadow-xl shadow-black/20"
:class="sizeClass"
@click.stop
>
<div class="flex shrink-0 items-center justify-between border-b border-border px-5 py-4">
<h2 class="text-sm font-semibold tracking-[0.04em] text-text">{{ popup.config.heading }}</h2>
<button type="button" class="text-muted transition-colors hover:text-text" @click="usePopup().close()">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<div class="min-h-0 flex-1 overflow-y-auto p-5">
<component :is="popup.component" />
</div>
</div>
</div>
</Transition>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted } from 'vue'
import { PopupSize } from '~/utils/popup'
const popup = computed(() => usePopup().get())
const sizeClass = computed(() => {
switch (popup.value?.config?.size) {
case PopupSize.SMALL:
return 'max-w-md'
case PopupSize.LARGE:
return 'max-w-4xl'
case PopupSize.FULL:
return 'max-w-[calc(100vw-2rem)]'
default:
return 'max-w-xl'
}
})
function closeOutside() {
if (popup.value?.config?.closeOnOverlayClick) {
usePopup().close()
}
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
usePopup().close()
}
}
onMounted(() => document.addEventListener('keydown', handleKeydown))
onUnmounted(() => document.removeEventListener('keydown', handleKeydown))
</script>
+26
View File
@@ -0,0 +1,26 @@
<template>
<div v-if="loading" class="h-40 animate-pulse rounded-md bg-surface-raised" />
<pre v-else class="whitespace-pre-wrap break-words font-mono text-xs text-text">{{ text }}</pre>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const payload = usePopup().require<{ bucket: string; key: string }>().payload!
const { getObjectText } = useS3Client()
const loading = ref(true)
const text = ref('')
onMounted(async () => {
try {
text.value = await getObjectText(payload.bucket, payload.key)
}
catch {
text.value = 'Datei konnte nicht geladen werden.'
}
finally {
loading.value = false
}
})
</script>
+222
View File
@@ -0,0 +1,222 @@
<template>
<div v-if="finished" class="flex flex-col items-center gap-4 py-8 text-center">
<div class="flex items-center gap-3">
<div
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full"
:class="hasErrors ? 'bg-red-500' : 'bg-green-500'"
>
<span class="material-symbols-outlined !text-[22px] text-white">{{ hasErrors ? 'close' : 'check' }}</span>
</div>
<p class="text-left text-text">
{{ hasErrors
? `${errorCount} von ${queue.length} Datei${queue.length === 1 ? '' : 'en'} fehlgeschlagen`
: `${successCount} Datei${successCount === 1 ? '' : 'en'} hochgeladen` }}
</p>
</div>
<p v-if="hasErrors" class="max-w-xs text-sm text-muted">
{{ successCount }} erfolgreich, {{ errorCount }} fehlgeschlagen. Nochmal versuchen?
</p>
<div class="mt-1 flex gap-2">
<button
v-if="hasErrors"
type="button"
class="rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
@click="retryFailed"
>
Erneut versuchen
</button>
<button
type="button"
class="rounded-md bg-accent px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90"
@click="usePopup().close()"
>
Fertig
</button>
</div>
</div>
<div v-else class="space-y-5">
<div>
<FieldLabel>Zielpfad</FieldLabel>
<div class="mt-1 flex items-center gap-2 rounded-md border border-border bg-bg px-3 py-2">
<span class="material-symbols-outlined !text-[18px] shrink-0 text-muted">folder</span>
<div class="flex flex-1 items-center font-mono text-sm">
<span class="shrink-0 text-muted">{{ bucket }}/</span>
<input
v-model="path"
type="text"
placeholder="backups/"
class="min-w-0 flex-1 bg-transparent text-text placeholder:text-muted/60 focus:outline-none"
>
</div>
</div>
</div>
<div
class="flex flex-col items-center justify-center gap-1.5 rounded-lg border-2 border-dashed px-6 py-10 text-center transition-colors"
:class="isDragging ? 'border-accent bg-accent-dim/40' : 'border-border hover:border-muted'"
@dragover.prevent="isDragging = true"
@dragleave.prevent="isDragging = false"
@drop.prevent="handleDrop"
@click="fileInput?.click()"
>
<span class="material-symbols-outlined !text-[32px] text-muted">upload_file</span>
<p class="text-sm text-text">Dateien hierher ziehen</p>
<p class="text-xs text-muted">oder klicken zum Auswählen</p>
<input ref="fileInput" type="file" multiple class="hidden" @change="handleFileSelect">
</div>
<div v-if="queue.length" class="max-h-48 space-y-1.5 overflow-y-auto">
<div
v-for="item in queue"
:key="item.id"
class="flex items-center gap-2.5 rounded-md border border-border px-3 py-2"
>
<span class="material-symbols-outlined !text-[16px] shrink-0" :class="statusIconClass(item.status)">
{{ statusIcon(item.status) }}
</span>
<div class="min-w-0 flex-1">
<p class="truncate font-mono text-xs text-text">{{ normalizedPath }}{{ item.file.name }}</p>
<p class="text-[11px] text-muted">{{ formatBytes(item.file.size) }}</p>
</div>
<button
v-if="item.status === 'pending'"
type="button"
class="shrink-0 text-muted transition-colors hover:text-text"
@click="queue = queue.filter((q) => q.id !== item.id)"
>
<span class="material-symbols-outlined !text-[16px]">close</span>
</button>
</div>
</div>
<div class="flex justify-end gap-2 pt-1">
<button
type="button"
class="rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
@click="usePopup().close()"
>
Abbrechen
</button>
<button
type="button"
class="flex items-center gap-2 rounded-md bg-accent px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="!pendingCount || uploading"
@click="startUpload"
>
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': uploading }">
{{ uploading ? 'progress_activity' : 'upload' }}
</span>
{{ uploading ? `Lädt hoch (${doneCount}/${queue.length})…` : `${pendingCount} Datei${pendingCount === 1 ? '' : 'en'} hochladen` }}
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { formatBytes } from '~/utils/format'
type Status = 'pending' | 'uploading' | 'done' | 'error'
interface QueueItem {
id: string
file: File
status: Status
}
const payload = usePopup().require<{ bucket: string }>().payload!
const bucket = payload.bucket
const { uploadObject } = useS3Client()
const path = ref('')
const queue = ref<QueueItem[]>([])
const uploading = ref(false)
const finished = ref(false)
const isDragging = ref(false)
const fileInput = ref<HTMLInputElement | null>(null)
const normalizedPath = computed(() => {
if (!path.value) {
return ''
}
return path.value.endsWith('/') ? path.value : `${path.value}/`
})
const pendingCount = computed(() => queue.value.filter((item) => item.status === 'pending').length)
const doneCount = computed(() => queue.value.filter((item) => item.status === 'done' || item.status === 'error').length)
const successCount = computed(() => queue.value.filter((item) => item.status === 'done').length)
const errorCount = computed(() => queue.value.filter((item) => item.status === 'error').length)
const hasErrors = computed(() => errorCount.value > 0)
function addFiles(fileList: FileList | null) {
if (!fileList) {
return
}
for (const file of Array.from(fileList)) {
queue.value.push({ id: `${file.name}-${file.size}-${Math.random().toString(36).slice(2)}`, file, status: 'pending' })
}
}
function handleDrop(event: DragEvent) {
isDragging.value = false
addFiles(event.dataTransfer?.files ?? null)
}
function handleFileSelect(event: Event) {
const input = event.target as HTMLInputElement
addFiles(input.files)
input.value = ''
}
function statusIcon(status: Status) {
if (status === 'uploading') {
return 'progress_activity'
}
if (status === 'done') {
return 'check_circle'
}
if (status === 'error') {
return 'error'
}
return 'draft'
}
function statusIconClass(status: Status) {
if (status === 'uploading') {
return 'animate-spin text-muted'
}
if (status === 'done') {
return 'text-accent'
}
if (status === 'error') {
return 'text-red-500'
}
return 'text-muted'
}
async function startUpload() {
uploading.value = true
const pending = queue.value.filter((item) => item.status === 'pending')
for (const item of pending) {
item.status = 'uploading'
try {
await uploadObject(bucket, `${normalizedPath.value}${item.file.name}`, item.file)
item.status = 'done'
}
catch {
item.status = 'error'
}
}
uploading.value = false
finished.value = true
usePopup().callback()
}
function retryFailed() {
queue.value = queue.value
.filter((item) => item.status === 'error')
.map((item) => ({ ...item, status: 'pending' as Status }))
finished.value = false
}
</script>