Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(cloud): preserve alternate upload access and retry feedback

Timothy Yin186bbed27677
diff --git a/apps/cloud/app/components/CloudAlbumsManager.vue b/apps/cloud/app/components/CloudAlbumsManager.vue
index 67543937..a161f86a 100644
--- a/apps/cloud/app/components/CloudAlbumsManager.vue
+++ b/apps/cloud/app/components/CloudAlbumsManager.vue
@@ -552,8 +552,8 @@ function menu(album: Album) {
:alt="photo.title || $t('cloud.messages.photograph')"
/><span>{{ photo.title }}</span
><CloudButton
- :color="draft.coverPhotoId === photo.id ? 'primary' : 'neutral'"
- variant="ghost"
+ :variant="draft.coverPhotoId === photo.id ? 'soft' : 'ghost'"
+ :aria-pressed="draft.coverPhotoId === photo.id"
:icon="ButtonIconStar"
size="sm"
:aria-label="$t('cloud.ui.setCover', { title: photo.title })"
diff --git a/apps/cloud/app/components/CloudPhotoLibrary.vue b/apps/cloud/app/components/CloudPhotoLibrary.vue
index f3edce7d..79a6a872 100644
--- a/apps/cloud/app/components/CloudPhotoLibrary.vue
+++ b/apps/cloud/app/components/CloudPhotoLibrary.vue
@@ -8,6 +8,7 @@ import {
Trash2 as ButtonIconTrash2,
Upload as ButtonIconUpload,
} from 'lucide-vue-next'
+import { uploadQuotaGate } from '../utils/quota-gate'
const { t, locale } = useI18n()
import type { Photo } from '@chronoframe/contracts/resources'
@@ -38,22 +39,20 @@ const {
const quota = useCloudQuota(useEntryContext().value?.workspaceId)
const uploadAdmission = computed(() => {
if (!ready.value) return { allowed: false, reason: 'checking' }
- const connection = connections.value.find((c) => c.id === connectionId.value)
- const mode = !connection || connection.pool_id ? 'platform' : 'byos'
- const resources =
- mode === 'byos'
- ? (['byos', 'photos', 'monthlyBytes', 'fileBytes'] as const)
- : (['photos', 'storageBytes', 'monthlyBytes', 'fileBytes'] as const)
- return (
- resources
- .map((resource) => quota.gate(resource, mode))
- .find((gate) => !gate.allowed) ?? { allowed: true, reason: '' }
+ return uploadQuotaGate(
+ quota.data.value,
+ connections.value,
+ connectionId.value,
)
})
async function openUpload() {
await quota.refresh()
- if (uploadAdmission.value.allowed && !quota.error.value)
+ if (uploadAdmission.value.allowed && !quota.error.value) {
+ const target = uploadAdmission.value
+ if ('connectionId' in target && target.connectionId)
+ connectionId.value = target.connectionId
uploadOpen.value = true
+ }
}
const search = ref(''),
selection = ref<Record<string, boolean>>({}),
diff --git a/apps/cloud/app/components/CloudSiteWorkspace.vue b/apps/cloud/app/components/CloudSiteWorkspace.vue
index df6be0e8..9be298fa 100644
--- a/apps/cloud/app/components/CloudSiteWorkspace.vue
+++ b/apps/cloud/app/components/CloudSiteWorkspace.vue
@@ -10,7 +10,8 @@ settings.data = structuredClone(PUBLIC_GALLERY_DEFAULTS) as Record<
settings.data.app!.title = useEntryContext().value?.name ?? 'ChronoFrame'
settings.isInitialized = true
const media = provideCloudSiteMedia(props)
-const { photos, loading, message, failed, reload } = media
+const { photos, loading, message, failed, reload, loadError, refreshMedia } =
+ media
const status = computed(() => (loading.value ? 'pending' : 'success'))
</script>
<template>
@@ -19,14 +20,20 @@ const status = computed(() => (loading.value ? 'pending' : 'success'))
:refresh="reload"
:status="status"
>
- <p
+ <CloudAlert
v-if="message"
- :role="failed ? 'alert' : 'status'"
- class="cf-notice"
- :class="{ 'cf-notice-error': failed }"
+ :tone="failed ? 'error' : 'info'"
>
- {{ message }}
- </p>
+ {{ message
+ }}<CloudButton
+ v-if="loadError"
+ size="sm"
+ variant="secondary"
+ :loading="loading"
+ @click="refreshMedia"
+ >{{ $t('cloud.messages.retry') }}</CloudButton
+ >
+ </CloudAlert>
<slot /><CloudUploadDrawer
/></PhotosProvider>
</template>
diff --git a/apps/cloud/app/components/CloudUploadDrawer.vue b/apps/cloud/app/components/CloudUploadDrawer.vue
index f486188d..49459e97 100644
--- a/apps/cloud/app/components/CloudUploadDrawer.vue
+++ b/apps/cloud/app/components/CloudUploadDrawer.vue
@@ -1,4 +1,5 @@
<script setup lang="ts">
+import { uploadQuotaGate } from '../utils/quota-gate'
const {
uploadOpen,
message,
@@ -17,11 +18,25 @@ const {
} = useCloudSiteMedia()
const context = useEntryContext().value,
input = ref<HTMLInputElement>()
+const quota = useCloudQuota(context?.workspaceId)
+const selectedAdmission = computed(() =>
+ uploadQuotaGate(
+ quota.data.value,
+ connections.value.filter((c) => c.id === connectionId.value),
+ connectionId.value,
+ ),
+)
+const uploadAllowed = computed(
+ () =>
+ !!connectionId.value &&
+ selectedAdmission.value.allowed &&
+ !quota.error.value,
+)
async function dropFiles(event: DragEvent) {
if (
!input.value ||
uploading.value ||
- !connectionId.value ||
+ !uploadAllowed.value ||
!admin.value ||
!event.dataTransfer?.files.length
)
@@ -63,6 +78,9 @@ async function dropFiles(event: DragEvent) {
? $t('cloud.messages.platformStorage')
: c.config.bucket,
value: c.id,
+ disabled:
+ !uploadQuotaGate(quota.data.value, [c], c.id).allowed ||
+ !!quota.error.value,
}))
"
class="w-full"
@@ -90,6 +108,14 @@ async function dropFiles(event: DragEvent) {
>
{{ $t('cloud.storageAllowance.unavailable') }}
</p>
+ <CloudQuotaNotice
+ v-if="
+ connectionId && (!selectedAdmission.allowed || quota.error.value)
+ "
+ :reason="selectedAdmission.reason"
+ :error="!!quota.error.value"
+ @retry="quota.refresh()"
+ />
<input
ref="input"
class="sr-only"
@@ -97,13 +123,13 @@ async function dropFiles(event: DragEvent) {
multiple
accept="image/*,.heic,.heif,.mov"
:aria-label="$t('cloud.messages.choosePhotographs')"
- :disabled="uploading || !connectionId || !admin"
+ :disabled="uploading || !uploadAllowed || !admin"
@change="upload"
/><button
class="cf-upload-dropzone"
@dragover.prevent
@drop.prevent="dropFiles"
- :disabled="uploading || !connectionId || !admin"
+ :disabled="uploading || !uploadAllowed || !admin"
@click="input?.click()"
>
<UIcon
diff --git a/apps/cloud/app/composables/useCloudSiteMedia.ts b/apps/cloud/app/composables/useCloudSiteMedia.ts
index 37eca86a..8b6ed5fa 100644
--- a/apps/cloud/app/composables/useCloudSiteMedia.ts
+++ b/apps/cloud/app/composables/useCloudSiteMedia.ts
@@ -92,6 +92,7 @@ export function useCloudMediaWorkspace(props: {
activeResumeKey: string | undefined
const canPoll = ref(true)
const ready = ref(false)
+ const loadError = ref('')
const loading = ref(true),
uploadOpen = ref(false)
let reloadGeneration = 0
@@ -130,6 +131,11 @@ export function useCloudMediaWorkspace(props: {
jobs.value = p.jobs
albums.value = a.albums
ready.value = true
+ if (loadError.value && message.value === loadError.value) {
+ failed.value = false
+ message.value = ''
+ }
+ loadError.value = ''
if (
!connectionId.value ||
connections.value.find((c) => c.id === connectionId.value)
@@ -153,6 +159,7 @@ export function useCloudMediaWorkspace(props: {
'cloud.messages.mediaServicesNeedDeploymentConfigurationYourExistingSiteSettings',
)
: t('cloud.messages.couldNotRefreshMediaCheckYourAccessAndRetry')
+ loadError.value = message.value
canPoll.value = false
} finally {
if (generation === reloadGeneration) loading.value = false
@@ -524,6 +531,7 @@ export function useCloudMediaWorkspace(props: {
api,
loading,
ready,
+ loadError,
uploadOpen,
}
}
diff --git a/apps/cloud/app/pages/sites/[siteId]/overview.vue b/apps/cloud/app/pages/sites/[siteId]/overview.vue
index ad729b5c..b783dae8 100644
--- a/apps/cloud/app/pages/sites/[siteId]/overview.vue
+++ b/apps/cloud/app/pages/sites/[siteId]/overview.vue
@@ -20,7 +20,7 @@ const activeContext = useEntryContext(),
watch(activeContext, (next) => {
if (next?.scope === site.value.scope) site.value = next
})
-const { photos, albums, jobs, loading, ready, connections, connectionId } =
+const { photos, albums, jobs, loading, ready, connections, loadError } =
useCloudSiteMedia()
const processing = computed(
() =>
@@ -31,8 +31,8 @@ const processing = computed(
const failed = computed(
() => jobs.value.filter((job) => job.state === 'failed').length,
)
-const connection = computed(() =>
- connections.value.find((item) => item.id === connectionId.value),
+const connection = computed(
+ () => connections.value.find((item) => item.pool_id) ?? connections.value[0],
)
const actions = computed(() => [
{
@@ -77,8 +77,8 @@ const actions = computed(() => [
>
<CloudStatCard
:label="$t('cloud.messages.photographs')"
- :value="photos.length"
- :loading="!ready"
+ :value="ready ? photos.length : undefined"
+ :loading="!ready && !loadError"
><NuxtLink
:to="`/sites/${site.siteId}/photos`"
class="cf-text-link"
@@ -87,8 +87,8 @@ const actions = computed(() => [
></CloudStatCard>
<CloudStatCard
:label="$t('cloud.messages.albums')"
- :value="albums.length"
- :loading="!ready"
+ :value="ready ? albums.length : undefined"
+ :loading="!ready && !loadError"
><NuxtLink
:to="`/sites/${site.siteId}/albums`"
class="cf-text-link"
@@ -97,8 +97,8 @@ const actions = computed(() => [
></CloudStatCard>
<CloudStatCard
:label="$t('cloud.messages.processing')"
- :value="processing"
- :loading="!ready"
+ :value="ready ? processing : undefined"
+ :loading="!ready && !loadError"
:detail="
failed
? $t('cloud.dashboard.failedJobs', { count: failed })
@@ -129,11 +129,11 @@ const actions = computed(() => [
<CloudCard class="cf-dashboard-panel"
><h2>{{ $t('cloud.dashboard.siteHealth') }}</h2>
<CloudSkeleton
- v-if="!ready"
+ v-if="!ready && !loadError"
class="h-32 w-full"
/>
<ul
- v-else
+ v-else-if="ready"
class="cf-site-health-list"
>
<li>
diff --git a/apps/cloud/app/utils/quota-gate.ts b/apps/cloud/app/utils/quota-gate.ts
index 740cd9c6..f8adf222 100644
--- a/apps/cloud/app/utils/quota-gate.ts
+++ b/apps/cloud/app/utils/quota-gate.ts
@@ -31,3 +31,37 @@ export function quotaGate(
limit,
}
}
+
+export type UploadConnection = {
+ id: string
+ pool_id?: string | null
+ uploads_enabled?: number
+}
+/** Prefer the current target, but never hide another connection with available allowance. */
+export function uploadQuotaGate(
+ data: any,
+ connections: UploadConnection[],
+ selected = '',
+) {
+ const candidates = connections
+ .filter((c) => c.uploads_enabled !== 0)
+ .sort((a, b) => Number(b.id === selected) - Number(a.id === selected))
+ const targets = candidates.length
+ ? candidates
+ : [{ id: '', pool_id: 'platform' }]
+ const gates = targets.map((connection) => {
+ const mode = connection.pool_id ? 'platform' : 'byos'
+ const resources: QuotaResource[] =
+ mode === 'byos'
+ ? ['byos', 'photos', 'monthlyBytes', 'fileBytes']
+ : ['photos', 'storageBytes', 'monthlyBytes', 'fileBytes']
+ const denied = resources
+ .map((resource) => quotaGate(data, resource, mode))
+ .find((gate) => !gate.allowed)
+ return {
+ ...(denied ?? { allowed: true, reason: '' }),
+ connectionId: connection.id,
+ }
+ })
+ return gates.find((gate) => gate.allowed) ?? gates[0]!
+}
diff --git a/tests/console-quota.test.ts b/tests/console-quota.test.ts
index 6b26466f..fc40b83a 100644
--- a/tests/console-quota.test.ts
+++ b/tests/console-quota.test.ts
@@ -1,6 +1,9 @@
import assert from 'node:assert/strict'
import test from 'node:test'
-import { quotaGate } from '../apps/cloud/app/utils/quota-gate.ts'
+import {
+ quotaGate,
+ uploadQuotaGate,
+} from '../apps/cloud/app/utils/quota-gate.ts'
test('Quota preflight blocks unknown or read-only contexts before opening a form', () => {
assert.equal(quotaGate(null, 'sites').reason, 'checking')
@@ -51,3 +54,34 @@ test('Quota preflight denies missing and zero limits without inventing unlimited
assert.equal(quotaGate(data, 'fileBytes').allowed, false)
assert.equal(quotaGate(data, 'byos').allowed, true)
})
+
+test('Upload preflight finds an eligible alternative without trapping users on a full pooled target', () => {
+ const data = {
+ workspace: { role: 'admin' },
+ plan: {
+ limits: { photos: 10, storageBytes: 10, monthlyBytes: 50, fileBytes: 20 },
+ byosLimits: { byos: 1, photos: 10, monthlyBytes: 50, fileBytes: 20 },
+ },
+ usage: { photos: 1, storageBytes: 10, monthlyBytes: 1 },
+ }
+ const connections: {
+ id: string
+ pool_id?: string
+ uploads_enabled?: number
+ }[] = [{ id: 'pool', pool_id: 'platform' }, { id: 'custom' }]
+ assert.equal(
+ uploadQuotaGate(data, connections, 'pool').connectionId,
+ 'custom',
+ )
+ assert.equal(uploadQuotaGate(data, connections, 'pool').allowed, true)
+ assert.equal(uploadQuotaGate(data, [connections[0]!], 'pool').allowed, false)
+ assert.equal(uploadQuotaGate(data, [connections[1]!], 'custom').allowed, true)
+ data.usage.storageBytes = 0
+ assert.equal(uploadQuotaGate(data, connections, 'pool').connectionId, 'pool')
+ connections[1]!.uploads_enabled = 0
+ data.usage.storageBytes = 10
+ assert.equal(uploadQuotaGate(data, connections, 'pool').allowed, false)
+ data.plan.byosLimits.byos = 0
+ delete connections[1]!.uploads_enabled
+ assert.equal(uploadQuotaGate(data, connections, 'pool').allowed, false)
+})