Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
feat(cloud): separate featured pricing and current plan indicators
Timothy Yinbf34cf94ac8f
diff --git a/apps/cloud/app/assets/cloud.css b/apps/cloud/app/assets/cloud.cssindex 7bd9b8d5..70ea3be4 100644--- a/apps/cloud/app/assets/cloud.css+++ b/apps/cloud/app/assets/cloud.css@@ -2904,7 +2904,7 @@ a.cf-domain-address:hover {border: 1px solid var(--border);border-radius: 14px;}-.cf-pricing-card.is-default {+.cf-pricing-card.is-featured {border-color: var(--primary);box-shadow: 0 0 0 1px var(--primary);}@@ -3198,3 +3198,10 @@ a.cf-domain-address:hover {padding: 18px;}}++.cf-pricing > .cf-workspace-picker {+ margin-bottom: 12px;+}+.cf-pricing-current {+ margin-bottom: 24px;+}diff --git a/apps/cloud/app/components/CloudPricing.vue b/apps/cloud/app/components/CloudPricing.vueindex 7222cce5..bbb0717a 100644--- a/apps/cloud/app/components/CloudPricing.vue+++ b/apps/cloud/app/components/CloudPricing.vue@@ -10,10 +10,13 @@ const props = withDefaults(defineProps<{ portal?: boolean }>(), {}),{ t, locale } = useI18n(),links = useCloudLinks(),- interval = ref<1 | 3>(1)+ interval = ref<1 | 3>(1),+ billing = props.portal ? useWorkspaceBilling() : nullconst { data, error, refresh } = await useFetch<any>('/api/billing/catalog', {key: 'public-pricing-catalog',})+if (billing) await billing.ready+const currentPlan = computed(() => billing?.data.value?.plan.id)const amount = (plan: any) =>interval.value === 1 ? plan.monthlyPrice : plan.quarterlyPriceconst action = (plan: any) =>@@ -45,6 +48,38 @@ const action = (plan: any) =></fieldset><p class="cf-field-hint">{{ $t('cloud.billing.paymentsPlanned') }}</p></div>+ <template v-if="billing">+ <label class="cf-workspace-picker"+ >{{ $t('cloud.billing.workspace')+ }}<select v-model="billing.selected.value">+ <option+ v-for="workspace in billing.workspaces.value"+ :key="workspace.id"+ :value="workspace.id"+ >+ {{ workspace.name }}+ </option>+ </select></label+ >+ <p+ v-if="billing.error.value"+ role="alert"+ class="cf-notice"+ >+ {{ $t('cloud.billing.failed') }}+ <CloudButton+ variant="ghost"+ @click="billing.retry"+ >{{ $t('cloud.billing.retry') }}</CloudButton+ >+ </p>+ <p+ v-else-if="billing.data.value"+ class="cf-field-hint cf-pricing-current"+ >+ {{ $t('cloud.billing.current') }}: {{ billing.data.value.plan.name }}+ </p>+ </template><CloudCardv-if="error"role="alert"@@ -58,12 +93,12 @@ const action = (plan: any) =>v-for="plan in data.plans":key="plan.id"class="cf-pricing-card"- :class="{ 'is-default': plan.id === data.newPlanId }"+ :class="{ 'is-featured': plan.featured }"><div class="cf-plan-card-heading"><h2>{{ plan.name }}</h2>- <CloudBadge v-if="plan.id === data.newPlanId">{{- $t('cloud.billing.defaultTier')+ <CloudBadge v-if="portal && plan.id === currentPlan">{{+ $t('cloud.billing.current')}}</CloudBadge></div><p class="cf-plan-description">@@ -95,7 +130,7 @@ const action = (plan: any) =></p><CloudButtonas-child- :variant="plan.id === data.newPlanId ? 'default' : 'secondary'"+ :variant="plan.featured ? 'default' : 'secondary'"><NuxtLink:to="action(plan)":external="!portal"diff --git a/packages/platform/migrations/0018_featured_plan.sql b/packages/platform/migrations/0018_featured_plan.sqlnew file mode 100644index 00000000..8fd5d6ca--- /dev/null+++ b/packages/platform/migrations/0018_featured_plan.sql@@ -0,0 +1,2 @@+ALTER TABLE platform_plans ADD COLUMN featured INTEGER NOT NULL DEFAULT 0 CHECK(featured IN(0,1));+CREATE UNIQUE INDEX platform_plans_one_featured ON platform_plans(featured) WHERE featured=1;diff --git a/packages/platform/src/billing.ts b/packages/platform/src/billing.tsindex 6530812a..488ddaa7 100644--- a/packages/platform/src/billing.ts+++ b/packages/platform/src/billing.ts@@ -21,6 +21,7 @@ export function validatePricing(value: unknown) {!p ||!CURRENCIES.includes(p.currency as (typeof CURRENCIES)[number]) ||typeof p.listed !== 'boolean' ||+ (p.featured !== undefined && typeof p.featured !== 'boolean') ||typeof p.description !== 'string' ||p.description.length > 500 ||!Number.isSafeInteger(p.sortOrder) ||@@ -41,6 +42,7 @@ export function validatePricing(value: unknown) {monthlyPrice: p.monthlyPrice as number | null,quarterlyPrice: p.quarterlyPrice as number | null,listed: p.listed,+ featured: p.featured as boolean | undefined,description: p.description,sortOrder: Number(p.sortOrder),}@@ -54,9 +56,10 @@ export async function pricingCatalog(db: PlatformD1) {monthly_price: number | nullquarterly_price: number | nulldescription: string+ featured: number}>(db.prepare(- 'SELECT id,name,policy_json,currency,monthly_price,quarterly_price,description FROM platform_plans WHERE active=1 AND listed=1 ORDER BY sort_order,id',+ 'SELECT id,name,policy_json,currency,monthly_price,quarterly_price,description,featured FROM platform_plans WHERE active=1 AND listed=1 ORDER BY sort_order,id',),)const settings = await db@@ -66,8 +69,9 @@ export async function pricingCatalog(db: PlatformD1) {paymentAvailable: false,newPlanId: settings?.new_plan_id ?? 'free',plans: rows.map(- ({ policy_json, monthly_price, quarterly_price, ...row }) => ({+ ({ policy_json, monthly_price, quarterly_price, featured, ...row }) => ({...row,+ featured: !!featured,monthlyPrice: monthly_price,quarterlyPrice: quarterly_price,policy: validatePolicy(JSON.parse(policy_json)),diff --git a/tests/platform-subscriptions.test.ts b/tests/platform-subscriptions.test.tsindex d7c876c1..e134ee86 100644--- a/tests/platform-subscriptions.test.ts+++ b/tests/platform-subscriptions.test.ts@@ -141,6 +141,23 @@ test('Real D1 defaults, live expiry, activation races/idempotency and workspace.run()const catalog = await pricingCatalog(db)assert.equal(catalog.paymentAvailable, false)+ assert.ok(catalog.plans.every((p) => p.featured === false))+ await db+ .prepare("UPDATE platform_plans SET featured=1 WHERE id='pro'")+ .run()+ assert.equal(+ (await pricingCatalog(db)).plans.find((p) => p.featured)!.id,+ 'pro',+ )+ await assert.rejects(+ db+ .prepare("UPDATE platform_plans SET featured=1 WHERE id='starter'")+ .run(),+ /UNIQUE/,+ )+ await db+ .prepare("UPDATE platform_plans SET featured=0 WHERE id='pro'")+ .run()assert.equal(catalog.plans.find((p) => p.id === 'pro')!.quarterlyPrice,2400,