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.
This commit is contained in:
+74
@@ -28,6 +28,25 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<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">
|
<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>
|
<span class="material-symbols-outlined !text-[16px] text-muted">search</span>
|
||||||
<input
|
<input
|
||||||
@@ -58,9 +77,12 @@
|
|||||||
:has-search="search.length > 0"
|
:has-search="search.length > 0"
|
||||||
:search-term="search"
|
:search-term="search"
|
||||||
:error="objectsError"
|
:error="objectsError"
|
||||||
|
:selected-keys="selectedKeys"
|
||||||
@select="selectedObject = $event"
|
@select="selectedObject = $event"
|
||||||
@upload="openUploadPopup"
|
@upload="openUploadPopup"
|
||||||
@retry="retryLoadObjects"
|
@retry="retryLoadObjects"
|
||||||
|
@toggle="toggleSelection"
|
||||||
|
@toggle-all="toggleSelectAll"
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -81,6 +103,7 @@
|
|||||||
import { ref, computed, watch, onMounted } from 'vue'
|
import { ref, computed, watch, onMounted } from 'vue'
|
||||||
import { Popup, PopupSize } from '~/utils/popup'
|
import { Popup, PopupSize } from '~/utils/popup'
|
||||||
import UploadPopup from '~/components/popup/UploadPopup.vue'
|
import UploadPopup from '~/components/popup/UploadPopup.vue'
|
||||||
|
import MoveObjectsPopup, { type MoveObjectsPayload } from '~/components/popup/MoveObjectsPopup.vue'
|
||||||
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
useHead({ title: 'r9t · Object Storage' })
|
useHead({ title: 'r9t · Object Storage' })
|
||||||
@@ -99,6 +122,7 @@ const loadingObjects = ref(false)
|
|||||||
const errorMessage = ref<string | null>(null)
|
const errorMessage = ref<string | null>(null)
|
||||||
const objectsError = ref<string | null>(null)
|
const objectsError = ref<string | null>(null)
|
||||||
const toastMessage = ref<string | null>(null)
|
const toastMessage = ref<string | null>(null)
|
||||||
|
const selectedKeys = ref<Set<string>>(new Set())
|
||||||
|
|
||||||
const filteredObjects = computed(() => {
|
const filteredObjects = computed(() => {
|
||||||
if (!search.value) {
|
if (!search.value) {
|
||||||
@@ -111,6 +135,28 @@ const filteredObjects = computed(() => {
|
|||||||
function selectBucket(name: string) {
|
function selectBucket(name: string) {
|
||||||
selectedBucket.value = name
|
selectedBucket.value = name
|
||||||
selectedObject.value = null
|
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) {
|
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() {
|
async function loadBuckets() {
|
||||||
errorMessage.value = null
|
errorMessage.value = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,6 +3,16 @@
|
|||||||
<table v-if="loading || objects.length" class="w-full border-collapse text-sm">
|
<table v-if="loading || objects.length" class="w-full border-collapse text-sm">
|
||||||
<thead class="sticky top-0 bg-bg">
|
<thead class="sticky top-0 bg-bg">
|
||||||
<tr class="border-b border-border text-left text-xs tracking-[0.08em] text-muted">
|
<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">
|
<th class="px-4 py-2.5 font-medium">
|
||||||
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
|
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
|
||||||
</th>
|
</th>
|
||||||
@@ -17,7 +27,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<template v-if="loading">
|
<template v-if="loading">
|
||||||
<tr v-for="n in 5" :key="n" class="border-b border-border/60">
|
<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" />
|
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -27,8 +37,17 @@
|
|||||||
v-else
|
v-else
|
||||||
:key="object.key"
|
:key="object.key"
|
||||||
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
|
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)"
|
@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]">
|
<td class="px-4 py-[5px]">
|
||||||
<div class="flex items-center gap-2.5">
|
<div class="flex items-center gap-2.5">
|
||||||
<FileTypeBadge :filename="object.key" />
|
<FileTypeBadge :filename="object.key" />
|
||||||
@@ -96,8 +115,18 @@ const props = defineProps<{
|
|||||||
hasSearch: boolean
|
hasSearch: boolean
|
||||||
searchTerm: string
|
searchTerm: string
|
||||||
error?: string | null
|
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'
|
type SortKey = 'key' | 'size' | 'lastModified'
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -43,5 +43,49 @@ export function useS3Client() {
|
|||||||
await $fetch(`/api${encodeCanonicalPath(path)}`, { method: 'DELETE', headers })
|
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
@@ -11,22 +11,38 @@ export async function signS3Get(path: string, accessKey: string, secretKey: stri
|
|||||||
return signS3('GET', path, await sha256Hex(''), accessKey, secretKey)
|
return signS3('GET', path, await sha256Hex(''), accessKey, secretKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signS3Put(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
export async function signS3Put(
|
||||||
return signS3('PUT', path, 'UNSIGNED-PAYLOAD', accessKey, secretKey)
|
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> {
|
export async function signS3Delete(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||||
return signS3('DELETE', path, await sha256Hex(''), accessKey, secretKey)
|
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 amzDate = toAmzDate(new Date())
|
||||||
const dateStamp = amzDate.slice(0, 8)
|
const dateStamp = amzDate.slice(0, 8)
|
||||||
|
|
||||||
const signedHeaderValues: Record<string, string> = {
|
const unsortedHeaderValues: Record<string, string> = {
|
||||||
'x-amz-content-sha256': payloadHash,
|
'x-amz-content-sha256': payloadHash,
|
||||||
'x-amz-date': amzDate,
|
'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 signedHeaders = Object.keys(signedHeaderValues).join(';')
|
||||||
const canonicalHeaders = Object.entries(signedHeaderValues)
|
const canonicalHeaders = Object.entries(signedHeaderValues)
|
||||||
.map(([name, value]) => `${name}:${value}\n`)
|
.map(([name, value]) => `${name}:${value}\n`)
|
||||||
|
|||||||
Reference in New Issue
Block a user