Files
frontend/app/components/popup/BulkMovePopup.vue
T
andreas.dinauer 96f9d88200 feat: Bulk-Aktionen für Objekte (Auswählen, Löschen, Verschieben)
- Checkboxen in der Objekttabelle inkl. Select-All pro Bucket-Ansicht
- BulkActionBar zeigt Anzahl Auswahl + Aktionen (Verschieben/Löschen/Aufheben)
- BulkDeletePopup: löscht ausgewählte Objekte einzeln, mit Retry bei Teilfehlern
- BulkMovePopup: verschiebt in beliebigen Zielbucket/-pfad via Server-Side-Copy + Delete
- sigv4: signS3Copy für x-amz-copy-source PUT-Requests, Header werden jetzt
  sortiert statt auf Insertion-Order zu vertrauen
- useS3Client: copyObject/moveObject ergänzt

Move ist client-seitig Copy+Delete, da S3 kein natives Rename/Move kennt.
2026-09-10 22:25:34 +02:00

207 lines
6.8 KiB
Vue
Raw 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 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} Objekt${queue.length === 1 ? '' : 'en'} fehlgeschlagen`
: `${successCount} Objekt${successCount === 1 ? '' : 'e'} verschoben` }}
</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>Zielbucket</FieldLabel>
<select
v-model="destBucket"
class="mt-1 w-full rounded-md border border-border bg-bg px-3 py-2 text-sm text-text focus:outline-none"
>
<option v-for="bucket in buckets" :key="bucket.name" :value="bucket.name">{{ bucket.name }}</option>
</select>
</div>
<div>
<FieldLabel>Zielpfad (optional)</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">{{ destBucket || '–' }}/</span>
<input
v-model="destPath"
type="text"
placeholder="archiv/"
class="min-w-0 flex-1 bg-transparent text-text placeholder:text-muted/60 focus:outline-none"
>
</div>
</div>
<p class="mt-1.5 text-xs text-muted">
Objekte behalten ihren Dateinamen, werden aber unter diesem Pfad im Zielbucket abgelegt.
</p>
</div>
<div class="max-h-48 space-y-1.5 overflow-y-auto">
<div
v-for="item in queue"
:key="item.key"
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>
<p class="min-w-0 flex-1 truncate font-mono text-xs text-text">{{ item.key }}</p>
</div>
</div>
<p v-if="sameLocationWarning" class="text-sm text-accent">
Ziel entspricht dem aktuellen Ort — das würde nichts verschieben.
</p>
<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="!destBucket || moving || sameLocationWarning"
@click="startMove"
>
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': moving }">
{{ moving ? 'progress_activity' : 'drive_file_move' }}
</span>
{{ moving ? `Verschiebt (${doneCount}/${queue.length})…` : `${queue.length} Objekt${queue.length === 1 ? '' : 'e'} verschieben` }}
</button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { baseName } from '~/utils/format'
import type { S3Bucket } from '~/utils/s3xml'
type Status = 'pending' | 'moving' | 'done' | 'error'
interface QueueItem {
key: string
status: Status
}
const payload = usePopup().require<{ bucket: string, keys: string[] }>().payload!
const sourceBucket = payload.bucket
const { listBuckets, moveObject } = useS3Client()
const buckets = ref<S3Bucket[]>([])
const destBucket = ref('')
const destPath = ref('')
const queue = ref<QueueItem[]>(payload.keys.map((key) => ({ key, status: 'pending' as Status })))
const moving = ref(false)
const finished = ref(false)
const normalizedPath = computed(() => {
if (!destPath.value) {
return ''
}
return destPath.value.endsWith('/') ? destPath.value : `${destPath.value}/`
})
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)
const sameLocationWarning = computed(() => {
if (destBucket.value !== sourceBucket) {
return false
}
return queue.value.every((item) => `${normalizedPath.value}${baseName(item.key)}` === item.key)
})
function statusIcon(status: Status) {
if (status === 'moving') {
return 'progress_activity'
}
if (status === 'done') {
return 'check_circle'
}
if (status === 'error') {
return 'error'
}
return 'draft'
}
function statusIconClass(status: Status) {
if (status === 'moving') {
return 'animate-spin text-muted'
}
if (status === 'done') {
return 'text-accent'
}
if (status === 'error') {
return 'text-red-500'
}
return 'text-muted'
}
async function startMove() {
moving.value = true
const pending = queue.value.filter((item) => item.status === 'pending')
for (const item of pending) {
item.status = 'moving'
try {
const destKey = `${normalizedPath.value}${baseName(item.key)}`
await moveObject(sourceBucket, item.key, destBucket.value, destKey)
item.status = 'done'
}
catch {
item.status = 'error'
}
}
moving.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
}
onMounted(async () => {
buckets.value = await listBuckets()
destBucket.value = sourceBucket
})
</script>