🎉 Init
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
NUXT_PUBLIC_S3_ACCESS_KEY=devkey
|
||||||
|
NUXT_PUBLIC_S3_SECRET_KEY=devsecret
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# Nuxt dev/build outputs
|
||||||
|
.output
|
||||||
|
.data
|
||||||
|
.nuxt
|
||||||
|
.nitro
|
||||||
|
.cache
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Node dependencies
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
.fleet
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Local env files
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
FROM node:22.9.0-alpine
|
||||||
|
|
||||||
|
WORKDIR /usr/app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
RUN npx nuxi cleanup
|
||||||
|
|
||||||
|
RUN npx nuxi build
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["node", ".output/server/index.mjs"]
|
||||||
Vendored
+38
@@ -0,0 +1,38 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Set Image Name') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
env.IMAGE = "harbor.dinauer.dev/r9t/frontend:${env.BUILD_NUMBER}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Build Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
sh "docker build --no-cache -t ${env.IMAGE} --build-arg VERSION=${env.BUILD_NUMBER} ."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Push Image to Docker Hub') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'harbor', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||||
|
sh 'echo ${PASSWORD} | docker login harbor.dinauer.dev -u ${USERNAME} --password-stdin'
|
||||||
|
sh "docker push ${env.IMAGE}"
|
||||||
|
sh "docker logout harbor.dinauer.dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Remove image from host') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
sh "docker image rm --force ${env.IMAGE}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# Nuxt Minimal Starter
|
||||||
|
|
||||||
|
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Make sure to install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn install
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Server
|
||||||
|
|
||||||
|
Start the development server on `http://localhost:3000`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm dev
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn dev
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Production
|
||||||
|
|
||||||
|
Build the application for production:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm build
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn build
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Locally preview production build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run preview
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm preview
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn preview
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run preview
|
||||||
|
```
|
||||||
|
|
||||||
|
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
|
||||||
+185
@@ -0,0 +1,185 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex h-screen flex-col bg-bg text-text">
|
||||||
|
<NuxtRouteAnnouncer />
|
||||||
|
|
||||||
|
<header class="flex h-14 shrink-0 items-center justify-between border-b border-border bg-surface px-4">
|
||||||
|
<div class="flex items-center gap-2.5">
|
||||||
|
<span class="material-symbols-outlined text-accent">storage</span>
|
||||||
|
<span class="text-sm font-semibold tracking-[0.04em]">r9t</span>
|
||||||
|
</div>
|
||||||
|
<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>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="flex min-h-0 flex-1">
|
||||||
|
<BucketList :buckets="buckets" :selected="selectedBucket" @select="selectBucket" @create="mockAction" />
|
||||||
|
|
||||||
|
<main class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<div class="flex shrink-0 items-center justify-between gap-4 border-b border-border px-5 py-3.5">
|
||||||
|
<div class="flex items-center gap-1.5 text-sm">
|
||||||
|
<span class="text-muted">Bucket</span>
|
||||||
|
<span class="material-symbols-outlined !text-[16px] text-muted">chevron_right</span>
|
||||||
|
<span class="font-medium">{{ selectedBucket ?? '–' }}</span>
|
||||||
|
<span v-if="selectedBucket" class="ml-1 rounded-full bg-surface-raised px-2 py-0.5 text-xs text-muted">
|
||||||
|
{{ objects.length }} Objekte
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<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>
|
||||||
|
<input
|
||||||
|
v-model="search"
|
||||||
|
type="text"
|
||||||
|
placeholder="Key filtern…"
|
||||||
|
class="w-40 bg-transparent text-sm text-text placeholder:text-muted focus:outline-none"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<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="openUploadPopup"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">upload</span>
|
||||||
|
Hochladen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="errorMessage" class="shrink-0 border-b border-border bg-surface px-5 py-2 text-sm text-accent">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ObjectTable
|
||||||
|
:objects="filteredObjects"
|
||||||
|
:loading="loadingObjects"
|
||||||
|
:has-search="search.length > 0"
|
||||||
|
:search-term="search"
|
||||||
|
:error="objectsError"
|
||||||
|
@select="selectedObject = $event"
|
||||||
|
@upload="openUploadPopup"
|
||||||
|
@retry="retryLoadObjects"
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<ObjectDetail
|
||||||
|
:object="selectedObject"
|
||||||
|
:bucket="selectedBucket ?? ''"
|
||||||
|
@close="selectedObject = null"
|
||||||
|
@error="notify"
|
||||||
|
@deleted="handleObjectDeleted"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<AppToast :message="toastMessage" />
|
||||||
|
<PopupSlot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch, onMounted } from 'vue'
|
||||||
|
import { Popup, PopupSize } from '~/utils/popup'
|
||||||
|
import UploadPopup from '~/components/popup/UploadPopup.vue'
|
||||||
|
import type { S3Bucket, S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
|
useHead({ title: 'r9t · Object Storage' })
|
||||||
|
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const accessKey = config.public.s3AccessKey
|
||||||
|
|
||||||
|
const { listBuckets, listObjects } = useS3Client()
|
||||||
|
|
||||||
|
const buckets = ref<S3Bucket[]>([])
|
||||||
|
const objects = ref<S3Object[]>([])
|
||||||
|
const selectedBucket = ref<string | null>(null)
|
||||||
|
const selectedObject = ref<S3Object | null>(null)
|
||||||
|
const search = ref('')
|
||||||
|
const loadingObjects = ref(false)
|
||||||
|
const errorMessage = ref<string | null>(null)
|
||||||
|
const objectsError = ref<string | null>(null)
|
||||||
|
const toastMessage = ref<string | null>(null)
|
||||||
|
|
||||||
|
const filteredObjects = computed(() => {
|
||||||
|
if (!search.value) {
|
||||||
|
return objects.value
|
||||||
|
}
|
||||||
|
const needle = search.value.toLowerCase()
|
||||||
|
return objects.value.filter((object) => object.key.toLowerCase().includes(needle))
|
||||||
|
})
|
||||||
|
|
||||||
|
function selectBucket(name: string) {
|
||||||
|
selectedBucket.value = name
|
||||||
|
selectedObject.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function notify(message: string) {
|
||||||
|
toastMessage.value = message
|
||||||
|
setTimeout(() => { toastMessage.value = null }, 2500)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockAction() {
|
||||||
|
notify('Noch nicht verdrahtet — nur Lesezugriff in diesem UI.')
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleObjectDeleted() {
|
||||||
|
selectedObject.value = null
|
||||||
|
notify('Objekt gelöscht.')
|
||||||
|
if (selectedBucket.value) {
|
||||||
|
loadObjects(selectedBucket.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openUploadPopup() {
|
||||||
|
if (!selectedBucket.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
usePopup().open(
|
||||||
|
Popup.component(UploadPopup)
|
||||||
|
.setConfig({ heading: 'Hochladen', size: PopupSize.MEDIUM, closeOnOverlayClick: false, callback: () => loadObjects(selectedBucket.value!) })
|
||||||
|
.setPayload({ bucket: selectedBucket.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadBuckets() {
|
||||||
|
errorMessage.value = null
|
||||||
|
try {
|
||||||
|
buckets.value = await listBuckets()
|
||||||
|
if (buckets.value.length && !selectedBucket.value) {
|
||||||
|
selectBucket(buckets.value[0]!.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
errorMessage.value = 'Buckets konnten nicht geladen werden. Läuft der Server auf Port 8080?'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadObjects(bucket: string) {
|
||||||
|
loadingObjects.value = true
|
||||||
|
objectsError.value = null
|
||||||
|
try {
|
||||||
|
objects.value = await listObjects(bucket)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
objectsError.value = `Objekte für "${bucket}" konnten nicht geladen werden.`
|
||||||
|
objects.value = []
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loadingObjects.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function retryLoadObjects() {
|
||||||
|
if (selectedBucket.value) {
|
||||||
|
loadObjects(selectedBucket.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(selectedBucket, (bucket) => {
|
||||||
|
if (bucket) {
|
||||||
|
loadObjects(bucket)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(loadBuckets)
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap');
|
||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
@theme {
|
||||||
|
--color-bg: #ffffff;
|
||||||
|
--color-surface: #f7f5f2;
|
||||||
|
--color-surface-raised: #efebe4;
|
||||||
|
--color-border: #e3ded5;
|
||||||
|
--color-text: #1d1b18;
|
||||||
|
--color-muted: #6f6a62;
|
||||||
|
--color-accent: #ea580c;
|
||||||
|
--color-accent-dim: #fbdcc4;
|
||||||
|
|
||||||
|
--font-sans: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
|
||||||
|
--font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-symbols-outlined {
|
||||||
|
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1;
|
||||||
|
vertical-align: middle;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
color: var(--color-text);
|
||||||
|
font-family: var(--font-sans);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
::selection {
|
||||||
|
background-color: var(--color-accent-dim);
|
||||||
|
color: var(--color-text);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<Transition
|
||||||
|
enter-active-class="transition duration-200 ease-out"
|
||||||
|
enter-from-class="translate-y-2 opacity-0"
|
||||||
|
enter-to-class="translate-y-0 opacity-100"
|
||||||
|
leave-active-class="transition duration-150 ease-in"
|
||||||
|
leave-from-class="translate-y-0 opacity-100"
|
||||||
|
leave-to-class="translate-y-2 opacity-0"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-if="message"
|
||||||
|
class="fixed bottom-6 left-1/2 z-50 flex -translate-x-1/2 items-center gap-2 rounded-lg border border-border bg-surface-raised px-4 py-2.5 text-sm text-text shadow-lg shadow-black/40"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined text-accent">info</span>
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{ message: string | null }>()
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<aside class="flex w-60 shrink-0 flex-col border-r border-border bg-surface">
|
||||||
|
<div class="flex items-center justify-between px-4 pb-2 pt-5">
|
||||||
|
<span class="text-xs font-semibold tracking-[0.14em] text-muted">BUCKETS</span>
|
||||||
|
<span class="rounded-full bg-surface-raised px-2 py-0.5 text-[11px] font-semibold text-muted">
|
||||||
|
{{ buckets.length }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar-scroll flex-1 space-y-0.5 overflow-y-auto px-2.5 pt-1">
|
||||||
|
<button
|
||||||
|
v-for="bucket in buckets"
|
||||||
|
:key="bucket.name"
|
||||||
|
type="button"
|
||||||
|
class="group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-sm transition-all duration-150"
|
||||||
|
:class="bucket.name === selected
|
||||||
|
? 'bg-accent-dim text-text shadow-[inset_0_0_0_1px_rgba(234,88,12,0.25)]'
|
||||||
|
: 'text-muted hover:translate-x-0.5 hover:bg-surface-raised hover:text-text'"
|
||||||
|
@click="$emit('select', bucket.name)"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="flex size-6 shrink-0 items-center justify-center rounded-md transition-colors"
|
||||||
|
:class="bucket.name === selected ? 'bg-accent text-white' : 'bg-surface-raised text-muted group-hover:text-text'"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[15px]">folder</span>
|
||||||
|
</span>
|
||||||
|
<span class="truncate font-medium">{{ bucket.name }}</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<p v-if="!buckets.length" class="px-2.5 py-2 text-sm text-muted">
|
||||||
|
Keine Buckets gefunden.
|
||||||
|
</p>
|
||||||
|
</nav>
|
||||||
|
<div class="mx-2.5 mb-3 mt-2 border-t border-dashed border-border pt-2.5">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center gap-2 rounded-lg border border-dashed border-border px-2.5 py-2 text-sm text-muted transition-colors hover:border-accent hover:text-accent"
|
||||||
|
@click="$emit('create')"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">add</span>
|
||||||
|
Bucket
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { S3Bucket } from '~/utils/s3xml'
|
||||||
|
|
||||||
|
defineProps<{ buckets: S3Bucket[]; selected: string | null }>()
|
||||||
|
defineEmits<{ select: [name: string]; create: [] }>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.sidebar-scroll::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-scroll::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--color-border);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-scroll::-webkit-scrollbar-track {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex items-center gap-2" :title="`${parts} part${parts === 1 ? '' : 's'}`">
|
||||||
|
<div class="flex h-2 w-16 gap-[2px]">
|
||||||
|
<div
|
||||||
|
v-for="n in parts"
|
||||||
|
:key="n"
|
||||||
|
class="flex-1 rounded-[1px] bg-accent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span class="font-mono text-[11px] tabular-nums text-muted">{{ parts }}×</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{ parts: number }>()
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<FieldLabel>{{ label }}</FieldLabel>
|
||||||
|
<div class="mt-1 flex items-center gap-2">
|
||||||
|
<p class="break-all font-mono text-sm text-text">{{ value }}</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 text-muted transition-colors hover:text-accent"
|
||||||
|
:title="`${label} kopieren`"
|
||||||
|
@click="copy"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[16px]">{{ copied ? 'check' : 'content_copy' }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ label: string; value: string }>()
|
||||||
|
const copied = ref(false)
|
||||||
|
|
||||||
|
async function copy() {
|
||||||
|
await navigator.clipboard.writeText(props.value)
|
||||||
|
copied.value = true
|
||||||
|
setTimeout(() => { copied.value = false }, 1500)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<p class="text-xs font-semibold tracking-[0.1em] text-muted">
|
||||||
|
<slot />
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<template>
|
||||||
|
<div class="badge-halo" :style="{ '--hue': fileType.hue, '--sat': fileType.sat + '%' }">
|
||||||
|
<span class="badge-mark">
|
||||||
|
<svg class="badge-mark-shape" viewBox="0 -960 960 960">
|
||||||
|
<path d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640v400q0 33-23.5 56.5T800-160H160Z" />
|
||||||
|
</svg>
|
||||||
|
<span class="badge-letter">{{ fileType.letter }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ filename: string }>()
|
||||||
|
|
||||||
|
interface FileType {
|
||||||
|
letter: string
|
||||||
|
hue: number
|
||||||
|
sat: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const FILE_TYPES: Record<string, FileType> = {
|
||||||
|
zip: { letter: 'Z', hue: 275, sat: 68 },
|
||||||
|
yaml: { letter: 'Y', hue: 175, sat: 62 },
|
||||||
|
yml: { letter: 'Y', hue: 175, sat: 62 },
|
||||||
|
json: { letter: 'J', hue: 42, sat: 78 },
|
||||||
|
txt: { letter: 'T', hue: 220, sat: 10 },
|
||||||
|
csv: { letter: 'C', hue: 145, sat: 55 },
|
||||||
|
log: { letter: 'L', hue: 210, sat: 65 },
|
||||||
|
md: { letter: 'M', hue: 255, sat: 55 },
|
||||||
|
sql: { letter: 'S', hue: 330, sat: 60 },
|
||||||
|
pdf: { letter: 'P', hue: 5, sat: 68 },
|
||||||
|
enc: { letter: 'E', hue: 25, sat: 88 },
|
||||||
|
}
|
||||||
|
|
||||||
|
const FALLBACK_HUE = 220
|
||||||
|
const FALLBACK_SAT = 8
|
||||||
|
|
||||||
|
const fileType = computed<FileType>(() => {
|
||||||
|
const dotIndex = props.filename.lastIndexOf('.')
|
||||||
|
const extension = dotIndex === -1 ? '' : props.filename.slice(dotIndex + 1).toLowerCase()
|
||||||
|
const known = FILE_TYPES[extension]
|
||||||
|
if (known) {
|
||||||
|
return known
|
||||||
|
}
|
||||||
|
if (!extension) {
|
||||||
|
return { letter: '·', hue: FALLBACK_HUE, sat: FALLBACK_SAT }
|
||||||
|
}
|
||||||
|
return { letter: extension[0]!.toUpperCase(), hue: FALLBACK_HUE, sat: FALLBACK_SAT }
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.badge-halo {
|
||||||
|
width: 34px;
|
||||||
|
height: 34px;
|
||||||
|
border-radius: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex: none;
|
||||||
|
background: hsl(var(--hue) var(--sat) 50% / 14%);
|
||||||
|
border: 1.5px solid hsl(var(--hue) var(--sat) 46% / 40%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-mark {
|
||||||
|
position: relative;
|
||||||
|
width: 27px;
|
||||||
|
height: 27px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-mark-shape {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
filter: drop-shadow(0 1px 1.5px hsl(var(--hue) var(--sat) 30% / 45%));
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-mark-shape path {
|
||||||
|
fill: hsl(var(--hue) calc(var(--sat) * 0.45) 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-letter {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding-top: 5.5px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<template>
|
||||||
|
<aside
|
||||||
|
v-if="object"
|
||||||
|
class="flex h-full w-96 shrink-0 flex-col border-l border-border bg-surface"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between border-b border-border px-5 py-4">
|
||||||
|
<h2 class="text-sm font-semibold tracking-[0.06em] text-muted">OBJEKT</h2>
|
||||||
|
<button type="button" class="text-muted transition-colors hover:text-text" @click="$emit('close')">
|
||||||
|
<span class="material-symbols-outlined">close</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1 space-y-6 overflow-y-auto px-5 py-5">
|
||||||
|
<div>
|
||||||
|
<FieldLabel>Bucket</FieldLabel>
|
||||||
|
<p class="mt-1 font-mono text-sm text-text">{{ bucket }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<FieldLabel>Objekt</FieldLabel>
|
||||||
|
<p class="mt-1 break-all font-mono text-sm text-text">{{ object.key }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<FieldLabel>Chunks</FieldLabel>
|
||||||
|
<div class="mt-2 flex items-center gap-3">
|
||||||
|
<ChunkBar :parts="partCount(object.etag)" />
|
||||||
|
<span class="text-sm text-muted">
|
||||||
|
{{ partCount(object.etag) === 1 ? 'Single-Part-Upload' : `Multipart-Upload, ${partCount(object.etag)} Teile` }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<FieldLabel>Größe</FieldLabel>
|
||||||
|
<p class="mt-1 font-mono text-sm text-text">
|
||||||
|
{{ formatBytes(object.size) }} <span class="text-muted">· {{ object.size.toLocaleString('de-DE') }} Bytes</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<FieldLabel>Zuletzt geändert</FieldLabel>
|
||||||
|
<p class="mt-1 font-mono text-sm text-text">{{ formatDateTime(object.lastModified) }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CopyField label="S3-URI" :value="`s3://${bucket}/${object.key}`" />
|
||||||
|
<CopyField label="ETag" :value="object.etag" />
|
||||||
|
|
||||||
|
<div class="border-t border-border pt-6">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center justify-center gap-2 rounded-md bg-red-500 px-3 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90"
|
||||||
|
@click="confirmDelete"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">delete</span>
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex shrink-0 gap-2 border-t border-border px-5 py-4">
|
||||||
|
<button
|
||||||
|
v-if="isTextFile"
|
||||||
|
type="button"
|
||||||
|
class="flex flex-1 items-center justify-center gap-2 rounded-md border border-border px-3 py-2 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
|
||||||
|
@click="openPreview"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">visibility</span>
|
||||||
|
Anzeigen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex flex-1 items-center justify-center gap-2 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
|
||||||
|
:disabled="downloading"
|
||||||
|
@click="download"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': downloading }">{{ downloading ? 'progress_activity' : 'download' }}</span>
|
||||||
|
{{ downloading ? 'Lädt herunter…' : 'Herunterladen' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { partCount, formatBytes, formatDateTime, baseName } from '~/utils/format'
|
||||||
|
import { Popup, PopupSize } from '~/utils/popup'
|
||||||
|
import TextPreviewPopup from '~/components/popup/TextPreviewPopup.vue'
|
||||||
|
import ConfirmPopup, { type ConfirmPayload } from '~/components/popup/ConfirmPopup.vue'
|
||||||
|
import type { S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
|
const props = defineProps<{ object: S3Object | null; bucket: string }>()
|
||||||
|
const emit = defineEmits<{ close: []; error: [message: string]; deleted: [] }>()
|
||||||
|
|
||||||
|
const { downloadObject, deleteObject } = useS3Client()
|
||||||
|
const downloading = ref(false)
|
||||||
|
|
||||||
|
const isTextFile = computed(() => props.object?.key.toLowerCase().endsWith('.txt') ?? false)
|
||||||
|
|
||||||
|
function openPreview() {
|
||||||
|
if (!props.object) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
usePopup().open(
|
||||||
|
Popup.component(TextPreviewPopup)
|
||||||
|
.setConfig({ heading: baseName(props.object.key), size: PopupSize.MEDIUM, closeOnOverlayClick: true })
|
||||||
|
.setPayload({ bucket: props.bucket, key: props.object.key }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmDelete() {
|
||||||
|
if (!props.object) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const key = props.object.key
|
||||||
|
usePopup().open(
|
||||||
|
Popup.component<ConfirmPayload>(ConfirmPopup)
|
||||||
|
.setConfig({ heading: 'Objekt löschen', size: PopupSize.SMALL, closeOnOverlayClick: true, callback: () => emit('deleted') })
|
||||||
|
.setPayload({
|
||||||
|
message: `"${key}" wird unwiderruflich aus "${props.bucket}" gelöscht.`,
|
||||||
|
confirmLabel: 'Löschen',
|
||||||
|
onConfirm: () => deleteObject(props.bucket, key),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function download() {
|
||||||
|
if (!props.object) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
downloading.value = true
|
||||||
|
try {
|
||||||
|
const blob = await downloadObject(props.bucket, 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 {
|
||||||
|
emit('error', `${baseName(props.object.key)} konnte nicht heruntergeladen werden.`)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
downloading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex-1 overflow-auto">
|
||||||
|
<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="px-4 py-2.5 font-medium">
|
||||||
|
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
<SortHeader :active="sortKey === 'size' ? sortDir : null" @click="toggleSort('size')">SIZE</SortHeader>
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
<SortHeader :active="sortKey === 'lastModified' ? sortDir : null" @click="toggleSort('lastModified')">MODIFIED</SortHeader>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<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">
|
||||||
|
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</template>
|
||||||
|
<tr
|
||||||
|
v-for="object in sortedObjects"
|
||||||
|
v-else
|
||||||
|
:key="object.key"
|
||||||
|
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
|
||||||
|
@click="$emit('select', object)"
|
||||||
|
>
|
||||||
|
<td class="px-4 py-[5px]">
|
||||||
|
<div class="flex items-center gap-2.5">
|
||||||
|
<FileTypeBadge :filename="object.key" />
|
||||||
|
<PathBreadcrumb :path="object.key" />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">{{ formatBytes(object.size) }}</td>
|
||||||
|
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span>{{ formatDate(object.lastModified) }} {{ formatTime(object.lastModified) }}</span>
|
||||||
|
<span
|
||||||
|
v-if="isToday(object.lastModified)"
|
||||||
|
class="rounded bg-surface-raised px-1 py-0.5 font-sans text-[11.5px] font-medium normal-case tracking-normal text-muted"
|
||||||
|
>Heute</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div v-else class="flex h-full flex-col items-center justify-center gap-3 px-6 text-center">
|
||||||
|
<template v-if="error">
|
||||||
|
<span class="material-symbols-outlined !text-[40px] text-accent">error</span>
|
||||||
|
<p class="text-text">Objekte konnten nicht geladen werden</p>
|
||||||
|
<p class="max-w-xs text-sm text-muted">{{ error }}</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="mt-1 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('retry')"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">refresh</span>
|
||||||
|
Erneut versuchen
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span class="material-symbols-outlined !text-[40px] text-muted">{{ hasSearch ? 'search_off' : 'inventory_2' }}</span>
|
||||||
|
<p class="text-text">{{ hasSearch ? 'Keine Treffer' : 'Dieser Bucket ist leer' }}</p>
|
||||||
|
<p class="max-w-xs text-sm text-muted">
|
||||||
|
{{ hasSearch
|
||||||
|
? `Keine Objekte passen zu "${searchTerm}".`
|
||||||
|
: 'Objekte, die du hier hochlädst, tauchen in dieser Liste auf.' }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
v-if="!hasSearch"
|
||||||
|
type="button"
|
||||||
|
class="mt-1 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="$emit('upload')"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]">upload</span>
|
||||||
|
Hochladen
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
|
||||||
|
import type { S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
objects: S3Object[]
|
||||||
|
loading: boolean
|
||||||
|
hasSearch: boolean
|
||||||
|
searchTerm: string
|
||||||
|
error?: string | null
|
||||||
|
}>()
|
||||||
|
defineEmits<{ select: [object: S3Object]; upload: []; retry: [] }>()
|
||||||
|
|
||||||
|
type SortKey = 'key' | 'size' | 'lastModified'
|
||||||
|
|
||||||
|
const sortKey = ref<SortKey>('lastModified')
|
||||||
|
const sortDir = ref<'asc' | 'desc'>('desc')
|
||||||
|
|
||||||
|
function toggleSort(key: SortKey) {
|
||||||
|
if (sortKey.value === key) {
|
||||||
|
sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sortKey.value = key
|
||||||
|
sortDir.value = 'asc'
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedObjects = computed(() => {
|
||||||
|
const factor = sortDir.value === 'asc' ? 1 : -1
|
||||||
|
return [...props.objects].sort((a, b) => {
|
||||||
|
if (sortKey.value === 'key') {
|
||||||
|
return a.key.localeCompare(b.key) * factor
|
||||||
|
}
|
||||||
|
if (sortKey.value === 'size') {
|
||||||
|
return (a.size - b.size) * factor
|
||||||
|
}
|
||||||
|
return (new Date(a.lastModified).getTime() - new Date(b.lastModified).getTime()) * factor
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<template>
|
||||||
|
<span class="truncate">
|
||||||
|
<template v-for="(dir, i) in segments.dirs" :key="i">
|
||||||
|
<span class="text-muted">{{ dir }}</span><span class="mx-1.5 text-[17px] font-semibold text-text">›</span>
|
||||||
|
</template>
|
||||||
|
<span class="font-semibold text-text">{{ segments.file }}</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ path: string }>()
|
||||||
|
|
||||||
|
const segments = computed(() => {
|
||||||
|
const parts = props.path.split('/')
|
||||||
|
const file = parts.pop() ?? props.path
|
||||||
|
return { dirs: parts, file }
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<template>
|
||||||
|
<button type="button" class="inline-flex items-center gap-0.5 transition-colors hover:text-text" @click="$emit('click')">
|
||||||
|
<slot />
|
||||||
|
<span class="flex flex-col">
|
||||||
|
<span
|
||||||
|
class="material-symbols-outlined !text-[18px] leading-[8px]"
|
||||||
|
:class="active === 'asc' ? 'text-accent' : 'text-muted/40'"
|
||||||
|
>arrow_drop_up</span>
|
||||||
|
<span
|
||||||
|
class="material-symbols-outlined !text-[18px] leading-[8px] -mt-2.5"
|
||||||
|
:class="active === 'desc' ? 'text-accent' : 'text-muted/40'"
|
||||||
|
>arrow_drop_down</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{ active: 'asc' | 'desc' | null }>()
|
||||||
|
defineEmits<{ click: [] }>()
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<template>
|
||||||
|
<div class="space-y-5">
|
||||||
|
<p class="text-sm text-text">{{ payload.message }}</p>
|
||||||
|
<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-red-500 px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-wait disabled:opacity-70"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="confirm"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': loading }">
|
||||||
|
{{ loading ? 'progress_activity' : 'delete' }}
|
||||||
|
</span>
|
||||||
|
{{ payload.confirmLabel ?? 'Löschen' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
export interface ConfirmPayload {
|
||||||
|
message: string
|
||||||
|
confirmLabel?: string
|
||||||
|
onConfirm: () => Promise<void> | void
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = usePopup().require<ConfirmPayload>().payload!
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
async function confirm() {
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
await payload.onConfirm()
|
||||||
|
usePopup().callback()
|
||||||
|
usePopup().close()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
error.value = 'Das hat nicht geklappt. Versuch es nochmal.'
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<Transition
|
||||||
|
enter-active-class="transition duration-150 ease-out"
|
||||||
|
enter-from-class="opacity-0"
|
||||||
|
enter-to-class="opacity-100"
|
||||||
|
leave-active-class="transition duration-100 ease-in"
|
||||||
|
leave-from-class="opacity-100"
|
||||||
|
leave-to-class="opacity-0"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-if="popup?.config"
|
||||||
|
class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-[2px]"
|
||||||
|
@click="closeOutside"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex max-h-[calc(100vh-4rem)] w-full flex-col rounded-lg border border-border bg-surface shadow-xl shadow-black/20"
|
||||||
|
:class="sizeClass"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<div class="flex shrink-0 items-center justify-between border-b border-border px-5 py-4">
|
||||||
|
<h2 class="text-sm font-semibold tracking-[0.04em] text-text">{{ popup.config.heading }}</h2>
|
||||||
|
<button type="button" class="text-muted transition-colors hover:text-text" @click="usePopup().close()">
|
||||||
|
<span class="material-symbols-outlined">close</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="min-h-0 flex-1 overflow-y-auto p-5">
|
||||||
|
<component :is="popup.component" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, onUnmounted } from 'vue'
|
||||||
|
import { PopupSize } from '~/utils/popup'
|
||||||
|
|
||||||
|
const popup = computed(() => usePopup().get())
|
||||||
|
|
||||||
|
const sizeClass = computed(() => {
|
||||||
|
switch (popup.value?.config?.size) {
|
||||||
|
case PopupSize.SMALL:
|
||||||
|
return 'max-w-md'
|
||||||
|
case PopupSize.LARGE:
|
||||||
|
return 'max-w-4xl'
|
||||||
|
case PopupSize.FULL:
|
||||||
|
return 'max-w-[calc(100vw-2rem)]'
|
||||||
|
default:
|
||||||
|
return 'max-w-xl'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function closeOutside() {
|
||||||
|
if (popup.value?.config?.closeOnOverlayClick) {
|
||||||
|
usePopup().close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
usePopup().close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => document.addEventListener('keydown', handleKeydown))
|
||||||
|
onUnmounted(() => document.removeEventListener('keydown', handleKeydown))
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="loading" class="h-40 animate-pulse rounded-md bg-surface-raised" />
|
||||||
|
<pre v-else class="whitespace-pre-wrap break-words font-mono text-xs text-text">{{ text }}</pre>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted } from 'vue'
|
||||||
|
|
||||||
|
const payload = usePopup().require<{ bucket: string; key: string }>().payload!
|
||||||
|
const { getObjectText } = useS3Client()
|
||||||
|
|
||||||
|
const loading = ref(true)
|
||||||
|
const text = ref('')
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
text.value = await getObjectText(payload.bucket, payload.key)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
text.value = 'Datei konnte nicht geladen werden.'
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
<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} Datei${queue.length === 1 ? '' : 'en'} fehlgeschlagen`
|
||||||
|
: `${successCount} Datei${successCount === 1 ? '' : 'en'} hochgeladen` }}
|
||||||
|
</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>Zielpfad</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">{{ bucket }}/</span>
|
||||||
|
<input
|
||||||
|
v-model="path"
|
||||||
|
type="text"
|
||||||
|
placeholder="backups/"
|
||||||
|
class="min-w-0 flex-1 bg-transparent text-text placeholder:text-muted/60 focus:outline-none"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="flex flex-col items-center justify-center gap-1.5 rounded-lg border-2 border-dashed px-6 py-10 text-center transition-colors"
|
||||||
|
:class="isDragging ? 'border-accent bg-accent-dim/40' : 'border-border hover:border-muted'"
|
||||||
|
@dragover.prevent="isDragging = true"
|
||||||
|
@dragleave.prevent="isDragging = false"
|
||||||
|
@drop.prevent="handleDrop"
|
||||||
|
@click="fileInput?.click()"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[32px] text-muted">upload_file</span>
|
||||||
|
<p class="text-sm text-text">Dateien hierher ziehen</p>
|
||||||
|
<p class="text-xs text-muted">oder klicken zum Auswählen</p>
|
||||||
|
<input ref="fileInput" type="file" multiple class="hidden" @change="handleFileSelect">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="queue.length" class="max-h-48 space-y-1.5 overflow-y-auto">
|
||||||
|
<div
|
||||||
|
v-for="item in queue"
|
||||||
|
:key="item.id"
|
||||||
|
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>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<p class="truncate font-mono text-xs text-text">{{ normalizedPath }}{{ item.file.name }}</p>
|
||||||
|
<p class="text-[11px] text-muted">{{ formatBytes(item.file.size) }}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
v-if="item.status === 'pending'"
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 text-muted transition-colors hover:text-text"
|
||||||
|
@click="queue = queue.filter((q) => q.id !== item.id)"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[16px]">close</span>
|
||||||
|
</button>
|
||||||
|
</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-accent px-4 py-2 text-sm font-medium text-white transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:disabled="!pendingCount || uploading"
|
||||||
|
@click="startUpload"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined !text-[18px]" :class="{ 'animate-spin': uploading }">
|
||||||
|
{{ uploading ? 'progress_activity' : 'upload' }}
|
||||||
|
</span>
|
||||||
|
{{ uploading ? `Lädt hoch (${doneCount}/${queue.length})…` : `${pendingCount} Datei${pendingCount === 1 ? '' : 'en'} hochladen` }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { formatBytes } from '~/utils/format'
|
||||||
|
|
||||||
|
type Status = 'pending' | 'uploading' | 'done' | 'error'
|
||||||
|
|
||||||
|
interface QueueItem {
|
||||||
|
id: string
|
||||||
|
file: File
|
||||||
|
status: Status
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = usePopup().require<{ bucket: string }>().payload!
|
||||||
|
const bucket = payload.bucket
|
||||||
|
const { uploadObject } = useS3Client()
|
||||||
|
|
||||||
|
const path = ref('')
|
||||||
|
const queue = ref<QueueItem[]>([])
|
||||||
|
const uploading = ref(false)
|
||||||
|
const finished = ref(false)
|
||||||
|
const isDragging = ref(false)
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null)
|
||||||
|
|
||||||
|
const normalizedPath = computed(() => {
|
||||||
|
if (!path.value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return path.value.endsWith('/') ? path.value : `${path.value}/`
|
||||||
|
})
|
||||||
|
|
||||||
|
const pendingCount = computed(() => queue.value.filter((item) => item.status === 'pending').length)
|
||||||
|
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 addFiles(fileList: FileList | null) {
|
||||||
|
if (!fileList) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (const file of Array.from(fileList)) {
|
||||||
|
queue.value.push({ id: `${file.name}-${file.size}-${Math.random().toString(36).slice(2)}`, file, status: 'pending' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDrop(event: DragEvent) {
|
||||||
|
isDragging.value = false
|
||||||
|
addFiles(event.dataTransfer?.files ?? null)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleFileSelect(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
addFiles(input.files)
|
||||||
|
input.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusIcon(status: Status) {
|
||||||
|
if (status === 'uploading') {
|
||||||
|
return 'progress_activity'
|
||||||
|
}
|
||||||
|
if (status === 'done') {
|
||||||
|
return 'check_circle'
|
||||||
|
}
|
||||||
|
if (status === 'error') {
|
||||||
|
return 'error'
|
||||||
|
}
|
||||||
|
return 'draft'
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusIconClass(status: Status) {
|
||||||
|
if (status === 'uploading') {
|
||||||
|
return 'animate-spin text-muted'
|
||||||
|
}
|
||||||
|
if (status === 'done') {
|
||||||
|
return 'text-accent'
|
||||||
|
}
|
||||||
|
if (status === 'error') {
|
||||||
|
return 'text-red-500'
|
||||||
|
}
|
||||||
|
return 'text-muted'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startUpload() {
|
||||||
|
uploading.value = true
|
||||||
|
const pending = queue.value.filter((item) => item.status === 'pending')
|
||||||
|
for (const item of pending) {
|
||||||
|
item.status = 'uploading'
|
||||||
|
try {
|
||||||
|
await uploadObject(bucket, `${normalizedPath.value}${item.file.name}`, item.file)
|
||||||
|
item.status = 'done'
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
item.status = 'error'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uploading.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,38 @@
|
|||||||
|
import { Popup } from '~/utils/popup'
|
||||||
|
|
||||||
|
export function usePopup() {
|
||||||
|
const popup = useState<Popup<any> | undefined>('popup', () => undefined)
|
||||||
|
|
||||||
|
function get<P>(): Popup<P> | undefined {
|
||||||
|
return popup.value as Popup<P> | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function require<P>(): Popup<P> {
|
||||||
|
if (popup.value) {
|
||||||
|
return popup.value as Popup<P>
|
||||||
|
}
|
||||||
|
throw new Error('Expected to be in open popup state.')
|
||||||
|
}
|
||||||
|
|
||||||
|
function open<P>(next: Popup<P>) {
|
||||||
|
popup.value = next
|
||||||
|
setBodyScrolling(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
function callback(payload?: unknown) {
|
||||||
|
popup.value?.config?.callback?.(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
popup.value = undefined
|
||||||
|
setBodyScrolling(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { get, require, open, close, callback }
|
||||||
|
}
|
||||||
|
|
||||||
|
function setBodyScrolling(enabled: boolean) {
|
||||||
|
if (import.meta.client) {
|
||||||
|
document.body.style.overflow = enabled ? '' : 'hidden'
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { signS3Get, signS3Put, signS3Delete, encodeCanonicalPath } from '~/utils/sigv4'
|
||||||
|
import { parseBucketsXml, parseObjectsXml, type S3Bucket, type S3Object } from '~/utils/s3xml'
|
||||||
|
|
||||||
|
export function useS3Client() {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
|
||||||
|
async function get(path: string): Promise<string> {
|
||||||
|
const headers = await signS3Get(path, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||||
|
return $fetch<string>(`/api${encodeCanonicalPath(path)}`, { headers, responseType: 'text' })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listBuckets(): Promise<S3Bucket[]> {
|
||||||
|
return parseBucketsXml(await get('/'))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listObjects(bucket: string): Promise<S3Object[]> {
|
||||||
|
return parseObjectsXml(await get(`/${bucket}`))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadObject(bucket: string, key: string): Promise<Blob> {
|
||||||
|
const path = `/${bucket}/${key}`
|
||||||
|
const headers = await signS3Get(path, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||||
|
return $fetch<Blob>(`/api${encodeCanonicalPath(path)}`, { headers, responseType: 'blob' })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getObjectText(bucket: string, key: string): Promise<string> {
|
||||||
|
return get(`/${bucket}/${key}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadObject(bucket: string, key: string, file: File): Promise<void> {
|
||||||
|
const path = `/${bucket}/${key}`
|
||||||
|
const headers = await signS3Put(path, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||||
|
await $fetch(`/api${encodeCanonicalPath(path)}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { ...headers, 'Content-Type': file.type || 'application/octet-stream' },
|
||||||
|
body: file,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteObject(bucket: string, key: string): Promise<void> {
|
||||||
|
const path = `/${bucket}/${key}`
|
||||||
|
const headers = await signS3Delete(path, config.public.s3AccessKey, config.public.s3SecretKey)
|
||||||
|
await $fetch(`/api${encodeCanonicalPath(path)}`, { method: 'DELETE', headers })
|
||||||
|
}
|
||||||
|
|
||||||
|
return { listBuckets, listObjects, downloadObject, getObjectText, uploadObject, deleteObject }
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
const UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
|
|
||||||
|
export function formatBytes(bytes: number): string {
|
||||||
|
let value = bytes
|
||||||
|
let unitIndex = 0
|
||||||
|
while (value >= 1024 && unitIndex < UNITS.length - 1) {
|
||||||
|
value /= 1024
|
||||||
|
unitIndex += 1
|
||||||
|
}
|
||||||
|
return `${value.toFixed(unitIndex === 0 ? 0 : 1)} ${UNITS[unitIndex]}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTime(iso: string): string {
|
||||||
|
return new Date(iso).toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(iso: string): string {
|
||||||
|
return new Date(iso).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isToday(iso: string): boolean {
|
||||||
|
const date = new Date(iso)
|
||||||
|
const now = new Date()
|
||||||
|
return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDateTime(iso: string): string {
|
||||||
|
return new Date(iso).toLocaleString('de-DE', { dateStyle: 'medium', timeStyle: 'medium' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function partCount(etag: string): number {
|
||||||
|
const dashIndex = etag.indexOf('-')
|
||||||
|
if (dashIndex === -1) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
const parsed = Number(etag.slice(dashIndex + 1))
|
||||||
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shortEtag(etag: string): string {
|
||||||
|
const dashIndex = etag.indexOf('-')
|
||||||
|
const hash = dashIndex === -1 ? etag : etag.slice(0, dashIndex)
|
||||||
|
const suffix = dashIndex === -1 ? '' : etag.slice(dashIndex)
|
||||||
|
return `${hash.slice(0, 8)}…${hash.slice(-4)}${suffix}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function baseName(key: string): string {
|
||||||
|
const slashIndex = key.lastIndexOf('/')
|
||||||
|
return slashIndex === -1 ? key : key.slice(slashIndex + 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import type { Component } from 'vue'
|
||||||
|
|
||||||
|
export class Popup<P> {
|
||||||
|
component?: Component
|
||||||
|
payload?: P
|
||||||
|
config?: PopupConfig
|
||||||
|
|
||||||
|
public static component<P>(component: Component): Popup<P> {
|
||||||
|
const popup = new Popup<P>()
|
||||||
|
popup.component = component
|
||||||
|
return popup
|
||||||
|
}
|
||||||
|
|
||||||
|
public setPayload(payload: P) {
|
||||||
|
this.payload = payload
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
public setConfig(config: PopupConfig) {
|
||||||
|
this.config = config
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PopupConfig {
|
||||||
|
heading: string
|
||||||
|
size: PopupSize
|
||||||
|
closeOnOverlayClick?: boolean
|
||||||
|
callback?: (payload?: unknown) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PopupSize {
|
||||||
|
SMALL = 'small',
|
||||||
|
MEDIUM = 'medium',
|
||||||
|
LARGE = 'large',
|
||||||
|
FULL = 'full',
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
export interface S3Bucket {
|
||||||
|
name: string
|
||||||
|
creationDate: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface S3Object {
|
||||||
|
key: string
|
||||||
|
size: number
|
||||||
|
lastModified: string
|
||||||
|
etag: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseBucketsXml(xml: string): S3Bucket[] {
|
||||||
|
const doc = new DOMParser().parseFromString(xml, 'application/xml')
|
||||||
|
return Array.from(doc.getElementsByTagName('Bucket')).map((el) => ({
|
||||||
|
name: text(el, 'Name'),
|
||||||
|
creationDate: text(el, 'CreationDate'),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseObjectsXml(xml: string): S3Object[] {
|
||||||
|
const doc = new DOMParser().parseFromString(xml, 'application/xml')
|
||||||
|
return Array.from(doc.getElementsByTagName('Contents')).map((el) => ({
|
||||||
|
key: text(el, 'Key'),
|
||||||
|
size: Number(text(el, 'Size')),
|
||||||
|
lastModified: text(el, 'LastModified'),
|
||||||
|
etag: text(el, 'ETag').replace(/"/g, ''),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
function text(parent: Element, tag: string): string {
|
||||||
|
return parent.getElementsByTagName(tag)[0]?.textContent ?? ''
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
const REGION = 'us-east-1'
|
||||||
|
const SERVICE = 's3'
|
||||||
|
|
||||||
|
export interface SignedHeaders {
|
||||||
|
Authorization: string
|
||||||
|
'X-Amz-Date': string
|
||||||
|
'X-Amz-Content-Sha256': string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signS3Get(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||||
|
return signS3('GET', path, await sha256Hex(''), accessKey, secretKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signS3Put(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||||
|
return signS3('PUT', path, 'UNSIGNED-PAYLOAD', accessKey, secretKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signS3Delete(path: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||||
|
return signS3('DELETE', path, await sha256Hex(''), accessKey, secretKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function signS3(method: string, path: string, payloadHash: string, accessKey: string, secretKey: string): Promise<SignedHeaders> {
|
||||||
|
const amzDate = toAmzDate(new Date())
|
||||||
|
const dateStamp = amzDate.slice(0, 8)
|
||||||
|
|
||||||
|
const signedHeaderValues: Record<string, string> = {
|
||||||
|
'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`)
|
||||||
|
.join('')
|
||||||
|
|
||||||
|
const canonicalRequest = [method, encodeCanonicalPath(path), '', canonicalHeaders, signedHeaders, payloadHash].join('\n')
|
||||||
|
const credentialScope = `${dateStamp}/${REGION}/${SERVICE}/aws4_request`
|
||||||
|
const stringToSign = [
|
||||||
|
'AWS4-HMAC-SHA256',
|
||||||
|
amzDate,
|
||||||
|
credentialScope,
|
||||||
|
await sha256Hex(canonicalRequest),
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
const key = await deriveSigningKey(secretKey, dateStamp)
|
||||||
|
const signature = bufferToHex(await hmac(key, stringToSign))
|
||||||
|
|
||||||
|
return {
|
||||||
|
Authorization: `AWS4-HMAC-SHA256 Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`,
|
||||||
|
'X-Amz-Date': amzDate,
|
||||||
|
'X-Amz-Content-Sha256': payloadHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toAmzDate(date: Date): string {
|
||||||
|
return date.toISOString().replace(/[:-]|\.\d{3}/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function isUnreservedByte(byte: number): boolean {
|
||||||
|
return (byte >= 0x41 && byte <= 0x5a) // A-Z
|
||||||
|
|| (byte >= 0x61 && byte <= 0x7a) // a-z
|
||||||
|
|| (byte >= 0x30 && byte <= 0x39) // 0-9
|
||||||
|
|| byte === 0x2d || byte === 0x5f || byte === 0x2e || byte === 0x7e // - _ . ~
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encodeCanonicalPath(path: string): string {
|
||||||
|
return path
|
||||||
|
.split('/')
|
||||||
|
.map((segment) => Array.from(new TextEncoder().encode(segment))
|
||||||
|
.map((byte) => (isUnreservedByte(byte) ? String.fromCharCode(byte) : `%${byte.toString(16).toUpperCase().padStart(2, '0')}`))
|
||||||
|
.join(''))
|
||||||
|
.join('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deriveSigningKey(secretKey: string, dateStamp: string): Promise<ArrayBuffer> {
|
||||||
|
const kDate = await hmac(new TextEncoder().encode(`AWS4${secretKey}`), dateStamp)
|
||||||
|
const kRegion = await hmac(kDate, REGION)
|
||||||
|
const kService = await hmac(kRegion, SERVICE)
|
||||||
|
return hmac(kService, 'aws4_request')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function hmac(key: BufferSource, data: string): Promise<ArrayBuffer> {
|
||||||
|
const cryptoKey = await crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
|
||||||
|
return crypto.subtle.sign('HMAC', cryptoKey, new TextEncoder().encode(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sha256Hex(data: string): Promise<string> {
|
||||||
|
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(data))
|
||||||
|
return bufferToHex(digest)
|
||||||
|
}
|
||||||
|
|
||||||
|
function bufferToHex(buffer: ArrayBuffer): string {
|
||||||
|
return Array.from(new Uint8Array(buffer))
|
||||||
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
|
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
compatibilityDate: '2025-07-15',
|
||||||
|
devtools: { enabled: true },
|
||||||
|
css: ['~/assets/css/main.css'],
|
||||||
|
runtimeConfig: {
|
||||||
|
public: {
|
||||||
|
s3AccessKey: 'devkey',
|
||||||
|
s3SecretKey: 'devsecret',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
vite: {
|
||||||
|
plugins: [
|
||||||
|
tailwindcss(),
|
||||||
|
],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:8080',
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path: string) => path.replace(/^\/api/, ''),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
Generated
+9727
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "nuxt build",
|
||||||
|
"dev": "nuxt dev",
|
||||||
|
"generate": "nuxt generate",
|
||||||
|
"preview": "nuxt preview",
|
||||||
|
"postinstall": "nuxt prepare"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tailwindcss/vite": "^4.3.3",
|
||||||
|
"nuxt": "^4.5.2",
|
||||||
|
"tailwindcss": "^4.3.3",
|
||||||
|
"vue": "^3.5.41",
|
||||||
|
"vue-router": "^5.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,2 @@
|
|||||||
|
User-Agent: *
|
||||||
|
Disallow:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
// https://nuxt.com/docs/guide/concepts/typescript
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.server.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.shared.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.node.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user