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(albums): keep Cloud album routes numeric

Ahmet Ömer7f0f520eabde
diff --git a/packages/console/app/components/ConsoleAlbumDetailsFields.vue b/packages/console/app/components/ConsoleAlbumDetailsFields.vue
index 75e15408..b9866d28 100644
--- a/packages/console/app/components/ConsoleAlbumDetailsFields.vue
+++ b/packages/console/app/components/ConsoleAlbumDetailsFields.vue
@@ -1,6 +1,14 @@
<script setup lang="ts">
+import { ALBUM_SLUG_MAX_LENGTH } from '@chronoframe/contracts/album-slug'
+
+defineProps<{
+ showSlug?: boolean
+ currentSlug?: string
+}>()
+
const title = defineModel<string>('title', { required: true })
const description = defineModel<string>('description', { required: true })
+const slug = defineModel<string>('slug')
</script>
<template>
<div class="space-y-4">
@@ -27,5 +35,25 @@ const description = defineModel<string>('description', { required: true })
:rows="3"
/>
</UFormField>
+
+ <UFormField
+ v-if="showSlug"
+ :label="$t('dashboard.albums.form.slug')"
+ :description="$t('dashboard.albums.form.slugHint')"
+ name="slug"
+ >
+ <UInput
+ v-model="slug"
+ class="w-full"
+ :maxlength="ALBUM_SLUG_MAX_LENGTH"
+ :placeholder="$t('dashboard.albums.form.slugPlaceholder')"
+ />
+ <p
+ v-if="currentSlug"
+ class="mt-1 text-xs text-muted"
+ >
+ {{ $t('dashboard.albums.form.slugCurrent') }}: /albums/{{ currentSlug }}
+ </p>
+ </UFormField>
</div>
</template>
diff --git a/packages/console/app/pages/dashboard/albums.vue b/packages/console/app/pages/dashboard/albums.vue
index 13b962ec..995876fe 100644
--- a/packages/console/app/pages/dashboard/albums.vue
+++ b/packages/console/app/pages/dashboard/albums.vue
@@ -19,6 +19,7 @@ useHead({
})
interface AlbumItem extends Album {
+ slug: string
photoCount?: number
photoIds?: string[]
coverPhoto?: Photo | null
@@ -842,6 +843,9 @@ const columns = computed<any[]>(() => [
<ConsoleAlbumDetailsFields
v-model:title="formData.title"
v-model:description="formData.description"
+ v-model:slug="formData.slug"
+ show-slug
+ :current-slug="currentAlbum?.slug"
/>
<UFormField name="isHidden">
diff --git a/packages/contracts/src/resources.ts b/packages/contracts/src/resources.ts
index 96e530f0..768d8630 100644
--- a/packages/contracts/src/resources.ts
+++ b/packages/contracts/src/resources.ts
@@ -35,7 +35,8 @@ export interface Photo {
export interface Album {
id: number
- slug: string
+ /** Present for Self-hosted albums; Cloud currently uses the numeric ID in URLs. */
+ slug?: string
title: string
description: string | null
coverPhotoId: string | null
diff --git a/packages/gallery/app/components/album/Listing.vue b/packages/gallery/app/components/album/Listing.vue
index 185cb14f..8f547134 100644
--- a/packages/gallery/app/components/album/Listing.vue
+++ b/packages/gallery/app/components/album/Listing.vue
@@ -5,6 +5,7 @@ import { motion } from 'motion-v'
import { getAlbumListState } from '#gallery/utils/albumListState'
import { sampleWaterfallPhotos } from '#gallery/utils/sampleWaterfallPhotos'
import type { Album } from '@chronoframe/contracts/resources'
+import { albumPagePath } from '@chronoframe/gallery/shared/utils/albumPath'
interface AlbumWithPhotos extends Album {
photoIds?: string[]
}
@@ -12,6 +13,7 @@ const appSlogan = useSettingRef('app:slogan')
const { homeView, photoWallPath } = useHomeView()
const { photos } = usePhotos()
const { loggedIn } = useUserSession()
+const useSlugs = useEntryCapabilities().edition === 'self-hosted'
const {
data: albums,
status,
@@ -295,7 +297,7 @@ const hoveredAlbum = ref<number | null>(null)
<NuxtLink
v-for="album in visibleAlbums"
:key="album.id"
- :to="`/albums/${album.slug}`"
+ :to="albumPagePath(album, useSlugs)"
class="block"
@mouseenter="hoveredAlbum = album.id"
@mouseleave="hoveredAlbum = null"
diff --git a/packages/gallery/app/components/photo/InfoPanel.vue b/packages/gallery/app/components/photo/InfoPanel.vue
index e90f4ab5..7acccc45 100644
--- a/packages/gallery/app/components/photo/InfoPanel.vue
+++ b/packages/gallery/app/components/photo/InfoPanel.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { hasValidCoordinates } from '@chronoframe/gallery/shared/utils/location'
+import { albumPagePath } from '@chronoframe/gallery/shared/utils/albumPath'
import { motion } from 'motion-v'
import type { NeededExif } from '../../../shared/types/photo'
import type { KVData } from './KVRenderer.vue'
@@ -14,7 +15,7 @@ interface Props {
interface Album {
id: number
- slug: string
+ slug?: string
title: string
description: string | null
coverPhotoId: string | null
@@ -25,6 +26,7 @@ interface Album {
const dayjs = useDayjs()
const router = useRouter()
const { localizeExif } = useExifLocalization()
+const useSlugs = useEntryCapabilities().edition === 'self-hosted'
const props = defineProps<Props>()
@@ -482,8 +484,8 @@ const onTagClick = (tag: string) => {
})
}
-const onAlbumClick = (albumSlug: string) => {
- window.open(`/albums/${albumSlug}`)
+const onAlbumClick = (album: Album) => {
+ window.open(albumPagePath(album, useSlugs))
}
</script>
@@ -589,7 +591,7 @@ const onAlbumClick = (albumSlug: string) => {
v-for="album in albums"
:key="album.id"
class="p-3 bg-white/5 border border-white/10 rounded-lg cursor-pointer hover:bg-white/10 transition-colors"
- @click="onAlbumClick(album.slug)"
+ @click="onAlbumClick(album)"
>
<p class="text-sm text-white font-medium line-clamp-1">
{{ album.title }}
diff --git a/packages/gallery/app/components/photo/ShareModal.vue b/packages/gallery/app/components/photo/ShareModal.vue
index 9994aede..e60c6b49 100644
--- a/packages/gallery/app/components/photo/ShareModal.vue
+++ b/packages/gallery/app/components/photo/ShareModal.vue
@@ -1,4 +1,6 @@
<script lang="ts" setup>
+import { isAlbumPagePath } from '@chronoframe/gallery/shared/utils/albumPath'
+
interface Props {
isOpen: boolean
photo: Photo
@@ -22,7 +24,7 @@ const { returnRoute } = storeToRefs(useViewerState())
const shareUrl = computed(() => {
if (typeof window !== 'undefined') {
- if (returnRoute.value && /^\/albums\/\d+$/.test(returnRoute.value)) {
+ if (returnRoute.value && isAlbumPagePath(returnRoute.value)) {
return `${window.location.origin}${returnRoute.value}?photo=${encodeURIComponent(props.photo.id)}`
}
return `${window.location.origin}/${props.photo.id}`
diff --git a/packages/gallery/app/pages/albums/[albumId].vue b/packages/gallery/app/pages/albums/[albumId].vue
index 7bf8c3cc..ae6dd5f9 100644
--- a/packages/gallery/app/pages/albums/[albumId].vue
+++ b/packages/gallery/app/pages/albums/[albumId].vue
@@ -2,21 +2,33 @@
const galleryApi = useGalleryApi()
import { motion } from 'motion-v'
+import { numericAlbumId } from '@chronoframe/gallery/shared/utils/albumPath'
const route = useRoute()
const router = useRouter()
const dayjs = useDayjs()
const { user } = useUserSession()
const { albumListPath } = useHomeView()
+const useSlugs = useEntryCapabilities().edition === 'self-hosted'
const albumSegment = computed(() => String(route.params.albumId))
-const { data: resolved, error: resolveError } = await useGalleryFetch<{
- albumId: number
- slug: string
- isCanonical: boolean
-}>(() => `/api/albums/resolve/${encodeURIComponent(albumSegment.value)}`, {
- watch: [albumSegment],
-})
+const { data: resolved, error: resolveError } = useSlugs
+ ? await useGalleryFetch<{
+ albumId: number
+ slug: string
+ isCanonical: boolean
+ }>(() => `/api/albums/resolve/${encodeURIComponent(albumSegment.value)}`, {
+ watch: [albumSegment],
+ })
+ : {
+ data: computed(() => {
+ const id = numericAlbumId(albumSegment.value)
+ return id === null
+ ? null
+ : { albumId: id, slug: String(id), isCanonical: true }
+ }),
+ error: ref(null),
+ }
if (resolveError.value || !resolved.value)
throw createError({ statusCode: 404, statusMessage: $t('album.notFound') })
if (!resolved.value.isCanonical)
diff --git a/packages/gallery/shared/utils/albumPath.ts b/packages/gallery/shared/utils/albumPath.ts
new file mode 100644
index 00000000..e780704b
--- /dev/null
+++ b/packages/gallery/shared/utils/albumPath.ts
@@ -0,0 +1,29 @@
+import {
+ isNumericAlbumPathSegment,
+ isValidAlbumSlug,
+} from '@chronoframe/contracts/album-slug'
+
+export function numericAlbumId(segment: string): number | null {
+ if (!isNumericAlbumPathSegment(segment)) return null
+ const id = Number(segment)
+ return Number.isSafeInteger(id) && id > 0 ? id : null
+}
+
+export function albumPagePath(
+ album: { id: number; slug?: string },
+ useSlugs: boolean,
+): string {
+ if (useSlugs) {
+ if (!album.slug) throw new Error('Album slug is missing')
+ return `/albums/${album.slug}`
+ }
+ return `/albums/${album.id}`
+}
+
+export function isAlbumPagePath(path: string): boolean {
+ const segment = /^\/albums\/([^/?#]+)$/.exec(path)?.[1]
+ return (
+ segment !== undefined &&
+ (isValidAlbumSlug(segment) || numericAlbumId(segment) !== null)
+ )
+}
diff --git a/tests/album-path.test.ts b/tests/album-path.test.ts
new file mode 100644
index 00000000..b0fd8141
--- /dev/null
+++ b/tests/album-path.test.ts
@@ -0,0 +1,24 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import {
+ albumPagePath,
+ isAlbumPagePath,
+ numericAlbumId,
+} from '../packages/gallery/shared/utils/albumPath.ts'
+
+test('album links use slugs only for the self-hosted gallery', () => {
+ const album = { id: 12, slug: 'my-album' }
+ assert.equal(albumPagePath(album, true), '/albums/my-album')
+ assert.equal(albumPagePath(album, false), '/albums/12')
+ assert.throws(() => albumPagePath({ id: 12 }, true))
+})
+
+test('numeric Cloud paths and album share links remain valid', () => {
+ assert.equal(numericAlbumId('0012'), 12)
+ assert.equal(numericAlbumId('12abc'), null)
+ assert.equal(numericAlbumId('0'), null)
+ assert.equal(numericAlbumId('9007199254740992'), null)
+ assert.equal(isAlbumPagePath('/albums/12'), true)
+ assert.equal(isAlbumPagePath('/albums/my-album'), true)
+ assert.equal(isAlbumPagePath('/albums/../photos'), false)
+})
diff --git a/tests/cloud-resource-parity.test.ts b/tests/cloud-resource-parity.test.ts
index 866862d0..e9b5d31c 100644
--- a/tests/cloud-resource-parity.test.ts
+++ b/tests/cloud-resource-parity.test.ts
@@ -8,6 +8,7 @@ import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { createResourceReader } from '@chronoframe/core'
import * as schema from '../packages/database/src/schema.ts'
import { createSqliteResourceRepository } from '../packages/database/src/sqlite-resources.ts'
+import { backfillAlbumSlugs } from '../packages/database/src/album-slugs.ts'
import { createCloudResourceRepository } from '../packages/database/src/cloud-resources.ts'
import { createCloudMediaRepository } from '../packages/database/src/cloud-media.ts'
import { createCloudExecutionRepository } from '../packages/database/src/cloud-execution.ts'
@@ -109,6 +110,7 @@ test('Cloud D1 and Self-hosted SQLite share ordering, visibility and protected-a
{ id: 3, title: 'Locked', passwordHash: 'password', position: 0 },
])
.run()
+ backfillAlbumSlugs(legacy)
for (const a of [
{ id: '1', title: 'Public', position: 2, hidden: 0 },
{ id: '2', title: 'Hidden', position: 1, hidden: 1 },