✨ Add audit log CSV download #6
+30
-4
@@ -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>
|
||||||
|
|
||||||
@@ -81,6 +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 { 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' })
|
||||||
@@ -88,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 } = useS3Client()
|
const { listBuckets, listObjects, downloadAuditLogs } = useS3Client()
|
||||||
|
|
||||||
const buckets = ref<S3Bucket[]>([])
|
const buckets = ref<S3Bucket[]>([])
|
||||||
const objects = ref<S3Object[]>([])
|
const objects = ref<S3Object[]>([])
|
||||||
@@ -99,6 +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 downloadingAuditLogs = ref(false)
|
||||||
|
|
||||||
const filteredObjects = computed(() => {
|
const filteredObjects = computed(() => {
|
||||||
if (!search.value) {
|
if (!search.value) {
|
||||||
@@ -141,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.`)
|
||||||
|
|||||||
@@ -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,5 +49,5 @@ 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 }
|
return { listBuckets, listObjects, downloadObject, downloadAuditLogs, getObjectText, uploadObject, deleteObject }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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