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.

feat(cloud): configure default public gallery theme per site

Timothy Yin7b1eb9d7a785
diff --git a/apps/cloud/app/components/CloudSiteSettings.vue b/apps/cloud/app/components/CloudSiteSettings.vue
index 6e55ca50..85825de8 100644
--- a/apps/cloud/app/components/CloudSiteSettings.vue
+++ b/apps/cloud/app/components/CloudSiteSettings.vue
@@ -23,6 +23,9 @@ const profile = reactive({
author: data.value?.site.author ?? '',
avatarUrl: data.value?.site.avatarUrl ?? '',
})
+const theme = ref<'light' | 'dark' | 'system'>(
+ data.value?.site.presentation.theme ?? 'dark',
+)
const homeHeaderLayout = ref<'embedded' | 'fixed'>(
data.value?.site.presentation.homeHeaderLayout ?? 'embedded',
)
@@ -113,6 +116,7 @@ async function reload() {
author: data.value?.site.author ?? '',
avatarUrl: data.value?.site.avatarUrl ?? '',
})
+ theme.value = data.value?.site.presentation.theme ?? 'dark'
homeHeaderLayout.value =
data.value?.site.presentation.homeHeaderLayout ?? 'embedded'
socialDraft.value = Array.from(
@@ -141,6 +145,7 @@ async function save() {
published: !!data.value.site.published,
profile: { ...profile },
presentation: {
+ theme: theme.value,
homeHeaderLayout: homeHeaderLayout.value,
socialLinks: {
links: parseSocialLinks({
@@ -285,6 +290,32 @@ async function save() {
{{ iconError }}
</p>
</div>
+ <section class="cf-gallery-presentation">
+ <h3>{{ $t('cloud.presentation.theme') }}</h3>
+ <p class="cf-field-hint">
+ {{ $t('cloud.presentation.themeHelp') }}
+ </p>
+ <fieldset :disabled="busy">
+ <legend class="sr-only">
+ {{ $t('cloud.presentation.theme') }}
+ </legend>
+ <label
+ v-for="option in ['light', 'dark', 'system'] as const"
+ :key="option"
+ class="cf-layout-option"
+ >
+ <input
+ v-model="theme"
+ type="radio"
+ name="gallery-theme"
+ :value="option"
+ />
+ <span>{{
+ $t('cloud.presentation.themeOptions.' + option)
+ }}</span>
+ </label>
+ </fieldset>
+ </section>
<section class="cf-gallery-presentation">
<h3>{{ $t('cloud.presentation.layout') }}</h3>
<p class="cf-field-hint">
diff --git a/apps/cloud/i18n/locales/en.json b/apps/cloud/i18n/locales/en.json
index f7933af4..c8118436 100644
--- a/apps/cloud/i18n/locales/en.json
+++ b/apps/cloud/i18n/locales/en.json
@@ -609,7 +609,14 @@
"slot": "Link {number}",
"clear": "Clear link {number}",
"invalid": "Enter a valid HTTPS profile URL.",
- "duplicate": "This profile is already listed."
+ "duplicate": "This profile is already listed.",
+ "theme": "Default theme",
+ "themeHelp": "Choose the initial appearance of your public gallery. Visitors can switch between light and dark themes.",
+ "themeOptions": {
+ "light": "Light",
+ "dark": "Dark",
+ "system": "System"
+ }
},
"billing": {
"plan": "Plan & usage",
diff --git a/apps/cloud/i18n/locales/zh-Hans.json b/apps/cloud/i18n/locales/zh-Hans.json
index 641681a4..afb6afbf 100644
--- a/apps/cloud/i18n/locales/zh-Hans.json
+++ b/apps/cloud/i18n/locales/zh-Hans.json
@@ -609,7 +609,14 @@
"slot": "链接 {number}",
"clear": "清空链接 {number}",
"invalid": "请输入有效的 HTTPS 个人主页链接。",
- "duplicate": "该个人主页已添加。"
+ "duplicate": "该个人主页已添加。",
+ "theme": "默认主题",
+ "themeHelp": "设置公开图库的默认外观,访客仍可切换明暗主题。",
+ "themeOptions": {
+ "light": "浅色",
+ "dark": "深色",
+ "system": "跟随系统"
+ }
},
"billing": {
"plan": "套餐与用量",
diff --git a/apps/site/server/api/public/system/settings/all.get.ts b/apps/site/server/api/public/system/settings/all.get.ts
index 886a31f8..419db3d3 100644
--- a/apps/site/server/api/public/system/settings/all.get.ts
+++ b/apps/site/server/api/public/system/settings/all.get.ts
@@ -39,6 +39,7 @@ export default definePlatformHandler(async (event) => {
const presentation = parseGalleryPresentation(
JSON.parse(profile.presentation),
)
+ data.app!['appearance.theme'] = presentation.theme
data.app!['appearance.homeHeaderLayout'] = presentation.homeHeaderLayout
data.app!.socialLinks = presentation.socialLinks
}
diff --git a/packages/contracts/src/gallery-settings.ts b/packages/contracts/src/gallery-settings.ts
index ddbb2514..269397bd 100644
--- a/packages/contracts/src/gallery-settings.ts
+++ b/packages/contracts/src/gallery-settings.ts
@@ -42,6 +42,7 @@ export const PUBLIC_GALLERY_DEFAULTS = {
} as const
export interface GalleryPresentation {
+ theme: 'light' | 'dark' | 'system'
homeHeaderLayout: 'embedded' | 'fixed'
socialLinks: { links: string[] }
}
@@ -51,12 +52,18 @@ export function parseGalleryPresentation(value: unknown): GalleryPresentation {
const data = value as Record<string, unknown>
if (
Object.keys(data).some(
- (k) => !['homeHeaderLayout', 'socialLinks'].includes(k),
+ (k) => !['homeHeaderLayout', 'socialLinks', 'theme'].includes(k),
) ||
(data.homeHeaderLayout !== 'embedded' && data.homeHeaderLayout !== 'fixed')
)
throw new Error('Invalid home header layout')
+ if (
+ data.theme !== undefined &&
+ !['light', 'dark', 'system'].includes(data.theme as string)
+ )
+ throw new Error('Invalid gallery theme')
return {
+ theme: (data.theme ?? 'dark') as GalleryPresentation['theme'],
homeHeaderLayout:
data.homeHeaderLayout as GalleryPresentation['homeHeaderLayout'],
socialLinks: { links: parseSocialLinks(data.socialLinks) },
diff --git a/packages/platform/src/provisioning.ts b/packages/platform/src/provisioning.ts
index 05571e1c..280dcff8 100644
--- a/packages/platform/src/provisioning.ts
+++ b/packages/platform/src/provisioning.ts
@@ -233,7 +233,11 @@ export function createD1Provisioning(
let presentation = current.presentation
if (input.presentation !== undefined) {
try {
- presentation = parseGalleryPresentation(input.presentation)
+ const parsed = parseGalleryPresentation(input.presentation)
+ // Older clients do not send a theme; retain the stored preference.
+ if (!Object.hasOwn(input.presentation as object, 'theme'))
+ parsed.theme = current.presentation.theme
+ presentation = parsed
} catch {
throw new ProvisioningError(400, 'Invalid gallery presentation')
}
diff --git a/tests/gallery-presentation-theme.test.ts b/tests/gallery-presentation-theme.test.ts
new file mode 100644
index 00000000..08366c94
--- /dev/null
+++ b/tests/gallery-presentation-theme.test.ts
@@ -0,0 +1,14 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import { parseGalleryPresentation } from '../packages/contracts/src/gallery-settings.ts'
+
+const base = { homeHeaderLayout: 'embedded', socialLinks: { links: [] } }
+test('gallery themes accept the self-hosted choices and retain the existing SaaS default', () => {
+ assert.equal(parseGalleryPresentation(base).theme, 'dark')
+ for (const theme of ['light', 'dark', 'system']) {
+ assert.equal(parseGalleryPresentation({ ...base, theme }).theme, theme)
+ }
+ for (const theme of [null, '', 'auto', [], {}, 1]) {
+ assert.throws(() => parseGalleryPresentation({ ...base, theme }))
+ }
+})
diff --git a/tests/platform-provisioning.test.ts b/tests/platform-provisioning.test.ts
index eae59550..317cb460 100644
--- a/tests/platform-provisioning.test.ts
+++ b/tests/platform-provisioning.test.ts
@@ -223,6 +223,7 @@ test('Real D1 provisioning preserves old tenants, serializes defaults and enforc
revision: 3,
profile,
presentation: {
+ theme: 'light',
homeHeaderLayout: 'fixed',
socialLinks: {
links: [
@@ -233,6 +234,7 @@ test('Real D1 provisioning preserves old tenants, serializes defaults and enforc
},
})
assert.deepEqual(profiled.presentation, {
+ theme: 'light',
homeHeaderLayout: 'fixed',
socialLinks: {
links: ['https://github.com/example', 'https://example.com/portfolio'],
@@ -244,6 +246,10 @@ test('Real D1 provisioning preserves old tenants, serializes defaults and enforc
name: 'Renamed workspace',
published: false,
revision: 4,
+ presentation: {
+ homeHeaderLayout: 'fixed',
+ socialLinks: profiled.presentation.socialLinks,
+ },
})
assert.equal(
preserved.title,