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
fix(open-graph): pass location display settings into photo cards
Timothy Yin87e2ed0f27d8
diff --git a/app/components/OgImage/Photo.takumi.vue b/app/components/OgImage/Photo.takumi.vueindex 0e26ce16..38d4970e 100644--- a/app/components/OgImage/Photo.takumi.vue+++ b/app/components/OgImage/Photo.takumi.vue@@ -8,12 +8,17 @@ initIconBundle(addIcon)interface PhotoProps {photo?: PhotoappTitle?: string+ locationPreferredLevel?: string+ locationFallbackOrder?: string}-const { photo, appTitle: appTitleProp } = defineProps<PhotoProps>()+const { photo, appTitle: appTitleProp, locationPreferredLevel, locationFallbackOrder } = defineProps<PhotoProps>()const { $i18n } = useNuxtApp()-const locationLabel = useLocationLabel()+const locationLabel = useLocationLabel(() => ({+ preferredLevel: locationPreferredLevel,+ fallbackOrder: locationFallbackOrder,+}))const resolvedAppTitle = computed(() => {if (typeof appTitleProp === 'string' && appTitleProp.length > 0) {diff --git a/app/components/dashboard/LocationMigration.vue b/app/components/dashboard/LocationMigration.vueindex 9b834caf..ba0e4d24 100644--- a/app/components/dashboard/LocationMigration.vue+++ b/app/components/dashboard/LocationMigration.vue@@ -6,11 +6,13 @@ const migrationCount = ref(0)const migrationLoading = ref(false)const migrationError = ref(false)const toast = useToast()+const migrationHandled = useState('location-migration-handled', () => false)async function checkLocationMigration() {- if (!user.value?.isAdmin) return+ if (!user.value?.isAdmin || migrationHandled.value) returntry {const stats = await $fetch('/api/system/stats')+ if (migrationHandled.value) returnmigrationCount.value = stats.locationMigration.countmigrationOpen.value = migrationCount.value > 0} catch (error) {@@ -35,6 +37,7 @@ async function confirmLocationMigration() {method: 'POST',body: { payload: { type: 'location-migration' } },})+ migrationHandled.value = truetoast.add({title: $t('dashboard.locationMigration.queued'),color: 'success',diff --git a/app/composables/useInstanceOpenGraph.ts b/app/composables/useInstanceOpenGraph.tsindex e8d8c4d5..2354aa2b 100644--- a/app/composables/useInstanceOpenGraph.ts+++ b/app/composables/useInstanceOpenGraph.ts@@ -1,4 +1,5 @@import type { ComputedRef } from 'vue'+import { defaultLocationFallback } from '~~/shared/utils/location'/*** Share metadata for this ChronoFrame instance.@@ -18,6 +19,8 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {const appSlogan = useSettingRef('app:slogan')const appAuthor = useSettingRef('app:author')const appAvatar = useSettingRef('app:avatarUrl')+ const locationPreferredLevel = useSettingRef('location:preferredLevel')+ const locationFallbackOrder = useSettingRef('location:fallbackOrder')const { homeView } = useHomeView()const siteName = computed(@@ -107,6 +110,8 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {photo:currentPhoto.value?.id === id ? currentPhoto.value : undefined,appTitle: siteName.value,+ locationPreferredLevel: String(locationPreferredLevel.value || 'city'),+ locationFallbackOrder: String(locationFallbackOrder.value || defaultLocationFallback),},{ alt: shareTitle.value },)@@ -153,6 +158,8 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {slogan,author,avatarUrl,+ locationPreferredLevel,+ locationFallbackOrder,shareTitle,() => i18n?.locale.value,],diff --git a/app/composables/useLocationLabel.ts b/app/composables/useLocationLabel.tsindex 40a74ba4..71f42ee9 100644--- a/app/composables/useLocationLabel.ts+++ b/app/composables/useLocationLabel.ts@@ -1,10 +1,16 @@+import { toValue, type MaybeRefOrGetter } from 'vue'import {resolveLocationLabel,defaultLocationFallback,-} from '~~/shared/utils/location'+} from '../../shared/utils/location.ts'import type { NormalizedLocation } from '~~/shared/types/location'-export function useLocationLabel() {+export function useLocationLabel(+ overrides: MaybeRefOrGetter<{+ preferredLevel?: string+ fallbackOrder?: string+ }> = {},+) {const settings = useSettingsStore()return (photo: {geocoding?: NormalizedLocation | null@@ -12,10 +18,12 @@ export function useLocationLabel() {}) =>resolveLocationLabel(photo,- String(settings.getSetting('location:preferredLevel') || 'city'),- String(- settings.getSetting('location:fallbackOrder') ||- defaultLocationFallback,- ),+ toValue(overrides).preferredLevel ??+ String(settings.getSetting('location:preferredLevel') || 'city'),+ toValue(overrides).fallbackOrder ??+ String(+ settings.getSetting('location:fallbackOrder') ||+ defaultLocationFallback,+ ),).label}diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex e9400c9b..d9c4517c 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -1019,7 +1019,7 @@ const columns = computed<TableColumn<Photo>[]>(() => [)}- const location = [locationLabel(row.original), country].filter(Boolean).join(', ')+ const location = [...new Set([locationLabel(row.original), country].filter(Boolean))].join(', ')return h('span',{diff --git a/tests/location-label.test.ts b/tests/location-label.test.tsnew file mode 100644index 00000000..dcc6e147--- /dev/null+++ b/tests/location-label.test.ts@@ -0,0 +1,57 @@+import assert from 'node:assert/strict'+import test from 'node:test'+import { ref } from 'vue'+import { useLocationLabel } from '../app/composables/useLocationLabel.ts'+import type { NormalizedLocation } from '../shared/types/location.ts'++test('location label overrides survive isolated rendering and retain reactive defaults', () => {+ const previous = Object.getOwnPropertyDescriptor(+ globalThis,+ 'useSettingsStore',+ )+ const settings: Record<string, string> = {+ 'location:preferredLevel': 'city',+ 'location:fallbackOrder': 'country',+ }+ let storeReads = 0+ Object.assign(globalThis, {+ useSettingsStore: () => ({+ getSetting: (key: string) => {+ storeReads+++ return settings[key]+ },+ }),+ })+ const geocoding: NormalizedLocation = {+ version: 1,+ provider: 'nominatim',+ language: 'en',+ components: {+ country: { name: 'Country', sourceField: 'country' },+ city: { name: 'City', sourceField: 'city' },+ district: { name: 'District', sourceField: 'district' },+ },+ }+ try {+ const props = ref({ preferredLevel: 'district', fallbackOrder: 'country' })+ const explicit = useLocationLabel(() => props.value)+ assert.equal(explicit({ geocoding }), 'District')+ props.value.preferredLevel = 'region'+ assert.equal(explicit({ geocoding }), 'Country')+ assert.equal(+ storeReads,+ 0,+ 'explicit OG props must not read missing render-context settings',+ )+ assert.equal(useLocationLabel()({ geocoding }), 'City')+ const partial = useLocationLabel({ preferredLevel: 'region' })+ assert.equal(partial({ geocoding }), 'Country')+ settings['location:fallbackOrder'] = 'district'+ assert.equal(partial({ geocoding }), 'District')+ assert.equal(explicit({ city: 'Legacy city' }), 'Legacy city')+ } finally {+ if (previous)+ Object.defineProperty(globalThis, 'useSettingsStore', previous)+ else Reflect.deleteProperty(globalThis, 'useSettingsStore')+ }+})