Author SHA1 Message Date
andreas.dinauer 33c3670ba7 Bulk-Move für Objects
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.
2026-09-12 21:32:41 +02:00
6 changed files with 273 additions and 122 deletions
-115
View File
@@ -1,115 +0,0 @@
# r9t Frontend
Web-UI für unseren S3-kompatiblen Object Storage (r9t). Rein clientseitiges Nuxt/Vue-Frontend, das Buckets und Objekte auflistet, Objekte anzeigt/hochlädt/löscht und dafür Requests direkt per AWS SigV4 signiert.
## Tech-Stack
- [Nuxt 4](https://nuxt.com/) (Vue 3, TypeScript)
- [Tailwind CSS 4](https://tailwindcss.com/) (via `@tailwindcss/vite`)
- Kein State-Management-Framework, kein Backend-Code hier — nur UI + ein schlanker S3-Client
## Setup
Voraussetzung: Node.js (siehe `Dockerfile`, dort läuft `node:22.9.0-alpine`).
```bash
npm install
```
`.env` aus der Vorlage anlegen:
```bash
cp .env.example .env
```
Relevante Variablen (siehe `nuxt.config.ts` → `runtimeConfig.public`):
| Variable | Zweck | Default (Beispiel) |
|-------------------------------|---------------------------------------------|---------------------|
| `NUXT_PUBLIC_S3_ACCESS_KEY` | Access Key für SigV4-Signierung der Requests | `devkey` |
| `NUXT_PUBLIC_S3_SECRET_KEY` | Secret Key für SigV4-Signierung | `devsecret` |
Wichtig: Diese Keys landen im Public Runtime Config, sind also im Client-Bundle sichtbar. Für den Dev-Betrieb gegen einen lokalen/Test-Storage okay, für produktive Zugangsdaten nicht geeignet — das müsste über einen Backend-Proxy laufen, der Requests serverseitig signiert.
## Entwicklung
```bash
npm run dev
```
Läuft auf `http://localhost:3000`. Requests an `/api/*` werden per Vite-Dev-Proxy (siehe `nuxt.config.ts`) an `http://localhost:8080` weitergeleitet und dort landet der eigentliche S3-Server. Heißt: Für lokale Entwicklung muss der Storage-Server separat auf Port 8080 laufen.
## Build & Produktion
```bash
npm run build # Produktions-Build (.output/)
npm run preview # lokal den Produktions-Build testen
npm run generate # statischer Export, falls mal gebraucht
```
### Docker
```bash
docker build --build-arg VERSION=<version> -t r9t-frontend .
docker run -p 3000:3000 r9t-frontend
```
Das Dockerfile baut mit `npx nuxi build` und startet den Nitro-Server via `node .output/server/index.mjs`.
### CI/CD
`Jenkinsfile` baut das Image, pusht es nach `harbor.dinauer.dev/r9t/frontend:<BUILD_NUMBER>` und räumt danach den lokalen Build-Agent wieder auf. Kein automatischer Deploy-Schritt enthalten — Image landet nur in der Registry.
## Projektstruktur
```
app/
├── app.vue # Root-Komponente, App-Layout, State-Orchestrierung
├── assets/css/main.css # Tailwind-Einstieg
├── components/
│ ├── BucketList.vue # Sidebar mit Bucket-Auswahl
│ ├── ObjectTable.vue # Objektliste im gewählten Bucket
│ ├── ObjectDetail.vue # Detail-/Aktions-Panel für ein Objekt
│ ├── PathBreadcrumb.vue
│ ├── SortHeader.vue
│ ├── ChunkBar.vue
│ ├── CopyField.vue
│ ├── FieldLabel.vue
│ ├── FileTypeBadge.vue
│ ├── AppToast.vue # Toast-Benachrichtigungen
│ └── popup/
│ ├── PopupSlot.vue # Rendert die aktuell offene Popup-Instanz
│ ├── ConfirmPopup.vue
│ ├── UploadPopup.vue
│ └── TextPreviewPopup.vue
├── composables/
│ ├── useS3Client.ts # High-Level S3-Operationen (list/get/put/delete)
│ └── usePopup.ts # Globaler Popup-Store
└── utils/
├── sigv4.ts # AWS SigV4 Request-Signierung (browserseitig, WebCrypto)
├── s3xml.ts # Parsen der S3 List-XML-Responses
├── popup.ts # Popup-Klasse/Config-Typen
└── format.ts # Formatierungs-Helper (Größen, Daten, o.ä.)
```
Sonstige relevante Dateien:
- `nuxt.config.ts` — Runtime-Config, Tailwind-Plugin, Dev-Proxy nach `/api`
- `Dockerfile` — Produktions-Image
- `Jenkinsfile` — Build-Pipeline (Image bauen + nach Harbor pushen)
- `.env.example` — Vorlage für lokale Env-Variablen
## Funktionsweise (Kurzfassung)
1. `app.vue` lädt beim Mount die Bucket-Liste (`useS3Client().listBuckets()`).
2. Bei Bucket-Auswahl werden die Objekte geladen (`listObjects`), gefiltert per Suchfeld (Client-seitig, kein Server-Filter).
3. Jeder Request wird vorher in `sigv4.ts` per AWS4-HMAC-SHA256 signiert (Access/Secret Key aus der Runtime-Config) und läuft über den `/api`-Proxy zum eigentlichen S3-Server.
4. Objekt-Aktionen (Download, Upload, Löschen, Text-Vorschau) laufen über Popups (`usePopup`/`PopupSlot`), die dynamisch eine Vue-Komponente rendern.
5. Bucket-Erstellung ist aktuell nur gemockt (`mockAction` in `app.vue`) — das UI unterstützt bislang keinen echten Bucket-Create/Delete.
## Bekannte Einschränkungen
- Keine Authentifizierung im UI selbst — Access/Secret Key liegen statisch in der Config.
- Kein serverseitiger Proxy für die Signierung, SigV4 läuft komplett im Browser.
- Bucket-Erstellung ist nicht implementiert, nur ein Platzhalter-Toast.
- Kein automatisierter Test-Runner im Repo vorhanden (kein `test`-Script in `package.json`).
+74
View File
@@ -28,6 +28,25 @@
</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
@@ -58,9 +77,12 @@
: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>
@@ -81,6 +103,7 @@
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' })
@@ -99,6 +122,7 @@ 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) {
@@ -111,6 +135,28 @@ const filteredObjects = computed(() => {
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) {
@@ -141,6 +187,34 @@ function openUploadPopup() {
)
}
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 {
+31 -2
View File
@@ -3,6 +3,16 @@
<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="w-10 px-4 py-2.5 font-medium">
<input
type="checkbox"
class="size-4 cursor-pointer accent-accent"
:checked="allSelected"
:indeterminate="someSelected"
@click.stop
@change="$emit('toggle-all')"
>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
</th>
@@ -17,7 +27,7 @@
<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">
<td class="px-4 py-3" colspan="4">
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
</td>
</tr>
@@ -27,8 +37,17 @@
v-else
:key="object.key"
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
:class="{ 'bg-accent-dim/40': selectedKeys.has(object.key) }"
@click="$emit('select', object)"
>
<td class="px-4 py-[5px]" @click.stop>
<input
type="checkbox"
class="size-4 cursor-pointer accent-accent"
:checked="selectedKeys.has(object.key)"
@change="$emit('toggle', object.key)"
>
</td>
<td class="px-4 py-[5px]">
<div class="flex items-center gap-2.5">
<FileTypeBadge :filename="object.key" />
@@ -96,8 +115,18 @@ const props = defineProps<{
hasSearch: boolean
searchTerm: string
error?: string | null
selectedKeys: Set<string>
}>()
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
defineEmits<{
select: [object: S3Object]
upload: []
retry: []
toggle: [key: string]
'toggle-all': []
}>()
const allSelected = computed(() => props.objects.length > 0 && props.objects.every((object) => props.selectedKeys.has(object.key)))
const someSelected = computed(() => !allSelected.value && props.objects.some((object) => props.selectedKeys.has(object.key)))
type SortKey = 'key' | 'size' | 'lastModified'
+103
View File
@@ -0,0 +1,103 @@
<template>
<div class="space-y-5">
<div>
<FieldLabel>Objekte</FieldLabel>
<p class="mt-1 text-sm text-text">
{{ payload.keys.length }} Objekt{{ payload.keys.length === 1 ? '' : 'e' }} aus
<span class="font-mono">{{ payload.sourceBucket }}</span>
</p>
<ul class="mt-2 max-h-32 space-y-1 overflow-y-auto rounded-md border border-border bg-bg px-3 py-2">
<li v-for="key in payload.keys" :key="key" class="truncate font-mono text-xs text-muted">
{{ key }}
</li>
</ul>
</div>
<div>
<FieldLabel>Zielbucket</FieldLabel>
<select
v-model="targetBucket"
class="mt-1 w-full rounded-md border border-border bg-bg px-3 py-2 text-sm text-text focus:outline-none"
>
<option value="" disabled>Bucket auswählen…</option>
<option v-for="bucket in destinationBuckets" :key="bucket.name" :value="bucket.name">
{{ bucket.name }}
</option>
</select>
<p v-if="!destinationBuckets.length" class="mt-1.5 text-xs text-muted">
Kein anderer Bucket verfügbar.
</p>
</div>
<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-accent px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
:disabled="loading || !targetBucket"
@click="confirm"
>
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': loading }">
{{ loading ? 'progress_activity' : 'drive_file_move' }}
</span>
Verschieben
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import type { S3Bucket } from '~/utils/s3xml'
export interface MoveObjectsPayload {
sourceBucket: string
keys: string[]
buckets: S3Bucket[]
}
const payload = usePopup().require<MoveObjectsPayload>().payload!
const { moveObjects } = useS3Client()
const targetBucket = ref('')
const loading = ref(false)
const error = ref<string | null>(null)
const destinationBuckets = computed(() => payload.buckets.filter((bucket) => bucket.name !== payload.sourceBucket))
async function confirm() {
if (!targetBucket.value) {
return
}
loading.value = true
error.value = null
try {
const failures = await moveObjects(payload.sourceBucket, payload.keys, targetBucket.value)
if (failures.length) {
error.value = failures.length === payload.keys.length
? 'Das hat nicht geklappt. Versuch es nochmal.'
: `${failures.length} von ${payload.keys.length} Objekten konnten nicht verschoben werden.`
if (failures.length < payload.keys.length) {
usePopup().callback(payload.keys.filter((key) => !failures.some((failure) => failure.key === key)))
}
return
}
usePopup().callback(payload.keys)
usePopup().close()
}
catch {
error.value = 'Das hat nicht geklappt. Versuch es nochmal.'
}
finally {
loading.value = false
}
}
</script>
+45 -1
View File
@@ -43,5 +43,49 @@ export function useS3Client() {
await $fetch(`/api${encodeCanonicalPath(path)}`, { method: 'DELETE', headers })
}
return { listBuckets, listObjects, downloadObject, getObjectText, uploadObject, deleteObject }
async function copyObject(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Promise<void> {
const destPath = `/${destBucket}/${destKey}`
const copySource = encodeCanonicalPath(`/${sourceBucket}/${sourceKey}`)
const headers = await signS3Put(destPath, config.public.s3AccessKey, config.public.s3SecretKey, {
'x-amz-copy-source': copySource,
})
await $fetch(`/api${encodeCanonicalPath(destPath)}`, {
method: 'PUT',
headers: { ...headers, 'x-amz-copy-source': copySource },
})
}
async function moveObject(sourceBucket: string, key: string, destBucket: string): Promise<void> {
await copyObject(sourceBucket, key, destBucket, key)
await deleteObject(sourceBucket, key)
}
async function moveObjects(
sourceBucket: string,
keys: string[],
destBucket: string,
): Promise<{ key: string; error: unknown }[]> {
const failures: { key: string; error: unknown }[] = []
for (const key of keys) {
try {
await moveObject(sourceBucket, key, destBucket)
}
catch (error) {
failures.push({ key, error })
}
}
return failures
}
return {
listBuckets,
listObjects,
downloadObject,
getObjectText,
uploadObject,
deleteObject,
copyObject,
moveObject,
moveObjects,
}
}
+20 -4
View File
@@ -11,22 +11,38 @@ export async function signS3Get(path: string, accessKey: string, secretKey: stri
return signS3('GET', path, await sha256Hex(''), accessKey, secretKey)
}
export async function signS3Put(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
return signS3('PUT', path, 'UNSIGNED-PAYLOAD', accessKey, secretKey)
export async function signS3Put(
path: string,
accessKey: string,
secretKey: string,
extraHeaders?: Record<string, string>,
): Promise<SignedHeaders> {
return signS3('PUT', path, 'UNSIGNED-PAYLOAD', accessKey, secretKey, extraHeaders)
}
export async function signS3Delete(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
return signS3('DELETE', path, await sha256Hex(''), accessKey, secretKey)
}
async function signS3(method: string, path: string, payloadHash: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
async function signS3(
method: string,
path: string,
payloadHash: string,
accessKey: string,
secretKey: string,
extraHeaders?: Record<string, string>,
): Promise<SignedHeaders> {
const amzDate = toAmzDate(new Date())
const dateStamp = amzDate.slice(0, 8)
const signedHeaderValues: Record<string, string> = {
const unsortedHeaderValues: Record<string, string> = {
'x-amz-content-sha256': payloadHash,
'x-amz-date': amzDate,
...extraHeaders,
}
const signedHeaderValues = Object.fromEntries(
Object.entries(unsortedHeaderValues).sort(([a], [b]) => a.localeCompare(b)),
)
const signedHeaders = Object.keys(signedHeaderValues).join(';')
const canonicalHeaders = Object.entries(signedHeaderValues)
.map(([name, value]) => `${name}:${value}\n`)