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(billing): bound entitlement reads and respect reduced motion

Timothy Yin4080fd9a2659
diff --git a/apps/cloud/app/assets/cloud.css b/apps/cloud/app/assets/cloud.css
index 565c21c0..1a92fab9 100644
--- a/apps/cloud/app/assets/cloud.css
+++ b/apps/cloud/app/assets/cloud.css
@@ -3061,6 +3061,6 @@ a.cf-domain-address:hover {
}
@media (prefers-reduced-motion: reduce) {
.cf-payment-spinner {
- animation-duration: 2s;
+ animation: none;
}
}
diff --git a/apps/cloud/app/composables/useCloudPayments.ts b/apps/cloud/app/composables/useCloudPayments.ts
index 799391e7..5fe1ee81 100644
--- a/apps/cloud/app/composables/useCloudPayments.ts
+++ b/apps/cloud/app/composables/useCloudPayments.ts
@@ -15,6 +15,7 @@ export function useCloudPayments(
try {
const result = await $fetch('/api/billing/payments', {
query: { workspaceId: id },
+ timeout: 15000,
})
if (alive && current === generation) {
data.value = result
diff --git a/apps/cloud/app/composables/useWorkspaceBilling.ts b/apps/cloud/app/composables/useWorkspaceBilling.ts
index a92274b4..b5bf7a16 100644
--- a/apps/cloud/app/composables/useWorkspaceBilling.ts
+++ b/apps/cloud/app/composables/useWorkspaceBilling.ts
@@ -7,6 +7,7 @@ export function useWorkspaceBilling(adminOnly = false) {
async () => {
const list = await fetcher<{ workspaces: Workspace[] }>(
'/api/billing/workspaces',
+ { timeout: 15000 },
)
const primary =
list.workspaces.find((w) => w.owned) ??
@@ -16,6 +17,7 @@ export function useWorkspaceBilling(adminOnly = false) {
const plan = id
? await fetcher<any>('/api/billing/plan', {
query: { workspaceId: id },
+ timeout: 15000,
})
: null
return {
diff --git a/tests/portal-review-regressions.test.ts b/tests/portal-review-regressions.test.ts
index 566a70a9..35205fa1 100644
--- a/tests/portal-review-regressions.test.ts
+++ b/tests/portal-review-regressions.test.ts
@@ -2,6 +2,8 @@ import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import vm from 'node:vm'
+import { createServer } from 'node:http'
+import { createRequire } from 'node:module'
import ts from 'typescript'
import { isAlbumPagePath } from '../packages/gallery/shared/utils/albumPath.ts'
import { ref, reactive, computed, readonly, watch, effectScope } from 'vue'
@@ -408,3 +410,80 @@ test('Primary billing workspace consistently prefers ownership then administrati
await state.ready
assert.equal(selected, 1)
})
+
+test('billing refresh aborts stalled workspace, plan and payment reads', async () => {
+ const require = createRequire(import.meta.url)
+ const { $fetch } = createRequire(require.resolve('nuxt/package.json'))(
+ 'ofetch',
+ )
+ let stalledPath = ''
+ let closed: Promise<void> = Promise.resolve()
+ const server = createServer((request, response) => {
+ if (request.url?.split('?')[0] === stalledPath) {
+ closed = new Promise<void>((resolve) => response.once('close', resolve))
+ return
+ }
+ response.setHeader('Content-Type', 'application/json')
+ response.end(
+ JSON.stringify({ workspaces: [{ id: 1, role: 'admin', owned: 1 }] }),
+ )
+ })
+ await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve))
+ const address = server.address() as { port: number }
+ const fetcher = (url: string, options: any) => {
+ // Exercise the real fetch timeout/abort path on a shorter test clock.
+ assert.equal(options?.timeout, 15000)
+ return $fetch(url, {
+ ...options,
+ baseURL: `http://127.0.0.1:${address.port}`,
+ timeout: 100,
+ retry: 0,
+ })
+ }
+ const scope = effectScope()
+ try {
+ const billingModule = load(
+ 'apps/cloud/app/composables/useWorkspaceBilling.ts',
+ {
+ usePortalIdentity: () => ref({ id: 1 }),
+ useRequestFetch: () => fetcher,
+ useAsyncData: (_key: string, run: any) => ({
+ data: ref(null),
+ error: ref(null),
+ status: ref('idle'),
+ refresh: run,
+ }),
+ onMounted: () => {},
+ },
+ )
+ const billing = scope.run(() => billingModule.useWorkspaceBilling())!
+ for (const path of ['/api/billing/workspaces', '/api/billing/plan']) {
+ stalledPath = path
+ await assert.rejects(billing.refresh(), /timeout/i)
+ await closed // The underlying HTTP request was canceled, not merely raced.
+ }
+ const paymentsModule = load(
+ 'apps/cloud/app/composables/useCloudPayments.ts',
+ {
+ toValue: (value: any) =>
+ typeof value === 'function' ? value() : value,
+ $fetch: fetcher,
+ onMounted: () => {},
+ onBeforeUnmount: () => {},
+ useIntervalFn: () => {},
+ },
+ )
+ const payments = scope.run(() => paymentsModule.useCloudPayments(1))!
+ stalledPath = '/api/billing/payments'
+ await payments.refresh()
+ await closed
+ assert.ok(payments.error.value)
+ assert.equal(payments.data.value, undefined)
+ } finally {
+ scope.stop()
+ server.closeAllConnections()
+ await new Promise<void>((resolve, reject) =>
+ server.close((error) => (error ? reject(error) : resolve())),
+ )
+ }
+})