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(album): albums post/get API and albums page ui
Timothy Yin32aadecb3d10
diff --git a/app/components/masonry/item/Header.vue b/app/components/masonry/item/Header.vueindex 2bd5a7f1..4cb5cea3 100644--- a/app/components/masonry/item/Header.vue+++ b/app/components/masonry/item/Header.vue@@ -126,6 +126,16 @@ const isRepoLinkHovering = ref(false)to="/globe"/></UTooltip>+ <UTooltip :text="$t('ui.action.albums.tooltip')">+ <UButton+ variant="soft"+ color="neutral"+ class="bg-transparent rounded-full cursor-pointer"+ icon="tabler:photo"+ size="sm"+ to="/albums"+ />+ </UTooltip><UPopover><UTooltip :text="$t('ui.action.filter.tooltip')"><UChipdiff --git a/app/components/ui/ThumbImage.vue b/app/components/ui/ThumbImage.vueindex f114deb9..e30b70ee 100644--- a/app/components/ui/ThumbImage.vue+++ b/app/components/ui/ThumbImage.vue@@ -11,6 +11,7 @@ const props = withDefaults(style?: CSSPropertiesthreshold?: number | number[]rootMargin?: string+ lazy?: boolean}>(),{thumbhash: null,@@ -18,6 +19,7 @@ const props = withDefaults(style: undefined,threshold: 0.1,rootMargin: '50px',+ lazy: true,},)@@ -31,6 +33,12 @@ const isElemVisible = ref(false)const isLoaded = ref(false)const isError = ref(false)+onMounted(() => {+ if (!props.lazy) {+ isElemVisible.value = true+ }+})+const { stop } = useIntersectionObserver(elemRef,([entry], _observerElement) => {@@ -42,6 +50,7 @@ const { stop } = useIntersectionObserver({threshold: props.threshold,rootMargin: props.rootMargin,+ immediate: props.lazy,},)diff --git a/app/pages/albums/[albumId].vue b/app/pages/albums/[albumId].vuenew file mode 100644index 00000000..2afb2426--- /dev/null+++ b/app/pages/albums/[albumId].vue@@ -0,0 +1,13 @@+<script lang="ts" setup>++</script>++<template>+ <div>+ <h1>Album Details</h1>+ </div>+</template>++<style scoped>++</style>diff --git a/app/pages/albums/index.vue b/app/pages/albums/index.vuenew file mode 100644index 00000000..4593f687--- /dev/null+++ b/app/pages/albums/index.vue@@ -0,0 +1,322 @@+<script lang="ts" setup>+import { motion } from 'motion-v'++const config = useRuntimeConfig()+const { photos } = usePhotos()+const { data: albums } = useAsyncData(() => $fetch('/api/albums'))++// 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: any) => {+ if (!album.photos || album.photos.length === 0) return []++ const displayPhotos = []++ // 第一张:优先使用封面照片+ if (album.coverPhotoId) {+ const coverPhoto =+ getPhotoById(album.coverPhotoId) ||+ album.photos.find((p: any) => p.id === album.coverPhotoId)+ if (coverPhoto) {+ displayPhotos.push(coverPhoto)+ }+ }++ // 如果没有封面照片或封面照片不存在,使用第一张+ if (displayPhotos.length === 0 && album.photos[0]) {+ displayPhotos.push(album.photos[0])+ }++ // 添加其他照片(最多3张)+ for (const photo of album.photos) {+ if (displayPhotos.length >= 3) break+ if (!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<string | 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"+ >+ <ThumbImage+ class="w-full h-auto object-cover saturate-50"+ :lazy="false"+ :src="photo.thumbnailUrl!"+ :thumbhash="photo.thumbnailHash"+ :alt="photo.exif?.ImageDescription || 'Photo'"+ :style="{+ aspectRatio: photo.aspectRatio || 1,+ }"+ />+ </div>+ </template>+ </div>+ </div>+ </div>+ <!-- Overlay -->+ <div+ class="absolute inset-0 bg-gradient-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="Back to Home"+ 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-gradient-to-br from-neutral-800 to-neutral-400 dark:from-white dark:to-neutral-500 text-transparent"+ >+ {{ 'Albums'.toUpperCase() }}+ </h1>+ <p+ class="mt-2 text-lg text-neutral-600 dark:text-neutral-400 font-medium font-[Pacifico]"+ >+ {{ config.public.app.slogan }}+ </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 albums"+ :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">+ <!-- 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.photos || album.photos.length === 0"+ class="absolute inset-0 rounded-xl shadow-lg bg-neutral-200 dark:bg-neutral-700 flex items-center justify-center"+ >+ <span class="text-neutral-500 dark:text-neutral-400">+ No Image+ </span>+ </div>+ </div>++ <!-- Album Info -->+ <div class="px-2">+ <div class="flex flex-col gap-0">+ <div class="flex items-center gap-8">+ <h2+ class="flex-1 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="flex items-center gap-0.5 text-sm text-neutral-600 dark:text-neutral-400"+ >+ <Icon+ name="tabler:clock"+ class="h-[1lh] size-4"+ />+ {{ $dayjs(album.createdAt).fromNow() }}+ </p>+ </div>+ <p+ class="text-sm text-neutral-600 dark:text-neutral-400 line-clamp-2"+ >+ {{ album.description || 'No description' }}+ </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/server/api/albums/[albumId]/index.get.ts b/server/api/albums/[albumId]/index.get.tsnew file mode 100644index 00000000..ce49d7ac--- /dev/null+++ b/server/api/albums/[albumId]/index.get.ts@@ -0,0 +1,48 @@+import { asc, getTableColumns } from 'drizzle-orm'+import z from 'zod'++export default eventHandler(async (event) => {+ const { albumId } = await getValidatedRouterParams(+ event,+ z.object({+ albumId: z+ .string()+ .regex(/^\d+$/)+ .transform((val) => parseInt(val, 10)),+ }).parse,+ )++ const db = useDB()++ const album = db+ .select()+ .from(tables.albums)+ .where(eq(tables.albums.id, albumId))+ .get()++ if (!album) {+ throw createError({+ statusCode: 404,+ statusMessage: 'Album not found',+ })+ }++ const photos = await db+ // all fields from tables.photos+ .select({+ ...getTableColumns(tables.photos),+ })+ .from(tables.photos)+ .innerJoin(+ tables.albumPhotos,+ eq(tables.photos.id, tables.albumPhotos.photoId),+ )+ .where(eq(tables.albumPhotos.albumId, albumId))+ .orderBy(asc(tables.albumPhotos.position))+ .all()++ return {+ ...album,+ photos: photos || [],+ }+})diff --git a/server/api/albums/index.get.ts b/server/api/albums/index.get.tsnew file mode 100644index 00000000..d1d7810d--- /dev/null+++ b/server/api/albums/index.get.ts@@ -0,0 +1,31 @@+export default eventHandler(async (_event) => {+ const db = useDB()++ // 获取所有相册+ const albums = await db.select().from(tables.albums)++ // 为每个相册获取照片+ const albumsWithPhotos = await Promise.all(+ albums.map(async (album) => {+ const photos = await db+ .select({+ photo: tables.photos,+ position: tables.albumPhotos.position,+ })+ .from(tables.albumPhotos)+ .innerJoin(+ tables.photos,+ eq(tables.albumPhotos.photoId, tables.photos.id),+ )+ .where(eq(tables.albumPhotos.albumId, album.id))+ .orderBy(tables.albumPhotos.position)++ return {+ ...album,+ photos: photos.map((p) => p.photo),+ }+ }),+ )++ return albumsWithPhotos+})diff --git a/server/api/albums/index.post.ts b/server/api/albums/index.post.tsnew file mode 100644index 00000000..f3d14d72--- /dev/null+++ b/server/api/albums/index.post.ts@@ -0,0 +1,54 @@+import z from 'zod'++export default eventHandler(async (event) => {+ await requireUserSession(event)++ const body = await readValidatedBody(+ event,+ z.object({+ title: z.string().min(1).max(255),+ description: z.string().max(1000).optional(),+ coverPhotoId: z.string().optional(),+ photoIds: z.array(z.string()).optional(),+ }).parse,+ )++ const db = useDB()++ const album = db.transaction((tx) => {+ const newAlbum = tx+ .insert(tables.albums)+ .values({+ title: body.title,+ description: body.description || null,+ coverPhotoId: body.coverPhotoId || null,+ })+ .returning()+ .get()++ const albumId = newAlbum.id+ const photoIds = new Set(body.photoIds || [])++ if (body.coverPhotoId) {+ photoIds.add(body.coverPhotoId)+ }++ if (photoIds.size > 0) {+ let pos = 1000000+ for (const photoId of photoIds) {+ tx.insert(tables.albumPhotos)+ .values({+ albumId,+ photoId,+ position: (pos += 10),+ })+ .onConflictDoNothing()+ .run()+ }+ }++ return newAlbum+ })++ return album+})diff --git a/server/database/migrations/0008_nervous_taskmaster.sql b/server/database/migrations/0008_nervous_taskmaster.sqlnew file mode 100644index 00000000..a26406f1--- /dev/null+++ b/server/database/migrations/0008_nervous_taskmaster.sql@@ -0,0 +1,19 @@+CREATE TABLE `album_photos` (+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,+ `album_id` integer NOT NULL,+ `photo_id` text NOT NULL,+ `position` real DEFAULT 1000000 NOT NULL,+ `added_at` integer DEFAULT (unixepoch()) NOT NULL,+ FOREIGN KEY (`album_id`) REFERENCES `albums`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`photo_id`) REFERENCES `photos`(`id`) ON UPDATE no action ON DELETE cascade+);+--> statement-breakpoint+CREATE TABLE `albums` (+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,+ `title` text NOT NULL,+ `description` text,+ `cover_photo_id` text,+ `created_at` integer DEFAULT (unixepoch()) NOT NULL,+ `updated_at` integer DEFAULT (unixepoch()) NOT NULL,+ FOREIGN KEY (`cover_photo_id`) REFERENCES `photos`(`id`) ON UPDATE no action ON DELETE set null+);diff --git a/server/database/migrations/meta/0008_snapshot.json b/server/database/migrations/meta/0008_snapshot.jsonnew file mode 100644index 00000000..87679f67--- /dev/null+++ b/server/database/migrations/meta/0008_snapshot.json@@ -0,0 +1,590 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "62a66a2f-bc67-4b21-9f6f-4502f4c0b87d",+ "prevId": "3675d681-215a-456e-b291-4a89d8745143",+ "tables": {+ "album_photos": {+ "name": "album_photos",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "album_id": {+ "name": "album_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "photo_id": {+ "name": "photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "position": {+ "name": "position",+ "type": "real",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 1000000+ },+ "added_at": {+ "name": "added_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "album_photos_album_id_albums_id_fk": {+ "name": "album_photos_album_id_albums_id_fk",+ "tableFrom": "album_photos",+ "tableTo": "albums",+ "columnsFrom": [+ "album_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "album_photos_photo_id_photos_id_fk": {+ "name": "album_photos_photo_id_photos_id_fk",+ "tableFrom": "album_photos",+ "tableTo": "photos",+ "columnsFrom": [+ "photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "albums": {+ "name": "albums",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cover_photo_id": {+ "name": "cover_photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "albums_cover_photo_id_photos_id_fk": {+ "name": "albums_cover_photo_id_photos_id_fk",+ "tableFrom": "albums",+ "tableTo": "photos",+ "columnsFrom": [+ "cover_photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "photo_reactions": {+ "name": "photo_reactions",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "photo_id": {+ "name": "photo_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "reaction_type": {+ "name": "reaction_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "fingerprint": {+ "name": "fingerprint",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "ip_address": {+ "name": "ip_address",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "user_agent": {+ "name": "user_agent",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "photo_reactions_photo_id_photos_id_fk": {+ "name": "photo_reactions_photo_id_photos_id_fk",+ "tableFrom": "photo_reactions",+ "tableTo": "photos",+ "columnsFrom": [+ "photo_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "photos": {+ "name": "photos",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "width": {+ "name": "width",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "height": {+ "name": "height",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "aspect_ratio": {+ "name": "aspect_ratio",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "date_taken": {+ "name": "date_taken",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "storage_key": {+ "name": "storage_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_key": {+ "name": "thumbnail_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "file_size": {+ "name": "file_size",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_modified": {+ "name": "last_modified",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "original_url": {+ "name": "original_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_url": {+ "name": "thumbnail_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "thumbnail_hash": {+ "name": "thumbnail_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tags": {+ "name": "tags",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "exif": {+ "name": "exif",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "latitude": {+ "name": "latitude",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "longitude": {+ "name": "longitude",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "country": {+ "name": "country",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "city": {+ "name": "city",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "location_name": {+ "name": "location_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_live_photo": {+ "name": "is_live_photo",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "live_photo_video_url": {+ "name": "live_photo_video_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "live_photo_video_key": {+ "name": "live_photo_video_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "photos_id_unique": {+ "name": "photos_id_unique",+ "columns": [+ "id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "pipeline_queue": {+ "name": "pipeline_queue",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "payload": {+ "name": "payload",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{\"type\":\"photo\",\"storageKey\":\"\"}'"+ },+ "priority": {+ "name": "priority",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "max_attempts": {+ "name": "max_attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 3+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "status_stage": {+ "name": "status_stage",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "error_message": {+ "name": "error_message",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "completed_at": {+ "name": "completed_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "users": {+ "name": "users",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "avatar": {+ "name": "avatar",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "is_admin": {+ "name": "is_admin",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ }+ },+ "indexes": {+ "users_name_unique": {+ "name": "users_name_unique",+ "columns": [+ "name"+ ],+ "isUnique": true+ },+ "users_email_unique": {+ "name": "users_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/server/database/migrations/meta/_journal.json b/server/database/migrations/meta/_journal.jsonindex 1387569f..7990f826 100644--- a/server/database/migrations/meta/_journal.json+++ b/server/database/migrations/meta/_journal.json@@ -57,6 +57,13 @@"when": 1759771246422,"tag": "0007_uneven_spectrum","breakpoints": true+ },+ {+ "idx": 8,+ "version": "6",+ "when": 1760618594229,+ "tag": "0008_nervous_taskmaster",+ "breakpoints": true}]}\ No newline at end of filediff --git a/server/database/schema.ts b/server/database/schema.tsindex 96a793d1..f976fdbb 100644--- a/server/database/schema.ts+++ b/server/database/schema.ts@@ -87,7 +87,9 @@ export const pipelineQueue = sqliteTable('pipeline_queue', {// 照片表态表export const photoReactions = sqliteTable('photo_reactions', {id: integer('id').primaryKey({ autoIncrement: true }),- photoId: text('photo_id').notNull().references(() => photos.id, { onDelete: 'cascade' }),+ photoId: text('photo_id')+ .notNull()+ .references(() => photos.id, { onDelete: 'cascade' }),reactionType: text('reaction_type', {enum: ['like', 'love', 'amazing', 'funny', 'wow', 'sad', 'fire', 'sparkle'],}).notNull(),@@ -102,3 +104,34 @@ export const photoReactions = sqliteTable('photo_reactions', {.notNull().default(sql`(unixepoch())`),})++// 相簿表+export const albums = sqliteTable('albums', {+ id: integer('id').primaryKey({ autoIncrement: true }),+ title: text('title').notNull(),+ description: text('description'),+ coverPhotoId: text('cover_photo_id').references(() => photos.id, {+ onDelete: 'set null',+ }),+ createdAt: integer('created_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+ updatedAt: integer('updated_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+})++// 相簿-照片 多对多关系表+export const albumPhotos = sqliteTable('album_photos', {+ id: integer('id').primaryKey({ autoIncrement: true }),+ albumId: integer('album_id')+ .notNull()+ .references(() => albums.id, { onDelete: 'cascade' }),+ photoId: text('photo_id')+ .notNull()+ .references(() => photos.id, { onDelete: 'cascade' }),+ position: real('position').notNull().default(1000000),+ addedAt: integer('added_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+})diff --git a/server/utils/db.ts b/server/utils/db.tsindex f9750844..4bf0dd87 100644--- a/server/utils/db.ts+++ b/server/utils/db.ts@@ -48,3 +48,11 @@ export type PipelineQueueItem = typeof schema.pipelineQueue.$inferSelectexport type NewPipelineQueueItem = typeof schema.pipelineQueue.$inferInsertexport type PhotoReaction = typeof schema.photoReactions.$inferSelect++export type Album = typeof schema.albums.$inferSelect+export type NewAlbum = typeof schema.albums.$inferInsert+export type AlbumPhoto = typeof schema.albumPhotos.$inferSelect+export type NewAlbumPhoto = typeof schema.albumPhotos.$inferInsert+export type AlbumWithPhotos = Album & {+ photos: Photo[]+}