🎉 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
+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>