Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bbda8d24e |
+30
-39
@@ -7,9 +7,20 @@
|
|||||||
<span class="material-symbols-outlined text-accent">storage</span>
|
<span class="material-symbols-outlined text-accent">storage</span>
|
||||||
<span class="text-sm font-semibold tracking-[0.04em]">r9t</span>
|
<span class="text-sm font-semibold tracking-[0.04em]">r9t</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2 rounded-full border border-border bg-surface-raised px-3 py-1 text-xs text-muted">
|
<div class="flex items-center gap-2">
|
||||||
<span class="material-symbols-outlined !text-[15px]">vpn_key</span>
|
<button
|
||||||
<span class="font-mono">{{ accessKey }}</span>
|
type="button"
|
||||||
|
class="flex items-center gap-1.5 rounded-md border border-border bg-surface-raised px-3 py-1.5 text-xs text-muted transition-colors hover:text-text disabled:opacity-60"
|
||||||
|
:disabled="downloadingAuditLogs"
|
||||||
|
@click="downloadAuditLogCsv"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[16px]" :class="{ 'animate-spin': downloadingAuditLogs }">{{ downloadingAuditLogs ? 'progress_activity' : 'download' }}</span>
|
||||||
|
Audit Logs (CSV)
|
||||||
|
</button>
|
||||||
|
<div class="flex items-center gap-2 rounded-full border border-border bg-surface-raised px-3 py-1 text-xs text-muted">
|
||||||
|
<span class="material-symbols-outlined !text-[15px]">vpn_key</span>
|
||||||
|
<span class="font-mono">{{ accessKey }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -53,7 +64,6 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ObjectTable
|
<ObjectTable
|
||||||
ref="objectTableRef"
|
|
||||||
:objects="filteredObjects"
|
:objects="filteredObjects"
|
||||||
:loading="loadingObjects"
|
:loading="loadingObjects"
|
||||||
:has-search="search.length > 0"
|
:has-search="search.length > 0"
|
||||||
@@ -62,7 +72,6 @@
|
|||||||
@select="selectedObject = $event"
|
@select="selectedObject = $event"
|
||||||
@upload="openUploadPopup"
|
@upload="openUploadPopup"
|
||||||
@retry="retryLoadObjects"
|
@retry="retryLoadObjects"
|
||||||
@bulk-delete="openBulkDeletePopup"
|
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -83,7 +92,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 ConfirmPopup, { type ConfirmPayload } from '~/components/popup/ConfirmPopup.vue'
|
import { saveBlob } from '~/utils/download'
|
||||||
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
useHead({ title: 'r9t · Object Storage' })
|
useHead({ title: 'r9t · Object Storage' })
|
||||||
@@ -91,7 +100,7 @@ useHead({ title: 'r9t · Object Storage' })
|
|||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const accessKey = config.public.s3AccessKey
|
const accessKey = config.public.s3AccessKey
|
||||||
|
|
||||||
const { listBuckets, listObjects, deleteObjects } = useS3Client()
|
const { listBuckets, listObjects, downloadAuditLogs } = useS3Client()
|
||||||
|
|
||||||
const buckets = ref<S3Bucket[]>([])
|
const buckets = ref<S3Bucket[]>([])
|
||||||
const objects = ref<S3Object[]>([])
|
const objects = ref<S3Object[]>([])
|
||||||
@@ -102,7 +111,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 objectTableRef = ref<{ clearSelection: () => void } | null>(null)
|
const downloadingAuditLogs = ref(false)
|
||||||
|
|
||||||
const filteredObjects = computed(() => {
|
const filteredObjects = computed(() => {
|
||||||
if (!search.value) {
|
if (!search.value) {
|
||||||
@@ -134,37 +143,6 @@ function handleObjectDeleted() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openBulkDeletePopup(objectsToDelete: S3Object[]) {
|
|
||||||
if (!selectedBucket.value || !objectsToDelete.length) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const bucket = selectedBucket.value
|
|
||||||
const keys = objectsToDelete.map((object) => object.key)
|
|
||||||
|
|
||||||
usePopup().open(
|
|
||||||
Popup.component<ConfirmPayload>(ConfirmPopup)
|
|
||||||
.setConfig({ heading: `${keys.length} Objekte löschen`, size: PopupSize.SMALL, closeOnOverlayClick: true, callback: () => handleBulkDeleted(bucket, keys) })
|
|
||||||
.setPayload({
|
|
||||||
message: `${keys.length} ausgewählte Objekte werden unwiderruflich aus "${bucket}" gelöscht.`,
|
|
||||||
confirmLabel: 'Löschen',
|
|
||||||
onConfirm: async () => {
|
|
||||||
const { failed } = await deleteObjects(bucket, keys)
|
|
||||||
if (failed.length) {
|
|
||||||
throw new Error(`${failed.length} von ${keys.length} Objekten konnten nicht gelöscht werden.`)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBulkDeleted(bucket: string, keys: string[]) {
|
|
||||||
objectTableRef.value?.clearSelection()
|
|
||||||
notify(`${keys.length} Objekte gelöscht.`)
|
|
||||||
if (selectedBucket.value === bucket) {
|
|
||||||
loadObjects(bucket)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openUploadPopup() {
|
function openUploadPopup() {
|
||||||
if (!selectedBucket.value) {
|
if (!selectedBucket.value) {
|
||||||
return
|
return
|
||||||
@@ -176,6 +154,19 @@ function openUploadPopup() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadAuditLogCsv() {
|
||||||
|
downloadingAuditLogs.value = true
|
||||||
|
try {
|
||||||
|
saveBlob(await downloadAuditLogs(), 'audit-logs.csv')
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
notify('Audit Logs konnten nicht heruntergeladen werden.')
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
downloadingAuditLogs.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadBuckets() {
|
async function loadBuckets() {
|
||||||
errorMessage.value = null
|
errorMessage.value = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -84,6 +84,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { partCount, formatBytes, formatDateTime, baseName } from '~/utils/format'
|
import { partCount, formatBytes, formatDateTime, baseName } from '~/utils/format'
|
||||||
|
import { saveBlob } from '~/utils/download'
|
||||||
import { Popup, PopupSize } from '~/utils/popup'
|
import { Popup, PopupSize } from '~/utils/popup'
|
||||||
import TextPreviewPopup from '~/components/popup/TextPreviewPopup.vue'
|
import TextPreviewPopup from '~/components/popup/TextPreviewPopup.vue'
|
||||||
import ConfirmPopup, { type ConfirmPayload } from '~/components/popup/ConfirmPopup.vue'
|
import ConfirmPopup, { type ConfirmPayload } from '~/components/popup/ConfirmPopup.vue'
|
||||||
@@ -130,13 +131,7 @@ async function download() {
|
|||||||
}
|
}
|
||||||
downloading.value = true
|
downloading.value = true
|
||||||
try {
|
try {
|
||||||
const blob = await downloadObject(props.bucket, props.object.key)
|
saveBlob(await downloadObject(props.bucket, props.object.key), baseName(props.object.key))
|
||||||
const url = URL.createObjectURL(blob)
|
|
||||||
const link = document.createElement('a')
|
|
||||||
link.href = url
|
|
||||||
link.download = baseName(props.object.key)
|
|
||||||
link.click()
|
|
||||||
URL.revokeObjectURL(url)
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
emit('error', `${baseName(props.object.key)} konnte nicht heruntergeladen werden.`)
|
emit('error', `${baseName(props.object.key)} konnte nicht heruntergeladen werden.`)
|
||||||
|
|||||||
@@ -1,41 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex-1 overflow-auto">
|
<div class="flex-1 overflow-auto">
|
||||||
<div
|
|
||||||
v-if="selected.size"
|
|
||||||
class="sticky top-0 z-10 flex items-center justify-between gap-3 border-b border-border bg-surface px-4 py-2 text-sm"
|
|
||||||
>
|
|
||||||
<span class="text-text">{{ selected.size }} ausgewählt</span>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="rounded-md border border-border px-2.5 py-1 text-xs font-medium text-text transition-colors hover:bg-surface-raised"
|
|
||||||
@click="clearSelection"
|
|
||||||
>
|
|
||||||
Auswahl aufheben
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="flex items-center gap-1.5 rounded-md bg-red-500 px-3 py-1.5 text-xs font-medium text-white transition-opacity hover:opacity-90"
|
|
||||||
@click="$emit('bulk-delete', selectedObjects)"
|
|
||||||
>
|
|
||||||
<span class="material-symbols-outlined !text-[16px]">delete</span>
|
|
||||||
Löschen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<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-3.5 cursor-pointer accent-accent"
|
|
||||||
:checked="allSelected"
|
|
||||||
:disabled="!sortedObjects.length"
|
|
||||||
@change="toggleSelectAll"
|
|
||||||
>
|
|
||||||
</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>
|
||||||
@@ -50,7 +17,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="4">
|
<td class="px-4 py-3" colspan="3">
|
||||||
<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>
|
||||||
@@ -60,17 +27,8 @@
|
|||||||
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-surface-raised/50': selected.has(object.key) }"
|
|
||||||
@click="$emit('select', object)"
|
@click="$emit('select', object)"
|
||||||
>
|
>
|
||||||
<td class="px-4 py-[5px]" @click.stop>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
class="size-3.5 cursor-pointer accent-accent"
|
|
||||||
:checked="selected.has(object.key)"
|
|
||||||
@change="toggleSelected(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" />
|
||||||
@@ -128,7 +86,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
|
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
|
||||||
import type { S3Object } from '~/utils/s3xml'
|
import type { S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
@@ -139,49 +97,10 @@ const props = defineProps<{
|
|||||||
searchTerm: string
|
searchTerm: string
|
||||||
error?: string | null
|
error?: string | null
|
||||||
}>()
|
}>()
|
||||||
defineEmits<{ select: [object: S3Object]; upload: []; retry: []; 'bulk-delete': [objects: S3Object[]] }>()
|
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
|
||||||
|
|
||||||
type SortKey = 'key' | 'size' | 'lastModified'
|
type SortKey = 'key' | 'size' | 'lastModified'
|
||||||
|
|
||||||
const selected = ref<Set<string>>(new Set())
|
|
||||||
|
|
||||||
const selectedObjects = computed(() => props.objects.filter((object) => selected.value.has(object.key)))
|
|
||||||
|
|
||||||
const allSelected = computed(() => sortedObjects.value.length > 0 && sortedObjects.value.every((object) => selected.value.has(object.key)))
|
|
||||||
|
|
||||||
function toggleSelected(key: string) {
|
|
||||||
const next = new Set(selected.value)
|
|
||||||
if (next.has(key)) {
|
|
||||||
next.delete(key)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
next.add(key)
|
|
||||||
}
|
|
||||||
selected.value = next
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleSelectAll() {
|
|
||||||
if (allSelected.value) {
|
|
||||||
selected.value = new Set()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
selected.value = new Set(sortedObjects.value.map((object) => object.key))
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearSelection() {
|
|
||||||
selected.value = new Set()
|
|
||||||
}
|
|
||||||
|
|
||||||
defineExpose({ clearSelection })
|
|
||||||
|
|
||||||
watch(() => props.objects, (objects) => {
|
|
||||||
const keys = new Set(objects.map((object) => object.key))
|
|
||||||
const next = new Set([...selected.value].filter((key) => keys.has(key)))
|
|
||||||
if (next.size !== selected.value.size) {
|
|
||||||
selected.value = next
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const sortKey = ref<SortKey>('lastModified')
|
const sortKey = ref<SortKey>('lastModified')
|
||||||
const sortDir = ref<'asc' | 'desc'>('desc')
|
const sortDir = ref<'asc' | 'desc'>('desc')
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ export function useS3Client() {
|
|||||||
return $fetch<Blob>(`/api${encodeCanonicalPath(path)}`, { headers, responseType: 'blob' })
|
return $fetch<Blob>(`/api${encodeCanonicalPath(path)}`, { headers, responseType: 'blob' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function downloadAuditLogs(): Promise<Blob> {
|
||||||
|
const path = '/_audit-logs/csv'
|
||||||
|
const headers = await signS3Get(path, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||||
|
return $fetch<Blob>(`/api${path}`, { headers, responseType: 'blob' })
|
||||||
|
}
|
||||||
|
|
||||||
async function getObjectText(bucket: string, key: string): Promise<string> {
|
async function getObjectText(bucket: string, key: string): Promise<string> {
|
||||||
return get(`/${bucket}/${key}`)
|
return get(`/${bucket}/${key}`)
|
||||||
}
|
}
|
||||||
@@ -43,28 +49,5 @@ export function useS3Client() {
|
|||||||
await $fetch(`/api${encodeCanonicalPath(path)}`, { method: 'DELETE', headers })
|
await $fetch(`/api${encodeCanonicalPath(path)}`, { method: 'DELETE', headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BulkDeleteResult {
|
return { listBuckets, listObjects, downloadObject, downloadAuditLogs, getObjectText, uploadObject, deleteObject }
|
||||||
deleted: string[]
|
|
||||||
failed: { key: string; error: unknown }[]
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteObjects(bucket: string, keys: string[]): Promise<BulkDeleteResult> {
|
|
||||||
const results = await Promise.allSettled(keys.map((key) => deleteObject(bucket, key)))
|
|
||||||
|
|
||||||
const deleted: string[] = []
|
|
||||||
const failed: { key: string; error: unknown }[] = []
|
|
||||||
results.forEach((result, index) => {
|
|
||||||
const key = keys[index]!
|
|
||||||
if (result.status === 'fulfilled') {
|
|
||||||
deleted.push(key)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
failed.push({ key, error: result.reason })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return { deleted, failed }
|
|
||||||
}
|
|
||||||
|
|
||||||
return { listBuckets, listObjects, downloadObject, getObjectText, uploadObject, deleteObject, deleteObjects }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export function saveBlob(blob: Blob, fileName: string) {
|
||||||
|
const url = URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = fileName
|
||||||
|
link.click()
|
||||||
|
URL.revokeObjectURL(url)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user