Skip to content

Commit

Permalink
add note when db is full
Browse files Browse the repository at this point in the history
Signed-off-by: Chris-Robin Ennen <chris-robin@ennen.dev>
4350pChris committed Jan 3, 2024
1 parent 4555105 commit db41fb1
Showing 6 changed files with 41 additions and 27 deletions.
42 changes: 19 additions & 23 deletions components/upload/Worker.vue
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ interface Emits {
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const { queue, list, done, errors, retriable, doUpload } = useUpload()
const { queue, list, done, errors, retriable, full, doUpload } = useUpload()
watchEffect(() => {
const channel = props.channels.filter(c => queue.value.has(c)).at(-1)
@@ -36,35 +36,34 @@ watchEffect(() => {
})
const handleUpload = async () => {
const success = await doUpload(props.channels, props.entries)
try {
const success = await doUpload(props.channels, props.entries)
if (success)
emit('done')
if (success)
emit('done')
} catch (e) {
console.error(e)
}
}
onMounted(handleUpload)
</script>

<template>
<div class="w-full">
<Transition name="fade">
<p v-if="full" class="text-2xl text-center sticky bottom-0 -mb-4 bg-base-100 py-4">
{{ $t("upload.full") }}
</p>
</Transition>
<div v-if="!full" class="w-full">
<div class="sticky inset-x-0 top-36 z-10 pb-4 bg-base-100">
<progress
class="progress w-full"
:value="((errors.size + done.size) / (channels.length + 1)) * 100"
max="100"
/>
<progress class="progress w-full" :value="((errors.size + done.size) / (channels.length + 1)) * 100" max="100" />
</div>
<ul ref="list" class="list-none space-y-2">
<li
v-for="channel in ['vuesualizer-workspace', ...channels]"
:key="channel"
class="flex gap-2 justify-start items-center"
>
<li v-for="channel in ['vuesualizer-workspace', ...channels]" :key="channel"
class="flex gap-2 justify-start items-center">
<UploadingLoopIcon v-if="queue.has(channel)" class="w-5 h-5" />
<ConfirmIcon
v-else-if="done.has(channel)"
class="w-5 h-5 text-success"
/>
<ConfirmIcon v-else-if="done.has(channel)" class="w-5 h-5 text-success" />
<AlertIcon v-else-if="errors.has(channel)" class="w-5 h-5 text-error" />
<CircleIcon v-else class="w-5 h-5" />
<span v-if="channel === 'vuesualizer-workspace'">
@@ -74,10 +73,7 @@ onMounted(handleUpload)
</li>
</ul>
<Transition name="fade">
<div
v-if="retriable"
class="sticky bottom-0 -mb-4 bg-base-100 py-4 border-t"
>
<div v-if="retriable" class="sticky bottom-0 -mb-4 bg-base-100 py-4 border-t">
<button class="btn btn-outline btn-primary btn-block" @click="handleUpload">
{{ $t("retry") }}
</button>
8 changes: 8 additions & 0 deletions composables/useUpload.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Sema } from 'async-sema'
import { FetchError } from "ofetch"
import type { Entry } from '@zip.js/zip.js'

export const useUpload = () => {
const queue = ref(new Set<string>())
const done = ref(new Set<string>())
const errors = ref(new Set<string>())
const retriable = ref(false)
const full = ref(false)

const { parseData } = useZip()

@@ -84,6 +86,11 @@ export const useUpload = () => {
}
catch (e) {
errors.value.add('vuesualizer-workspace')

if (e instanceof FetchError && e.response?.status === 409) {
full.value = true
}

throw e
}
finally {
@@ -114,6 +121,7 @@ export const useUpload = () => {
queue,
done,
errors,
full,
retriable,
list,
doUpload,
3 changes: 2 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@
"success": "Import erfolgreich!",
"done": "Hier ist dein Link. Teile ihn mit anderen um ihnen Zugang zu dem Slack Archiv zu geben.",
"button": "Datei auswählen (.zip)",
"delete": "Lösche hochgeladene Datei"
"delete": "Lösche hochgeladene Datei",
"full": "Leider gibt es keinen Platz für weitere Workspaces."
},
"token": {
"copy": "Einladungslink kopieren",
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@
"success": "Upload successful!",
"done": "Here's your link. You may share it with others to give them access to your Slack archive.",
"button": "choose file (.zip)",
"delete": "delete uploaded export"
"delete": "delete uploaded export",
"full": "Unfortunately, we cannot accept any more uploads at this time. Please try again later."
},
"token": {
"copy": "copy invite link",
2 changes: 1 addition & 1 deletion server/api/files/index.post.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const mongoSortFromBody = (
case Sortable.Oldest:
return { 'files.timestamp': 1 }
default:
throw createError({ statusCode: 400, message: 'Unknown sorting' })
throw createError({ statusCode: 400, statusMessage: 'Unknown sorting' })
}
}

10 changes: 9 additions & 1 deletion server/api/import/workspace/index.post.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,15 @@ export default defineEventHandler(async (event) => {
const uuid = randomUUID()
const db = await mongo(uuid)

await createDb(db)
try {
await createDb(db)
} catch (e) {
// collections are full
throw createError({
statusCode: 409,
statusMessage: 'Database is full'
})
}

const { data } = await readBody<{ data: DataIn[] }>(event)

0 comments on commit db41fb1

Please sign in to comment.