Bulk-Aktionen: Objekte mehrfach auswählen, löschen und verschieben #2
+58
@@ -52,15 +52,24 @@
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
|
||||
<BulkActionBar
|
||||
:count="selectedKeys.size"
|
||||
@move="openBulkMovePopup"
|
||||
@delete="openBulkDeletePopup"
|
||||
@clear="selectedKeys = new Set()"
|
||||
/>
|
||||
|
||||
<ObjectTable
|
||||
:objects="filteredObjects"
|
||||
:loading="loadingObjects"
|
||||
:has-search="search.length > 0"
|
||||
:search-term="search"
|
||||
:error="objectsError"
|
||||
:selected-keys="selectedKeys"
|
||||
@select="selectedObject = $event"
|
||||
@upload="openUploadPopup"
|
||||
@retry="retryLoadObjects"
|
||||
@update:selected-keys="selectedKeys = $event"
|
||||
/>
|
||||
</main>
|
||||
|
||||
@@ -81,6 +90,8 @@
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { Popup, PopupSize } from '~/utils/popup'
|
||||
import UploadPopup from '~/components/popup/UploadPopup.vue'
|
||||
import BulkDeletePopup from '~/components/popup/BulkDeletePopup.vue'
|
||||
import BulkMovePopup from '~/components/popup/BulkMovePopup.vue'
|
||||
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
||||
|
||||
useHead({ title: 'r9t · Object Storage' })
|
||||
@@ -94,6 +105,7 @@ const buckets = ref<S3Bucket[]>([])
|
||||
const objects = ref<S3Object[]>([])
|
||||
const selectedBucket = ref<string | null>(null)
|
||||
const selectedObject = ref<S3Object | null>(null)
|
||||
const selectedKeys = ref<Set<string>>(new Set())
|
||||
const search = ref('')
|
||||
const loadingObjects = ref(false)
|
||||
const errorMessage = ref<string | null>(null)
|
||||
@@ -111,6 +123,7 @@ const filteredObjects = computed(() => {
|
||||
function selectBucket(name: string) {
|
||||
selectedBucket.value = name
|
||||
selectedObject.value = null
|
||||
selectedKeys.value = new Set()
|
||||
}
|
||||
|
||||
function notify(message: string) {
|
||||
@@ -123,6 +136,11 @@ function mockAction() {
|
||||
}
|
||||
|
||||
function handleObjectDeleted() {
|
||||
if (selectedObject.value) {
|
||||
const next = new Set(selectedKeys.value)
|
||||
next.delete(selectedObject.value.key)
|
||||
selectedKeys.value = next
|
||||
}
|
||||
selectedObject.value = null
|
||||
notify('Objekt gelöscht.')
|
||||
if (selectedBucket.value) {
|
||||
@@ -130,6 +148,46 @@ function handleObjectDeleted() {
|
||||
}
|
||||
}
|
||||
|
||||
function openBulkDeletePopup() {
|
||||
if (!selectedBucket.value || !selectedKeys.value.size) {
|
||||
return
|
||||
}
|
||||
const keys = Array.from(selectedKeys.value)
|
||||
usePopup().open(
|
||||
Popup.component(BulkDeletePopup)
|
||||
.setConfig({
|
||||
heading: 'Objekte löschen',
|
||||
size: PopupSize.MEDIUM,
|
||||
closeOnOverlayClick: false,
|
||||
callback: () => {
|
||||
selectedKeys.value = new Set()
|
||||
loadObjects(selectedBucket.value!)
|
||||
},
|
||||
})
|
||||
.setPayload({ bucket: selectedBucket.value, keys }),
|
||||
)
|
||||
}
|
||||
|
||||
function openBulkMovePopup() {
|
||||
if (!selectedBucket.value || !selectedKeys.value.size) {
|
||||
return
|
||||
}
|
||||
const keys = Array.from(selectedKeys.value)
|
||||
usePopup().open(
|
||||
Popup.component(BulkMovePopup)
|
||||
.setConfig({
|
||||
heading: 'Objekte verschieben',
|
||||
size: PopupSize.MEDIUM,
|
||||
closeOnOverlayClick: false,
|
||||
callback: () => {
|
||||
selectedKeys.value = new Set()
|
||||
loadObjects(selectedBucket.value!)
|
||||
},
|
||||
})
|
||||
.setPayload({ bucket: selectedBucket.value, keys }),
|
||||
)
|
||||
}
|
||||
|
||||
function openUploadPopup() {
|
||||
if (!selectedBucket.value) {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<div
|
||||
v-if="count > 0"
|
||||
class="flex shrink-0 items-center justify-between gap-4 border-b border-border bg-accent-dim/40 px-5 py-2.5"
|
||||
>
|
||||
<div class="flex items-center gap-2 text-sm text-text">
|
||||
<span class="material-symbols-outlined !text-[18px] text-accent">check_circle</span>
|
||||
{{ count }} Objekt{{ count === 1 ? '' : 'e' }} ausgewählt
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="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('move')"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[16px]">drive_file_move</span>
|
||||
Verschieben
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1.5 rounded-md bg-red-500 px-3 py-1.5 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||||
@click="$emit('delete')"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[16px]">delete</span>
|
||||
Löschen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1.5 rounded-md px-2 py-1.5 text-sm text-muted transition-colors hover:text-text"
|
||||
@click="$emit('clear')"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[16px]">close</span>
|
||||
Auswahl aufheben
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{ count: number }>()
|
||||
defineEmits<{ move: []; delete: []; clear: [] }>()
|
||||
</script>
|
||||
@@ -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">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="size-4 cursor-pointer accent-accent"
|
||||
:checked="allSelected"
|
||||
:indeterminate="someSelected && !allSelected"
|
||||
@click.stop
|
||||
@change="toggleSelectAll"
|
||||
>
|
||||
</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/30': 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="toggleSelect(object.key)"
|
||||
>
|
||||
</td>
|
||||
<td class="px-4 py-[5px]">
|
||||
<div class="flex items-center gap-2.5">
|
||||
<FileTypeBadge :filename="object.key" />
|
||||
@@ -96,8 +115,45 @@ const props = defineProps<{
|
||||
hasSearch: boolean
|
||||
searchTerm: string
|
||||
error?: string | null
|
||||
selectedKeys: Set<string>
|
||||
}>()
|
||||
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
|
||||
const emit = defineEmits<{
|
||||
select: [object: S3Object]
|
||||
upload: []
|
||||
retry: []
|
||||
'update:selectedKeys': [keys: Set<string>]
|
||||
}>()
|
||||
|
||||
function toggleSelect(key: string) {
|
||||
const next = new Set(props.selectedKeys)
|
||||
if (next.has(key)) {
|
||||
next.delete(key)
|
||||
}
|
||||
else {
|
||||
next.add(key)
|
||||
}
|
||||
emit('update:selectedKeys', next)
|
||||
}
|
||||
|
||||
const allSelected = computed(() => props.objects.length > 0 && props.objects.every((object) => props.selectedKeys.has(object.key)))
|
||||
const someSelected = computed(() => props.objects.some((object) => props.selectedKeys.has(object.key)))
|
||||
|
||||
function toggleSelectAll() {
|
||||
if (allSelected.value) {
|
||||
const next = new Set(props.selectedKeys)
|
||||
for (const object of props.objects) {
|
||||
next.delete(object.key)
|
||||
}
|
||||
emit('update:selectedKeys', next)
|
||||
}
|
||||
else {
|
||||
const next = new Set(props.selectedKeys)
|
||||
for (const object of props.objects) {
|
||||
next.add(object.key)
|
||||
}
|
||||
emit('update:selectedKeys', next)
|
||||
}
|
||||
}
|
||||
|
||||
type SortKey = 'key' | 'size' | 'lastModified'
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
<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'} gelöscht` }}
|
||||
</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">
|
||||
<p class="text-sm text-text">
|
||||
{{ queue.length }} Objekt{{ queue.length === 1 ? '' : 'e' }} werden unwiderruflich aus "{{ bucket }}" gelöscht.
|
||||
</p>
|
||||
|
||||
<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>
|
||||
|
||||
<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-red-500 px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
|
||||
:disabled="deleting"
|
||||
@click="startDelete"
|
||||
>
|
||||
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': deleting }">
|
||||
{{ deleting ? 'progress_activity' : 'delete' }}
|
||||
</span>
|
||||
{{ deleting ? `Löscht (${doneCount}/${queue.length})…` : `${queue.length} Objekt${queue.length === 1 ? '' : 'e'} löschen` }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
type Status = 'pending' | 'deleting' | 'done' | 'error'
|
||||
|
||||
interface QueueItem {
|
||||
key: string
|
||||
status: Status
|
||||
}
|
||||
|
||||
const payload = usePopup().require<{ bucket: string, keys: string[] }>().payload!
|
||||
const bucket = payload.bucket
|
||||
const { deleteObject } = useS3Client()
|
||||
|
||||
const queue = ref<QueueItem[]>(payload.keys.map((key) => ({ key, status: 'pending' as Status })))
|
||||
const deleting = ref(false)
|
||||
const finished = ref(false)
|
||||
|
||||
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 statusIcon(status: Status) {
|
||||
if (status === 'deleting') {
|
||||
return 'progress_activity'
|
||||
}
|
||||
if (status === 'done') {
|
||||
return 'check_circle'
|
||||
}
|
||||
if (status === 'error') {
|
||||
return 'error'
|
||||
}
|
||||
return 'draft'
|
||||
}
|
||||
|
||||
function statusIconClass(status: Status) {
|
||||
if (status === 'deleting') {
|
||||
return 'animate-spin text-muted'
|
||||
}
|
||||
if (status === 'done') {
|
||||
return 'text-accent'
|
||||
}
|
||||
if (status === 'error') {
|
||||
return 'text-red-500'
|
||||
}
|
||||
return 'text-muted'
|
||||
}
|
||||
|
||||
async function startDelete() {
|
||||
deleting.value = true
|
||||
const pending = queue.value.filter((item) => item.status === 'pending')
|
||||
for (const item of pending) {
|
||||
item.status = 'deleting'
|
||||
try {
|
||||
await deleteObject(bucket, item.key)
|
||||
item.status = 'done'
|
||||
}
|
||||
catch {
|
||||
item.status = 'error'
|
||||
}
|
||||
}
|
||||
deleting.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>
|
||||
@@ -0,0 +1,206 @@
|
||||
<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>
|
||||
@@ -1,4 +1,4 @@
|
||||
import { signS3Get, signS3Put, signS3Delete, encodeCanonicalPath } from '~/utils/sigv4'
|
||||
import { signS3Get, signS3Put, signS3Delete, signS3Copy, encodeCanonicalPath } from '~/utils/sigv4'
|
||||
import { parseBucketsXml, parseObjectsXml, type S3Bucket, type S3Object } from '~/utils/s3xml'
|
||||
|
||||
export function useS3Client() {
|
||||
@@ -43,5 +43,17 @@ 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 = `/${sourceBucket}/${sourceKey}`
|
||||
const headers = await signS3Copy(destPath, copySource, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||
await $fetch(`/api${encodeCanonicalPath(destPath)}`, { method: 'PUT', headers })
|
||||
}
|
||||
|
||||
async function moveObject(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Promise<void> {
|
||||
await copyObject(sourceBucket, sourceKey, destBucket, destKey)
|
||||
await deleteObject(sourceBucket, sourceKey)
|
||||
}
|
||||
|
||||
return { listBuckets, listObjects, downloadObject, getObjectText, uploadObject, deleteObject, copyObject, moveObject }
|
||||
}
|
||||
|
||||
+18
-4
@@ -19,17 +19,31 @@ export async function signS3Delete(path: string, accessKey: string, secretKey: s
|
||||
return signS3('DELETE', path, await sha256Hex(''), accessKey, secretKey)
|
||||
}
|
||||
|
||||
async function signS3(method: string, path: string, payloadHash: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||
export async function signS3Copy(path: string, copySource: string, accessKey: string, secretKey: string): Promise<SignedHeaders & { 'x-amz-copy-source': string }> {
|
||||
const headers = await signS3('PUT', path, await sha256Hex(''), accessKey, secretKey, { 'x-amz-copy-source': encodeCanonicalPath(copySource) })
|
||||
return { ...headers, 'x-amz-copy-source': encodeCanonicalPath(copySource) }
|
||||
}
|
||||
|
||||
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> = {
|
||||
...extraHeaders,
|
||||
'x-amz-content-sha256': payloadHash,
|
||||
'x-amz-date': amzDate,
|
||||
}
|
||||
const signedHeaders = Object.keys(signedHeaderValues).join(';')
|
||||
const canonicalHeaders = Object.entries(signedHeaderValues)
|
||||
.map(([name, value]) => `${name}:${value}\n`)
|
||||
const sortedHeaderNames = Object.keys(signedHeaderValues).sort()
|
||||
const signedHeaders = sortedHeaderNames.join(';')
|
||||
const canonicalHeaders = sortedHeaderNames
|
||||
.map((name) => `${name}:${signedHeaderValues[name]}\n`)
|
||||
.join('')
|
||||
|
||||
const canonicalRequest = [method, encodeCanonicalPath(path), '', canonicalHeaders, signedHeaders, payloadHash].join('\n')
|
||||
|
||||
Reference in New Issue
Block a user