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(home): let admins choose photos or albums as the home view

Ahmet Ömer9e43882282b0
diff --git a/app/components/AdminTours.client.vue b/app/components/AdminTours.client.vue
index 508de46d..5c9c2ce8 100644
--- a/app/components/AdminTours.client.vue
+++ b/app/components/AdminTours.client.vue
@@ -5,11 +5,12 @@ const route = useRoute()
const { user } = useUserSession()
const { records, ready, busy, revision, load, update } = useTours()
const settings = useSettingsStore()
+const { photoWallPath } = useHomeView()
const { locale } = useI18n()
let active: Driver | undefined
let generation = 0
const current = computed<TourId | undefined>(() => {
- if (route.path === '/') return 'home'
+ if (route.path === photoWallPath.value) return 'home'
if (route.path === '/dashboard') return 'dashboard'
const name = route.path
.replace('/dashboard/settings/', '')
diff --git a/app/components/album/Listing.vue b/app/components/album/Listing.vue
new file mode 100644
index 00000000..e0cabf41
--- /dev/null
+++ b/app/components/album/Listing.vue
@@ -0,0 +1,435 @@
+<script lang="ts" setup>
+import { motion } from 'motion-v'
+import { getAlbumListState } from '~/utils/albumListState'
+import { sampleWaterfallPhotos } from '~/utils/sampleWaterfallPhotos'
+import type { Album } from '~~/server/utils/db'
+interface AlbumWithPhotos extends Album {
+ photoIds?: string[]
+ hasPassword?: boolean
+}
+const appSlogan = useSettingRef('app:slogan')
+const { homeView, photoWallPath } = useHomeView()
+const { photos } = usePhotos()
+const { loggedIn } = useUserSession()
+const {
+ data: albums,
+ status,
+ refresh,
+} = useAsyncData<AlbumWithPhotos[]>('albums', () => $fetch('/api/albums'), {
+ watch: [],
+})
+
+// 根据登录状态决定是否过滤隐藏的相册
+// 登录用户可以看到所有相册,未登录用户只能看到非隐藏相册
+const visibleAlbums = computed(() => {
+ if (loggedIn.value) {
+ return albums.value || []
+ }
+ return (albums.value || []).filter((album) => !album.isHidden)
+})
+const listState = computed(() =>
+ getAlbumListState(status.value, visibleAlbums.value.length),
+)
+
+// Share one seed between SSR and hydration, and reuse it as photos change.
+const waterfallSeed = useState('album-waterfall-seed', () =>
+ Math.floor(Math.random() * 0x1_0000_0000),
+)
+const waterfallPhotos = computed(() =>
+ sampleWaterfallPhotos(photos.value, waterfallSeed.value),
+)
+const isMobile = useMediaQuery('(max-width: 768px)')
+const waterfallColumnCount = computed(() => (isMobile.value ? 3 : 8))
+const columnDurations = Array.from(
+ { length: 8 },
+ (_, index) => 80 + ((index * 37) % 70),
+)
+
+const columns = computed(() => {
+ const cols: (typeof waterfallPhotos.value)[] = Array.from(
+ { length: waterfallColumnCount.value },
+ () => [],
+ )
+
+ if (waterfallPhotos.value.length === 0) return cols
+
+ const photosPerColumn = 8
+
+ for (let colIndex = 0; colIndex < waterfallColumnCount.value; colIndex++) {
+ for (let i = 0; i < photosPerColumn; i++) {
+ const photoIndex =
+ (colIndex + i * waterfallColumnCount.value) %
+ waterfallPhotos.value.length
+ cols[colIndex]?.push(waterfallPhotos.value[photoIndex]!)
+ }
+ }
+
+ return cols
+})
+
+const getPhotoById = (photoId: string) => {
+ return photos.value.find((p) => p.id === photoId) || null
+}
+
+const getAlbumDisplayPhotos = (album: AlbumWithPhotos) => {
+ if (!album.photoIds || album.photoIds.length === 0) return []
+
+ const displayPhotos: Photo[] = []
+
+ // 第一张:优先使用封面照片
+ if (album.coverPhotoId) {
+ const coverPhoto = getPhotoById(album.coverPhotoId)
+ if (coverPhoto) {
+ displayPhotos.push(coverPhoto)
+ }
+ }
+
+ // 如果没有封面照片或封面照片不存在,使用第一张
+ if (displayPhotos.length === 0 && album.photoIds[0]) {
+ const firstPhoto = getPhotoById(album.photoIds[0])
+ if (firstPhoto) {
+ displayPhotos.push(firstPhoto)
+ }
+ }
+
+ // 添加其他照片(最多3张)
+ for (const photoId of album.photoIds) {
+ if (displayPhotos.length >= 3) break
+ const photo = getPhotoById(photoId)
+ if (photo && !displayPhotos.find((p) => p.id === photo.id)) {
+ displayPhotos.push(photo)
+ }
+ }
+
+ return displayPhotos
+}
+
+// 每张照片的初始位置和悬浮位置
+const getPhotoTransform = (index: number, isHover: boolean) => {
+ if (index === 0) {
+ return {
+ x: 0,
+ y: 0,
+ rotate: 0,
+ }
+ } else if (index === 1) {
+ return isHover
+ ? { x: -20, y: -16, rotate: -8 }
+ : { x: -6, y: -4, rotate: -4 }
+ } else {
+ return isHover ? { x: 28, y: -20, rotate: 10 } : { x: 8, y: -6, rotate: 5 }
+ }
+}
+
+const hoveredAlbum = ref<number | null>(null)
+</script>
+
+<template>
+ <div class="relative min-h-screen">
+ <!-- Animated waterfall area -->
+ <div
+ class="absolute inset-x-0 top-0 h-[30vh] sm:h-[50vh] overflow-hidden -z-10"
+ aria-hidden="true"
+ >
+ <ClientOnly>
+ <div class="absolute inset-0 flex h-full gap-0">
+ <!-- Per column -->
+ <div
+ v-for="(column, colIndex) in columns"
+ :key="colIndex"
+ class="flex-1 relative overflow-hidden select-none"
+ >
+ <div
+ class="flex flex-col"
+ :class="
+ colIndex % 2 === 0 ? 'animate-scroll-down' : 'animate-scroll-up'
+ "
+ :style="{ animationDuration: `${columnDurations[colIndex]}s` }"
+ >
+ <template
+ v-for="groupIndex in 3"
+ :key="groupIndex"
+ >
+ <div
+ v-for="(photo, photoIndex) in column"
+ :key="`${photo.id}-${groupIndex}-${photoIndex}`"
+ class="w-full overflow-hidden"
+ >
+ <ThumbImage
+ class="w-full h-auto object-cover saturate-50"
+ :lazy="false"
+ :src="photo.thumbnailUrl!"
+ :thumbhash="photo.thumbnailHash"
+ :alt="
+ photo.exif?.ImageDescription || $t('ui.photo.altFallback')
+ "
+ :style="{
+ aspectRatio: photo.aspectRatio || 1,
+ }"
+ />
+ </div>
+ </template>
+ </div>
+ </div>
+ </div>
+ </ClientOnly>
+ <!-- Overlay -->
+ <div
+ class="absolute -inset-1 bg-linear-to-b from-neutral-100/80 to-white dark:from-neutral-900/80 dark:to-neutral-900"
+ />
+ </div>
+
+ <div class="absolute p-4">
+ <!-- Photo wall -->
+ <UTooltip
+ :text="
+ homeView === 'albums'
+ ? $t('settings.app.homeView.photos')
+ : $t('ui.action.home.tooltip')
+ "
+ >
+ <UButton
+ variant="ghost"
+ color="neutral"
+ icon="tabler:arrow-left"
+ :label="
+ homeView === 'albums'
+ ? $t('settings.app.homeView.photos')
+ : $t('ui.action.home.tooltip')
+ "
+ size="sm"
+ :to="photoWallPath"
+ />
+ </UTooltip>
+ </div>
+
+ <!-- Titles -->
+ <div class="flex flex-col items-center pt-16 sm:pt-48 pb-24">
+ <h1
+ class="font-black text-6xl sm:text-7xl drop-shadow-2xl bg-clip-text bg-linear-to-br from-neutral-800 to-neutral-400 dark:from-white dark:to-neutral-500 text-transparent"
+ >
+ {{ $t('title.albums').toUpperCase() }}
+ </h1>
+ <p
+ class="mt-2 text-lg text-neutral-600 dark:text-neutral-400 font-medium font-[Pacifico]"
+ >
+ {{ appSlogan }}
+ </p>
+ </div>
+
+ <!-- Albums Grid -->
+ <div class="container mx-auto px-10 sm:px-6 lg:px-8 py-12">
+ <div
+ v-if="listState === 'loading'"
+ role="status"
+ aria-live="polite"
+ class="min-h-48 flex flex-col items-center justify-center gap-3 text-center"
+ >
+ <Icon
+ name="tabler:loader-2"
+ class="size-10 animate-spin text-neutral-400 dark:text-neutral-500"
+ aria-hidden="true"
+ />
+ <p class="text-neutral-600 dark:text-neutral-400">
+ {{ $t('album.list.loading') }}
+ </p>
+ </div>
+ <div
+ v-else-if="listState === 'empty'"
+ role="status"
+ aria-live="polite"
+ class="min-h-48 flex flex-col items-center justify-center gap-3 text-center"
+ >
+ <Icon
+ name="tabler:library-photo"
+ class="size-10 text-neutral-400 dark:text-neutral-500"
+ aria-hidden="true"
+ />
+ <h2
+ class="text-xl font-semibold text-neutral-800 dark:text-neutral-200"
+ >
+ {{ $t('album.list.emptyTitle') }}
+ </h2>
+ <p class="text-sm text-neutral-600 dark:text-neutral-400">
+ {{ $t('album.list.emptyDescription') }}
+ </p>
+ </div>
+ <div
+ v-else-if="listState === 'error'"
+ role="alert"
+ class="min-h-48 flex flex-col items-center justify-center gap-3 text-center"
+ >
+ <Icon
+ name="tabler:alert-circle"
+ class="size-10 text-error-500"
+ aria-hidden="true"
+ />
+ <h2
+ class="text-xl font-semibold text-neutral-800 dark:text-neutral-200"
+ >
+ {{ $t('album.list.errorTitle') }}
+ </h2>
+ <p class="text-sm text-neutral-600 dark:text-neutral-400">
+ {{ $t('album.list.errorDescription') }}
+ </p>
+ <UButton
+ type="button"
+ color="neutral"
+ variant="soft"
+ icon="tabler:refresh"
+ class="mt-2"
+ @click="refresh()"
+ >
+ {{ $t('album.list.retry') }}
+ </UButton>
+ </div>
+ <div
+ v-else
+ class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-16"
+ >
+ <NuxtLink
+ v-for="album in visibleAlbums"
+ :key="album.id"
+ :to="`/albums/${album.id}`"
+ class="block"
+ @mouseenter="hoveredAlbum = album.id"
+ @mouseleave="hoveredAlbum = null"
+ >
+ <!-- Stacked Photos Card -->
+ <div class="relative h-48 mb-4 group">
+ <!-- Photo Stack (3 layers) -->
+ <motion.div
+ v-for="(photo, index) in getAlbumDisplayPhotos(album)"
+ :key="photo.id"
+ class="absolute inset-0 rounded-xl shadow-lg overflow-hidden bg-white dark:bg-neutral-800"
+ :initial="{
+ x: getPhotoTransform(index, false).x,
+ y: getPhotoTransform(index, false).y,
+ rotate: getPhotoTransform(index, false).rotate,
+ opacity: 1 - index * 0.12,
+ }"
+ :animate="{
+ x: getPhotoTransform(index, hoveredAlbum === album.id).x,
+ y: getPhotoTransform(index, hoveredAlbum === album.id).y,
+ rotate: getPhotoTransform(index, hoveredAlbum === album.id)
+ .rotate,
+ opacity: hoveredAlbum === album.id ? 1 : 1 - index * 0.12,
+ }"
+ :transition="{
+ type: 'spring',
+ stiffness: 300,
+ damping: 30,
+ mass: 0.8,
+ }"
+ :style="{
+ zIndex: 3 - index,
+ }"
+ >
+ <ThumbImage
+ class="w-full h-full object-cover"
+ :src="photo.thumbnailUrl!"
+ :thumbhash="photo.thumbnailHash"
+ :alt="album.title"
+ :style="{
+ aspectRatio: photo.aspectRatio || 1,
+ }"
+ />
+ <!-- Overlay for stacked cards -->
+ <motion.div
+ v-if="index > 0"
+ class="absolute inset-0 bg-black/10 dark:bg-black/30"
+ :initial="{ opacity: 1 }"
+ :animate="{ opacity: hoveredAlbum === album.id ? 0 : 1 }"
+ :transition="{ duration: 0.3 }"
+ />
+ </motion.div>
+
+ <!-- Empty state -->
+ <div
+ v-if="!album.photoIds || album.photoIds.length === 0"
+ class="absolute inset-0 rounded-xl shadow-lg bg-linear-to-br from-neutral-100 to-neutral-50 dark:from-neutral-700 dark:to-neutral-800 flex flex-col items-center justify-center gap-3 border border-neutral-200 dark:border-neutral-600 group-hover:shadow-xl dark:group-hover:shadow-neutral-900/50 transition-shadow"
+ >
+ <Icon
+ :name="
+ album.hasPassword ? 'tabler:lock' : 'tabler:library-photo'
+ "
+ class="size-10 text-neutral-400 dark:text-neutral-500"
+ />
+ <div class="text-center">
+ <p
+ class="text-sm font-medium text-neutral-700 dark:text-neutral-300"
+ >
+ {{
+ album.hasPassword
+ ? $t('album.passwordRequired')
+ : $t('ui.album.noImage')
+ }}
+ </p>
+ <!-- <p class="text-xs text-neutral-500 dark:text-neutral-400 mt-1">
+ {{ $t('ui.album.emptyAlbumTip') }}
+ </p> -->
+ </div>
+ </div>
+ </div>
+
+ <!-- Album Info -->
+ <div class="px-2">
+ <div class="flex flex-col gap-0">
+ <h2
+ class="truncate text-lg font-semibold text-neutral-800 dark:text-neutral-200 transition-colors"
+ :class="{
+ 'text-primary-600 dark:text-primary-400':
+ hoveredAlbum === album.id,
+ }"
+ >
+ {{ album.title }}
+ </h2>
+ <p
+ class="text-sm text-neutral-600 dark:text-neutral-400 line-clamp-2"
+ >
+ {{ album.description || $t('ui.album.noDescription') }}
+ </p>
+ <p
+ class="mt-1 flex items-center justify-start gap-0.5 text-sm text-neutral-600 dark:text-neutral-400"
+ >
+ <Icon
+ name="tabler:clock"
+ class="h-lh size-4"
+ />
+ {{ $dayjs(album.createdAt).fromNow() }}
+ </p>
+ </div>
+ </div>
+ </NuxtLink>
+ </div>
+ </div>
+ </div>
+</template>
+
+<style scoped>
+@keyframes scroll-down {
+ 0% {
+ transform: translateY(0);
+ }
+ 100% {
+ transform: translateY(calc(-100% / 3));
+ }
+}
+
+@keyframes scroll-up {
+ 0% {
+ transform: translateY(calc(-100% / 3));
+ }
+ 100% {
+ transform: translateY(0);
+ }
+}
+
+.animate-scroll-down {
+ animation: scroll-down linear infinite;
+}
+
+.animate-scroll-up {
+ animation: scroll-up linear infinite;
+}
+</style>
diff --git a/app/components/masonry/Root.vue b/app/components/masonry/Root.vue
index 3529eb36..20527bde 100644
--- a/app/components/masonry/Root.vue
+++ b/app/components/masonry/Root.vue
@@ -11,6 +11,7 @@ const props = withDefaults(defineProps<Props>(), {
const dayjs = useDayjs()
const router = useRouter()
+const route = useRoute()
const { filteredPhotos, hasActiveFilters } = usePhotoFilters()
const { sortedPhotos } = usePhotoSort()
@@ -19,7 +20,8 @@ const displayPhotos = computed(() => {
return hasActiveFilters.value ? filteredPhotos.value : sortedPhotos.value
})
-const { currentPhotoIndex, isViewerOpen } = storeToRefs(useViewerState())
+const viewer = useViewerState()
+const { currentPhotoIndex, isViewerOpen } = storeToRefs(viewer)
const FIRST_SCREEN_ITEMS_COUNT = 50
const MASONRY_GAP = 4
@@ -327,7 +329,11 @@ onUnmounted(() => {
})
const handleOpenViewer = (index: number) => {
- router.push(`/${displayPhotos.value[index]?.id}`)
+ const photo = displayPhotos.value[index]
+ if (!photo) return
+
+ viewer.openViewer(index, route.path, displayPhotos.value)
+ router.push(`/${photo.id}`)
}
const scrollToPhoto = (photoIndex: number) => {
diff --git a/app/components/masonry/item/Header.vue b/app/components/masonry/item/Header.vue
index 56f776e4..a2a067a1 100644
--- a/app/components/masonry/item/Header.vue
+++ b/app/components/masonry/item/Header.vue
@@ -13,7 +13,6 @@ defineProps<{
}>()
const router = useRouter()
-// const config = useRuntimeConfig()
const colorMode = useColorMode()
const isDark = computed({
@@ -32,6 +31,7 @@ const handleOpenLogin = () => {
const { hasActiveFilters, selectedCounts } = usePhotoFilters()
const { currentSortIcon, currentSortOption } = usePhotoSort()
+const { albumListPath } = useHomeView()
const totalSelectedFilters = computed(() => {
return Object.values(selectedCounts.value).reduce(
@@ -131,7 +131,7 @@ const isRepoLinkHovering = ref(false)
class="bg-transparent rounded-full cursor-pointer"
icon="tabler:photo"
size="sm"
- to="/albums"
+ :to="albumListPath"
/>
</UTooltip>
<UPopover>
diff --git a/app/composables/useHomeView.ts b/app/composables/useHomeView.ts
new file mode 100644
index 00000000..4a586d0b
--- /dev/null
+++ b/app/composables/useHomeView.ts
@@ -0,0 +1,16 @@
+export function useHomeView() {
+ const preference = useSettingRef('app:homeView')
+ const homeView = computed(() =>
+ preference.value === 'albums' ? 'albums' : 'photos',
+ )
+
+ return {
+ homeView,
+ photoWallPath: computed(() =>
+ homeView.value === 'albums' ? '/photos' : '/',
+ ),
+ albumListPath: computed(() =>
+ homeView.value === 'albums' ? '/' : '/albums',
+ ),
+ }
+}
diff --git a/app/composables/useInstanceOpenGraph.ts b/app/composables/useInstanceOpenGraph.ts
index abf80532..e8d8c4d5 100644
--- a/app/composables/useInstanceOpenGraph.ts
+++ b/app/composables/useInstanceOpenGraph.ts
@@ -18,6 +18,7 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {
const appSlogan = useSettingRef('app:slogan')
const appAuthor = useSettingRef('app:author')
const appAvatar = useSettingRef('app:avatarUrl')
+ const { homeView } = useHomeView()
const siteName = computed(
() => cleanShareText(appTitle.value, 80) || 'ChronoFrame',
@@ -37,7 +38,7 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {
? photos.value.find((photo) => photo.id === photoId.value)
: undefined,
)
- const isHome = computed(() => route.path === '/')
+ const isHome = computed(() => route.path === '/' || route.path === '/photos')
// Logged-in visitors load every photo, including hidden ones. The public
// preview must keep using the anonymous collection.
@@ -69,9 +70,16 @@ export async function useInstanceOpenGraph(photos: ComputedRef<Photo[]>) {
undefined
)
})
- const canonicalUrl = computed(
- () => new URL(route.path, requestURL.origin).href,
- )
+ const canonicalUrl = computed(() => {
+ const path =
+ (homeView.value === 'albums' && route.path === '/albums') ||
+ (homeView.value === 'photos' && route.path === '/photos')
+ ? '/'
+ : route.path
+ return new URL(path, requestURL.origin).href
+ })
+
+ useHead({ link: [{ rel: 'canonical', href: canonicalUrl }] })
useSeoMeta({
description: shareDescription,
diff --git a/app/layouts/masonry.vue b/app/layouts/masonry.vue
index 7a22461e..bf250c63 100644
--- a/app/layouts/masonry.vue
+++ b/app/layouts/masonry.vue
@@ -4,6 +4,25 @@ useHead({
})
const { photos } = usePhotos()
+const route = useRoute()
+const router = useRouter()
+const { clearAllFilters, toggleFilter } = usePhotoFilters()
+
+watch(
+ () => route.query.tag,
+ (tag) => {
+ if (typeof tag !== 'string' || !['/', '/photos'].includes(route.path))
+ return
+
+ clearAllFilters()
+ toggleFilter('tags', tag)
+ router.replace({
+ path: route.path,
+ query: { ...route.query, tag: undefined },
+ })
+ },
+ { immediate: true },
+)
</script>
<template>
diff --git a/app/middleware/home-tag-redirect.ts b/app/middleware/home-tag-redirect.ts
new file mode 100644
index 00000000..48a8062a
--- /dev/null
+++ b/app/middleware/home-tag-redirect.ts
@@ -0,0 +1,8 @@
+export default defineNuxtRouteMiddleware((to) => {
+ const settings = useSettingsStore()
+ const showAlbums = settings.getSetting('app:homeView') === 'albums'
+
+ if (showAlbums && typeof to.query.tag === 'string') {
+ return navigateTo({ path: '/photos', query: to.query })
+ }
+})
diff --git a/app/pages/[...slug].vue b/app/pages/[...slug].vue
index 165bcdb3..c6ae1047 100644
--- a/app/pages/[...slug].vue
+++ b/app/pages/[...slug].vue
@@ -6,7 +6,6 @@ definePageMeta({
})
const route = useRoute()
-const router = useRouter()
const { switchToIndex, closeViewer, openViewer } = useViewerState()
const { isViewerOpen, scopedPhotos } = storeToRefs(useViewerState())
@@ -16,23 +15,6 @@ const { photos } = usePhotos()
const slug = computed(() => (route.params.slug as string[]) || [])
const photoId = computed(() => slug.value[0] || null)
-// 处理标签查询参数
-const { clearAllFilters, toggleFilter } = usePhotoFilters()
-
-// 监听路由查询参数中的标签
-watch(
- () => route.query.tag,
- (tagParam) => {
- if (tagParam && typeof tagParam === 'string' && !photoId.value) {
- clearAllFilters()
- toggleFilter('tags', tagParam)
-
- router.replace('/')
- }
- },
- { immediate: true },
-)
-
watch(
[photoId, photos],
([currentPhotoId, globalPhotos]) => {
@@ -72,6 +54,8 @@ watch(
},
{ immediate: true },
)
+
+onBeforeRouteLeave(() => closeViewer())
</script>
<template>
diff --git a/app/pages/albums/[albumId].vue b/app/pages/albums/[albumId].vue
index 0d2fc8da..f0550ac0 100644
--- a/app/pages/albums/[albumId].vue
+++ b/app/pages/albums/[albumId].vue
@@ -4,6 +4,7 @@ import { motion } from 'motion-v'
const route = useRoute()
const router = useRouter()
const dayjs = useDayjs()
+const { albumListPath } = useHomeView()
const albumId = computed(() => {
const id = route.params.albumId as string
@@ -184,7 +185,7 @@ const handleScroll = () => {
}
const goBackToAlbums = () => {
- router.push('/albums')
+ router.push(albumListPath.value)
}
onMounted(() => {
@@ -202,7 +203,7 @@ useHead({
</script>
<template>
- <div class="relative w-full">
+ <div class="relative min-h-screen w-full">
<div
v-if="pending && !isUnlocking"
class="flex flex-col items-center justify-center min-h-[50vh] gap-4"
diff --git a/app/pages/albums/index.vue b/app/pages/albums/index.vue
index 06e1b5ae..77daf6ba 100644
--- a/app/pages/albums/index.vue
+++ b/app/pages/albums/index.vue
@@ -1,354 +1,3 @@
-<script lang="ts" setup>
-import { motion } from 'motion-v'
-import type { Album } from '~~/server/utils/db'
-interface AlbumWithPhotos extends Album {
- photoIds?: string[]
- hasPassword?: boolean
-}
-const appSlogan = useSettingRef('app:slogan')
-const { photos } = usePhotos()
-const { loggedIn } = useUserSession()
-const { data: albums } = useAsyncData<AlbumWithPhotos[]>(
- 'albums',
- () => $fetch('/api/albums'),
- {
- watch: [],
- },
-)
-
-// 根据登录状态决定是否过滤隐藏的相册
-// 登录用户可以看到所有相册,未登录用户只能看到非隐藏相册
-const visibleAlbums = computed(() => {
- if (loggedIn.value) {
- return albums.value || []
- }
- return (albums.value || []).filter((album) => !album.isHidden)
-})
-
-// randomly pick 30 photos for waterfall
-const waterfallPhotos = computed(() =>
- photos.value.toSorted(() => 0.5 - Math.random()).slice(0, 30),
-)
-const isMobile = useMediaQuery('(max-width: 768px)')
-
-const waterfallColumnCount = computed(() => (isMobile.value ? 3 : 8))
-const columnDurations = ref<number[]>([])
-
-onMounted(() => {
- columnDurations.value = Array.from(
- { length: waterfallColumnCount.value },
- () => {
- // Base duration 120s, random offset -60 to +30s
- return 120 + (Math.random() * 90 - 60)
- },
- )
-})
-
-const columns = computed(() => {
- const cols: (typeof waterfallPhotos.value)[] = Array.from(
- { length: waterfallColumnCount.value },
- () => [],
- )
-
- if (waterfallPhotos.value.length === 0) return cols
-
- const photosPerColumn = 8
-
- for (let colIndex = 0; colIndex < waterfallColumnCount.value; colIndex++) {
- for (let i = 0; i < photosPerColumn; i++) {
- const photoIndex =
- (colIndex + i * waterfallColumnCount.value) %
- waterfallPhotos.value.length
- cols[colIndex]?.push(waterfallPhotos.value[photoIndex]!)
- }
- }
-
- return cols
-})
-
-const getPhotoById = (photoId: string) => {
- return photos.value.find((p) => p.id === photoId) || null
-}
-
-const getAlbumDisplayPhotos = (album: AlbumWithPhotos) => {
- if (!album.photoIds || album.photoIds.length === 0) return []
-
- const displayPhotos: Photo[] = []
-
- // 第一张:优先使用封面照片
- if (album.coverPhotoId) {
- const coverPhoto = getPhotoById(album.coverPhotoId)
- if (coverPhoto) {
- displayPhotos.push(coverPhoto)
- }
- }
-
- // 如果没有封面照片或封面照片不存在,使用第一张
- if (displayPhotos.length === 0 && album.photoIds[0]) {
- const firstPhoto = getPhotoById(album.photoIds[0])
- if (firstPhoto) {
- displayPhotos.push(firstPhoto)
- }
- }
-
- // 添加其他照片(最多3张)
- for (const photoId of album.photoIds) {
- if (displayPhotos.length >= 3) break
- const photo = getPhotoById(photoId)
- if (photo && !displayPhotos.find((p) => p.id === photo.id)) {
- displayPhotos.push(photo)
- }
- }
-
- return displayPhotos
-}
-
-// 每张照片的初始位置和悬浮位置
-const getPhotoTransform = (index: number, isHover: boolean) => {
- if (index === 0) {
- return {
- x: 0,
- y: 0,
- rotate: 0,
- }
- } else if (index === 1) {
- return isHover
- ? { x: -20, y: -16, rotate: -8 }
- : { x: -6, y: -4, rotate: -4 }
- } else {
- return isHover ? { x: 28, y: -20, rotate: 10 } : { x: 8, y: -6, rotate: 5 }
- }
-}
-
-const hoveredAlbum = ref<number | null>(null)
-</script>
-
<template>
- <div class="relative">
- <!-- Animated waterfall area -->
- <div
- class="absolute inset-x-0 top-0 h-[30vh] sm:h-[50vh] overflow-hidden -z-10"
- >
- <div class="absolute inset-0 flex h-full gap-0">
- <!-- Per column -->
- <div
- v-for="(column, colIndex) in columns"
- :key="colIndex"
- class="flex-1 relative overflow-hidden select-none"
- >
- <div
- class="flex flex-col"
- :class="
- colIndex % 2 === 0 ? 'animate-scroll-down' : 'animate-scroll-up'
- "
- :style="{
- animationDuration: columnDurations[colIndex]
- ? `${columnDurations[colIndex]}s`
- : '200s',
- }"
- >
- <template
- v-for="groupIndex in 3"
- :key="groupIndex"
- >
- <div
- v-for="(photo, photoIndex) in column"
- :key="`${photo.id}-${groupIndex}-${photoIndex}`"
- class="w-full overflow-hidden"
- >
- <ClientOnly>
- <ThumbImage
- class="w-full h-auto object-cover saturate-50"
- :lazy="false"
- :src="photo.thumbnailUrl!"
- :thumbhash="photo.thumbnailHash"
- :alt="photo.exif?.ImageDescription || $t('ui.photo.altFallback')"
- :style="{
- aspectRatio: photo.aspectRatio || 1,
- }"
- />
- </ClientOnly>
- </div>
- </template>
- </div>
- </div>
- </div>
- <!-- Overlay -->
- <div
- class="absolute -inset-1 bg-linear-to-b from-neutral-100/80 to-white dark:from-neutral-900/80 dark:to-neutral-900"
- />
- </div>
-
- <div class="absolute p-4">
- <!-- Back to home -->
- <UTooltip :text="$t('ui.action.home.tooltip')">
- <UButton
- variant="ghost"
- color="neutral"
- icon="tabler:arrow-left"
- :label="$t('ui.action.home.tooltip')"
- size="sm"
- to="/"
- />
- </UTooltip>
- </div>
-
- <!-- Titles -->
- <div class="flex flex-col items-center pt-16 sm:pt-48 pb-24">
- <h1
- class="font-black text-6xl sm:text-7xl drop-shadow-2xl bg-clip-text bg-linear-to-br from-neutral-800 to-neutral-400 dark:from-white dark:to-neutral-500 text-transparent"
- >
- {{ $t('title.albums').toUpperCase() }}
- </h1>
- <p
- class="mt-2 text-lg text-neutral-600 dark:text-neutral-400 font-medium font-[Pacifico]"
- >
- {{ appSlogan }}
- </p>
- </div>
-
- <!-- Albums Grid -->
- <div class="container mx-auto px-10 sm:px-6 lg:px-8 py-12">
- <div
- class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-16"
- >
- <NuxtLink
- v-for="album in visibleAlbums"
- :key="album.id"
- :to="`/albums/${album.id}`"
- class="block"
- @mouseenter="hoveredAlbum = album.id"
- @mouseleave="hoveredAlbum = null"
- >
- <!-- Stacked Photos Card -->
- <div class="relative h-48 mb-4 group">
- <!-- Photo Stack (3 layers) -->
- <motion.div
- v-for="(photo, index) in getAlbumDisplayPhotos(album)"
- :key="photo.id"
- class="absolute inset-0 rounded-xl shadow-lg overflow-hidden bg-white dark:bg-neutral-800"
- :initial="{
- x: getPhotoTransform(index, false).x,
- y: getPhotoTransform(index, false).y,
- rotate: getPhotoTransform(index, false).rotate,
- opacity: 1 - index * 0.12,
- }"
- :animate="{
- x: getPhotoTransform(index, hoveredAlbum === album.id).x,
- y: getPhotoTransform(index, hoveredAlbum === album.id).y,
- rotate: getPhotoTransform(index, hoveredAlbum === album.id)
- .rotate,
- opacity: hoveredAlbum === album.id ? 1 : 1 - index * 0.12,
- }"
- :transition="{
- type: 'spring',
- stiffness: 300,
- damping: 30,
- mass: 0.8,
- }"
- :style="{
- zIndex: 3 - index,
- }"
- >
- <ThumbImage
- class="w-full h-full object-cover"
- :src="photo.thumbnailUrl!"
- :thumbhash="photo.thumbnailHash"
- :alt="album.title"
- :style="{
- aspectRatio: photo.aspectRatio || 1,
- }"
- />
- <!-- Overlay for stacked cards -->
- <motion.div
- v-if="index > 0"
- class="absolute inset-0 bg-black/10 dark:bg-black/30"
- :initial="{ opacity: 1 }"
- :animate="{ opacity: hoveredAlbum === album.id ? 0 : 1 }"
- :transition="{ duration: 0.3 }"
- />
- </motion.div>
-
- <!-- Empty state -->
- <div
- v-if="!album.photoIds || album.photoIds.length === 0"
- class="absolute inset-0 rounded-xl shadow-lg bg-linear-to-br from-neutral-100 to-neutral-50 dark:from-neutral-700 dark:to-neutral-800 flex flex-col items-center justify-center gap-3 border border-neutral-200 dark:border-neutral-600 group-hover:shadow-xl dark:group-hover:shadow-neutral-900/50 transition-shadow"
- >
- <Icon
- :name="album.hasPassword ? 'tabler:lock' : 'tabler:library-photo'"
- class="size-10 text-neutral-400 dark:text-neutral-500"
- />
- <div class="text-center">
- <p
- class="text-sm font-medium text-neutral-700 dark:text-neutral-300"
- >
- {{ album.hasPassword ? $t('album.passwordRequired') : $t('ui.album.noImage') }}
- </p>
- <!-- <p class="text-xs text-neutral-500 dark:text-neutral-400 mt-1">
- {{ $t('ui.album.emptyAlbumTip') }}
- </p> -->
- </div>
- </div>
- </div>
-
- <!-- Album Info -->
- <div class="px-2">
- <div class="flex flex-col gap-0">
- <h2
- class="truncate text-lg font-semibold text-neutral-800 dark:text-neutral-200 transition-colors"
- :class="{
- 'text-primary-600 dark:text-primary-400':
- hoveredAlbum === album.id,
- }"
- >
- {{ album.title }}
- </h2>
- <p
- class="text-sm text-neutral-600 dark:text-neutral-400 line-clamp-2"
- >
- {{ album.description || $t('ui.album.noDescription') }}
- </p>
- <p
- class="mt-1 flex items-center justify-start gap-0.5 text-sm text-neutral-600 dark:text-neutral-400"
- >
- <Icon
- name="tabler:clock"
- class="h-lh size-4"
- />
- {{ $dayjs(album.createdAt).fromNow() }}
- </p>
- </div>
- </div>
- </NuxtLink>
- </div>
- </div>
- </div>
+ <AlbumListing />
</template>
-
-<style scoped>
-@keyframes scroll-down {
- 0% {
- transform: translateY(0);
- }
- 100% {
- transform: translateY(calc(-100% / 3));
- }
-}
-
-@keyframes scroll-up {
- 0% {
- transform: translateY(calc(-100% / 3));
- }
- 100% {
- transform: translateY(0);
- }
-}
-
-.animate-scroll-down {
- animation: scroll-down linear infinite;
-}
-
-.animate-scroll-up {
- animation: scroll-up linear infinite;
-}
-</style>
diff --git a/app/pages/index.vue b/app/pages/index.vue
new file mode 100644
index 00000000..ae81ebc3
--- /dev/null
+++ b/app/pages/index.vue
@@ -0,0 +1,17 @@
+<script setup lang="ts">
+definePageMeta({
+ middleware: 'home-tag-redirect',
+})
+
+const { homeView } = useHomeView()
+</script>
+
+<template>
+ <AlbumListing v-if="homeView === 'albums'" />
+ <NuxtLayout
+ v-else
+ name="masonry"
+ >
+ <div />
+ </NuxtLayout>
+</template>
diff --git a/app/pages/photos.vue b/app/pages/photos.vue
new file mode 100644
index 00000000..6310b7e0
--- /dev/null
+++ b/app/pages/photos.vue
@@ -0,0 +1,9 @@
+<script setup lang="ts">
+definePageMeta({ layout: 'masonry' })
+
+useHead({ title: () => $t('settings.app.homeView.photos') })
+</script>
+
+<template>
+ <div />
+</template>
diff --git a/app/router.options.ts b/app/router.options.ts
index 8882f4be..5d38fce0 100644
--- a/app/router.options.ts
+++ b/app/router.options.ts
@@ -6,7 +6,11 @@ export default <RouterConfig>{
return savedPosition
}
- if (from.path === '/' || to.name === 'slug') {
+ if (to.name === 'slug') {
+ return false
+ }
+
+ if (from.name === 'slug' && (to.path === '/photos' || to.path === '/')) {
return false
}
diff --git a/app/utils/albumListState.test.ts b/app/utils/albumListState.test.ts
new file mode 100644
index 00000000..9a6a561b
--- /dev/null
+++ b/app/utils/albumListState.test.ts
@@ -0,0 +1,19 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import { getAlbumListState } from './albumListState.ts'
+
+test('shows loading until the album request completes, including during retry', () => {
+ assert.equal(getAlbumListState('idle', 0), 'loading')
+ assert.equal(getAlbumListState('pending', 0), 'loading')
+ assert.equal(getAlbumListState('pending', 2), 'loading')
+})
+
+test('distinguishes a successful empty result from visible albums', () => {
+ assert.equal(getAlbumListState('success', 0), 'empty')
+ assert.equal(getAlbumListState('success', 2), 'ready')
+})
+
+test('shows failure even when stale album data remains available', () => {
+ assert.equal(getAlbumListState('error', 0), 'error')
+ assert.equal(getAlbumListState('error', 2), 'error')
+})
diff --git a/app/utils/albumListState.ts b/app/utils/albumListState.ts
new file mode 100644
index 00000000..c46419c2
--- /dev/null
+++ b/app/utils/albumListState.ts
@@ -0,0 +1,10 @@
+type AlbumListRequestStatus = 'idle' | 'pending' | 'success' | 'error'
+
+export function getAlbumListState(
+ status: AlbumListRequestStatus,
+ visibleAlbumCount: number,
+): 'loading' | 'empty' | 'error' | 'ready' {
+ if (status === 'pending' || status === 'idle') return 'loading'
+ if (status === 'error') return 'error'
+ return visibleAlbumCount === 0 ? 'empty' : 'ready'
+}
diff --git a/app/utils/sampleWaterfallPhotos.test.ts b/app/utils/sampleWaterfallPhotos.test.ts
new file mode 100644
index 00000000..68062630
--- /dev/null
+++ b/app/utils/sampleWaterfallPhotos.test.ts
@@ -0,0 +1,57 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import { sampleWaterfallPhotos } from './sampleWaterfallPhotos.ts'
+
+test('selects at most 30 unique photos without mutating the collection', () => {
+ const photos = Array.from({ length: 100 }, (_, id) => ({ id }))
+ const originalOrder = photos.map((photo) => photo.id)
+
+ const selected = sampleWaterfallPhotos(photos, 12345)
+
+ assert.equal(selected.length, 30)
+ assert.equal(new Set(selected.map((photo) => photo.id)).size, 30)
+ assert.notDeepEqual(
+ selected.map((photo) => photo.id),
+ originalOrder.slice(0, 30),
+ )
+ assert.deepEqual(
+ photos.map((photo) => photo.id),
+ originalOrder,
+ )
+})
+
+test('uses the seed consistently and varies the selection between seeds', () => {
+ const photos = Array.from({ length: 60 }, (_, id) => ({ id }))
+
+ assert.deepEqual(
+ sampleWaterfallPhotos(photos, 12345),
+ sampleWaterfallPhotos(photos, 12345),
+ )
+ assert.notDeepEqual(
+ sampleWaterfallPhotos(photos, 12345),
+ sampleWaterfallPhotos(photos, 67890),
+ )
+})
+
+test('handles empty, small, and changed collections', () => {
+ const photos = Array.from({ length: 12 }, (_, id) => ({ id }))
+
+ assert.deepEqual(sampleWaterfallPhotos([], 12345), [])
+ assert.deepEqual(
+ new Set(sampleWaterfallPhotos(photos, 12345).map((photo) => photo.id)),
+ new Set(photos.map((photo) => photo.id)),
+ )
+
+ const updated = photos.filter((photo) => photo.id !== 3)
+ updated.push({ id: 12 })
+ const selected = sampleWaterfallPhotos(updated, 12345)
+ assert.equal(selected.length, updated.length)
+ assert.equal(
+ selected.some((photo) => photo.id === 3),
+ false,
+ )
+ assert.equal(
+ selected.some((photo) => photo.id === 12),
+ true,
+ )
+})
diff --git a/app/utils/sampleWaterfallPhotos.ts b/app/utils/sampleWaterfallPhotos.ts
new file mode 100644
index 00000000..bc715b43
--- /dev/null
+++ b/app/utils/sampleWaterfallPhotos.ts
@@ -0,0 +1,32 @@
+const MAX_WATERFALL_PHOTOS = 30
+
+function seededRandom(seed: number) {
+ let state = seed
+
+ return () => {
+ state = (state + 0x6d2b79f5) | 0
+ let value = Math.imul(state ^ (state >>> 15), 1 | state)
+ value ^= value + Math.imul(value ^ (value >>> 7), 61 | value)
+ return ((value ^ (value >>> 14)) >>> 0) / 0x1_0000_0000
+ }
+}
+
+export function sampleWaterfallPhotos<T>(
+ photos: readonly T[],
+ seed: number,
+): T[] {
+ const shuffled = [...photos]
+ const count = Math.min(MAX_WATERFALL_PHOTOS, shuffled.length)
+ const random = seededRandom(seed)
+
+ // A partial Fisher-Yates shuffle samples without replacement.
+ for (let index = 0; index < count; index++) {
+ const randomIndex = index + Math.floor(random() * (shuffled.length - index))
+ ;[shuffled[index], shuffled[randomIndex]] = [
+ shuffled[randomIndex]!,
+ shuffled[index]!,
+ ]
+ }
+
+ return shuffled.slice(0, count)
+}
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 906b14d5..fd3c5514 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -165,6 +165,14 @@
}
},
"album": {
+ "list": {
+ "loading": "Loading albums…",
+ "emptyTitle": "No albums to show",
+ "emptyDescription": "Please check back later.",
+ "errorTitle": "Unable to load albums",
+ "errorDescription": "Something went wrong. Please try again.",
+ "retry": "Retry"
+ },
"passwordRequired": "Password required",
"passwordPlaceholder": "Enter album password",
"incorrectPassword": "Incorrect password",
@@ -1188,6 +1196,12 @@
"invalidType": "Please choose a PNG, JPEG, WebP, or GIF image",
"tooLarge": "Image must be smaller than {size}MB"
},
+ "homeView": {
+ "label": "Home page",
+ "description": "Choose what visitors see at the site root",
+ "photos": "Photo wall",
+ "albums": "Albums"
+ },
"appearance": {
"theme": {
"label": "Theme",
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index de0f5fa9..4f31c427 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -165,6 +165,14 @@
}
},
"album": {
+ "list": {
+ "loading": "アルバムを読み込み中…",
+ "emptyTitle": "表示できるアルバムがありません",
+ "emptyDescription": "また後でご確認ください。",
+ "errorTitle": "アルバムを読み込めませんでした",
+ "errorDescription": "問題が発生しました。もう一度お試しください。",
+ "retry": "再試行"
+ },
"passwordRequired": "パスワードが必要です",
"passwordPlaceholder": "アルバムのパスワードを入力",
"incorrectPassword": "パスワードが正しくありません",
@@ -1113,6 +1121,12 @@
"invalidType": "PNG、JPEG、WebP、または GIF 画像を選択してください",
"tooLarge": "画像は {size}MB 未満である必要があります"
},
+ "homeView": {
+ "label": "ホームページ",
+ "description": "サイトのトップページに表示する内容を選択",
+ "photos": "写真一覧",
+ "albums": "アルバム"
+ },
"appearance": {
"theme": {
"label": "テーマ",
diff --git a/i18n/locales/ru.json b/i18n/locales/ru.json
index 384869d2..c4eac1fd 100644
--- a/i18n/locales/ru.json
+++ b/i18n/locales/ru.json
@@ -165,6 +165,14 @@
}
},
"album": {
+ "list": {
+ "loading": "Загрузка альбомов…",
+ "emptyTitle": "Нет доступных альбомов",
+ "emptyDescription": "Загляните позже.",
+ "errorTitle": "Не удалось загрузить альбомы",
+ "errorDescription": "Произошла ошибка. Попробуйте ещё раз.",
+ "retry": "Повторить"
+ },
"passwordRequired": "Требуется пароль",
"passwordPlaceholder": "Введите пароль альбома",
"incorrectPassword": "Неверный пароль",
@@ -1188,6 +1196,12 @@
"invalidType": "Выберите изображение PNG, JPEG, WebP или GIF",
"tooLarge": "Размер изображения должен быть меньше {size}МБ"
},
+ "homeView": {
+ "label": "Главная страница",
+ "description": "Выберите, что посетители увидят на главной странице",
+ "photos": "Стена фотографий",
+ "albums": "Альбомы"
+ },
"appearance": {
"theme": {
"label": "Тема",
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index 5a0b3c44..03ba4469 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -179,6 +179,14 @@
}
},
"album": {
+ "list": {
+ "loading": "正在加载相簿…",
+ "emptyTitle": "暂无可显示的相簿",
+ "emptyDescription": "请稍后再来查看。",
+ "errorTitle": "无法加载相簿",
+ "errorDescription": "出现问题,请重试。",
+ "retry": "重试"
+ },
"passwordRequired": "此相簿需要密码",
"passwordPlaceholder": "输入相簿密码",
"incorrectPassword": "密码错误",
@@ -1188,6 +1196,12 @@
"invalidType": "请选择 PNG、JPEG、WebP 或 GIF 图片",
"tooLarge": "图片大小必须小于 {size}MB"
},
+ "homeView": {
+ "label": "首页内容",
+ "description": "选择访客打开网站首页时看到的内容",
+ "photos": "照片墙",
+ "albums": "相册"
+ },
"appearance": {
"theme": {
"label": "主题",
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index 864f3bf0..0b38ac52 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -179,6 +179,14 @@
}
},
"album": {
+ "list": {
+ "loading": "正在載入相簿…",
+ "emptyTitle": "暫無可顯示的相簿",
+ "emptyDescription": "請稍後再嚟睇吓。",
+ "errorTitle": "無法載入相簿",
+ "errorDescription": "發生問題,請再試一次。",
+ "retry": "重試"
+ },
"passwordRequired": "此相簿需要密碼",
"passwordPlaceholder": "輸入相簿密碼",
"incorrectPassword": "密碼錯誤",
@@ -1113,6 +1121,12 @@
"invalidType": "請選擇 PNG、JPEG、WebP 或 GIF 圖片",
"tooLarge": "圖片大小必須小於 {size}MB"
},
+ "homeView": {
+ "label": "首頁內容",
+ "description": "選擇訪客打開網站首頁時見到嘅內容",
+ "photos": "相片牆",
+ "albums": "相簿"
+ },
"appearance": {
"theme": {
"label": "主題",
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index 3fa74244..623b6a8a 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -179,6 +179,14 @@
}
},
"album": {
+ "list": {
+ "loading": "正在載入相簿…",
+ "emptyTitle": "目前沒有可顯示的相簿",
+ "emptyDescription": "請稍後再回來看看。",
+ "errorTitle": "無法載入相簿",
+ "errorDescription": "發生問題,請再試一次。",
+ "retry": "重試"
+ },
"passwordRequired": "此相簿需要密碼",
"passwordPlaceholder": "輸入相簿密碼",
"incorrectPassword": "密碼錯誤",
@@ -1113,6 +1121,12 @@
"invalidType": "請選擇 PNG、JPEG、WebP 或 GIF 圖片",
"tooLarge": "圖片大小必須小於 {size}MB"
},
+ "homeView": {
+ "label": "首頁內容",
+ "description": "選擇訪客開啟網站首頁時看到的內容",
+ "photos": "照片牆",
+ "albums": "相簿"
+ },
"appearance": {
"theme": {
"label": "主題",
diff --git a/server/api/albums/index.get.ts b/server/api/albums/index.get.ts
index 19784a7d..78aa7dd4 100644
--- a/server/api/albums/index.get.ts
+++ b/server/api/albums/index.get.ts
@@ -4,23 +4,38 @@ import { albumAccess } from '../../utils/album-access'
export default eventHandler(async (event) => {
const db = useDB()
const { admin } = await albumAccess(event)
- const restrictedPhotoIds = admin ? new Set<string>() : new Set(
- db.select({ photoId: tables.albumPhotos.photoId })
- .from(tables.albumPhotos)
- .innerJoin(tables.albums, eq(tables.albumPhotos.albumId, tables.albums.id))
- .where(or(eq(tables.albums.isHidden, true), isNotNull(tables.albums.passwordHash)))
- .all().map((row) => row.photoId),
- )
+ const restrictedPhotoIds = admin
+ ? new Set<string>()
+ : new Set(
+ db
+ .select({ photoId: tables.albumPhotos.photoId })
+ .from(tables.albumPhotos)
+ .innerJoin(
+ tables.albums,
+ eq(tables.albumPhotos.albumId, tables.albums.id),
+ )
+ .where(
+ or(
+ eq(tables.albums.isHidden, true),
+ isNotNull(tables.albums.passwordHash),
+ ),
+ )
+ .all()
+ .map((row) => row.photoId),
+ )
// Fetch all albums ordered by position asc (createdAt desc as secondary sort)
const albums = await db
.select()
.from(tables.albums)
.orderBy(asc(tables.albums.position), desc(tables.albums.createdAt))
+ const visibleAlbums = admin
+ ? albums
+ : albums.filter((album) => !album.isHidden)
// 为每个相册获取照片 ID 列表(避免循环引用)
const albumsWithPhotoIds = await Promise.all(
- albums.map(async (album) => {
+ visibleAlbums.map(async (album) => {
const accessible = admin || (!album.isHidden && !album.passwordHash)
const photoIds = await db
.select({
@@ -35,11 +50,17 @@ export default eventHandler(async (event) => {
...album,
passwordHash: undefined,
hasPassword: Boolean(album.passwordHash),
- coverPhotoId: admin || (accessible && !restrictedPhotoIds.has(album.coverPhotoId || ''))
- ? album.coverPhotoId : null,
+ coverPhotoId:
+ admin ||
+ (accessible && !restrictedPhotoIds.has(album.coverPhotoId || ''))
+ ? album.coverPhotoId
+ : null,
// 即使是空相册,也返回空数组而不是 undefined
- photoIds: accessible ? photoIds.map((p) => p.photoId)
- .filter((id) => !restrictedPhotoIds.has(id)) : [],
+ photoIds: accessible
+ ? photoIds
+ .map((p) => p.photoId)
+ .filter((id) => !restrictedPhotoIds.has(id))
+ : [],
}
}),
)
diff --git a/server/services/settings/contants.ts b/server/services/settings/contants.ts
index f18ff906..742142d3 100644
--- a/server/services/settings/contants.ts
+++ b/server/services/settings/contants.ts
@@ -79,6 +79,16 @@ export const DEFAULT_SETTINGS = [
defaultValue: '',
hidden: true,
},
+ {
+ namespace: 'app',
+ key: 'homeView',
+ type: 'string',
+ defaultValue: 'photos',
+ enum: ['photos', 'albums'],
+ label: 'settings.app.homeView.label',
+ description: 'settings.app.homeView.description',
+ isPublic: true,
+ },
{
namespace: 'app',
key: 'appearance.theme',
diff --git a/server/services/settings/ui-config.ts b/server/services/settings/ui-config.ts
index a929d326..ef37f447 100644
--- a/server/services/settings/ui-config.ts
+++ b/server/services/settings/ui-config.ts
@@ -30,6 +30,21 @@ export const APP_SETTINGS_UI: Record<string, FieldUIConfig> = {
placeholder: 'https://example.com/avatar.jpg',
help: 'settings.app.avatarUrl.help',
},
+ homeView: {
+ type: 'tabs',
+ options: [
+ {
+ label: 'settings.app.homeView.photos',
+ value: 'photos',
+ icon: 'tabler:photo',
+ },
+ {
+ label: 'settings.app.homeView.albums',
+ value: 'albums',
+ icon: 'tabler:folders',
+ },
+ ],
+ },
'appearance.theme': {
type: 'tabs',
options: [