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(reaction): add reaction picker component and integrate reactions functionality
HoshinoSuzumi33ab25143e63
diff --git a/app/components/photo/ReactionPicker.vue b/app/components/photo/ReactionPicker.vuenew file mode 100644index 00000000..f55a85d8--- /dev/null+++ b/app/components/photo/ReactionPicker.vue@@ -0,0 +1,142 @@+<script setup lang="ts">+import { motion, AnimatePresence } from 'motion-v'++interface Reaction {+ id: string+ iconName: string+ label: string+ count?: number+}++interface Props {+ isOpen: boolean+ selectedReaction?: string | null+ reactionCounts?: Record<string, number>+}++const props = defineProps<Props>()+const emit = defineEmits<{+ select: [id: string]+ close: []+}>()++// 可用的表态选项+const reactions = computed<Reaction[]>(() => [+ { id: 'like', iconName: 'fluent-emoji-flat:thumbs-up', label: 'like', count: props.reactionCounts?.like || 0 },+ { id: 'love', iconName: 'fluent-emoji-flat:red-heart', label: 'love', count: props.reactionCounts?.love || 0 },+ { id: 'amazing', iconName: 'fluent-emoji-flat:smiling-face-with-heart-eyes', label: 'amazing', count: props.reactionCounts?.amazing || 0 },+ { id: 'funny', iconName: 'fluent-emoji-flat:face-with-tears-of-joy', label: 'funny', count: props.reactionCounts?.funny || 0 },+ { id: 'wow', iconName: 'fluent-emoji-flat:face-with-open-mouth', label: 'wow', count: props.reactionCounts?.wow || 0 },+ { id: 'sad', iconName: 'fluent-emoji-flat:crying-face', label: 'sad', count: props.reactionCounts?.sad || 0 },+ { id: 'fire', iconName: 'fluent-emoji-flat:fire', label: 'fire', count: props.reactionCounts?.fire || 0 },+ { id: 'sparkle', iconName: 'fluent-emoji-flat:sparkles', label: 'sparkle', count: props.reactionCounts?.sparkle || 0 },+])++// 格式化数量显示+const formatCount = (count?: number): string => {+ if (!count || count === 0) return ''+ if (count >= 1000) {+ return `${(count / 1000).toFixed(1)}k`+ }+ return count.toString()+}++const handleSelect = (id: string) => {+ emit('select', id)+}+</script>++<template>+ <AnimatePresence>+ <motion.div+ v-if="isOpen"+ :initial="{ opacity: 0, scale: 0.9, y: 10 }"+ :animate="{ opacity: 1, scale: 1, y: 0 }"+ :exit="{ opacity: 0, scale: 0.9, y: 10 }"+ :transition="{+ type: 'spring',+ stiffness: 400,+ damping: 25,+ mass: 0.8+ }"+ class="absolute bottom-full right-0 mb-2 z-30"+ @click.stop+ >+ <div+ class="bg-white/90 dark:bg-neutral-800/90 backdrop-blur-xl rounded-2xl border border-neutral-200/50 dark:border-white/10 shadow-2xl shadow-black/10 dark:shadow-black/30 p-3"+ >+ <!-- 表态网格 -->+ <div class="grid grid-cols-4 gap-2 min-w-[220px]">+ <motion.button+ v-for="reaction in reactions"+ :key="reaction.id"+ type="button"+ :initial="{ scale: 0, opacity: 0 }"+ :animate="{+ scale: 1,+ opacity: 1,+ transition: {+ type: 'spring',+ stiffness: 500,+ damping: 20,+ delay: reactions.indexOf(reaction) * 0.03+ }+ }"+ :while-hover="{+ scale: 1.2,+ transition: {+ type: 'spring',+ stiffness: 500,+ damping: 20+ }+ }"+ :while-tap="{+ scale: 0.9,+ transition: {+ type: 'spring',+ stiffness: 500,+ damping: 20+ }+ }"+ :class="[+ 'relative aspect-square w-full min-w-[48px] rounded-xl flex items-center justify-center transition-colors cursor-pointer shrink-0 group',+ 'hover:bg-neutral-100/80 dark:hover:bg-white/10',+ 'active:bg-neutral-200/80 dark:active:bg-white/20',+ selectedReaction === reaction.id+ ? 'bg-blue-100 dark:bg-blue-500/20 ring-2 ring-blue-500/50'+ : 'bg-transparent'+ ]"+ :title="reaction.label"+ @click="handleSelect(reaction.id)"+ >+ <Icon+ :name="reaction.iconName"+ class="text-[28px] select-none"+ />++ <!-- 数量徽章 - 右上角 -->+ <motion.span+ v-if="reaction.count !== undefined && reaction.count > 0"+ :initial="{ scale: 0, opacity: 0 }"+ :animate="{ scale: 1, opacity: 1 }"+ :class="[+ 'absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1',+ 'flex items-center justify-center',+ 'text-[9px] font-bold leading-none',+ 'rounded-full',+ 'shadow-sm',+ selectedReaction === reaction.id+ ? 'bg-blue-500 text-white'+ : 'bg-gradient-to-br from-neutral-100 to-neutral-200 dark:from-neutral-700 dark:to-neutral-600 text-neutral-700 dark:text-neutral-100',+ 'border border-white/50 dark:border-neutral-800/50',+ 'group-hover:scale-110 transition-transform duration-150'+ ]"+ >+ {{ formatCount(reaction.count) }}+ </motion.span>+ </motion.button>+ </div>+ </div>+ </motion.div>+ </AnimatePresence>+</template>diff --git a/app/components/photo/Viewer.vue b/app/components/photo/Viewer.vueindex c778a9cb..7ec9bd88 100644--- a/app/components/photo/Viewer.vue+++ b/app/components/photo/Viewer.vue@@ -10,6 +10,7 @@ import LoadingIndicator from './LoadingIndicator.vue'import ProgressiveImage from './ProgressiveImage.vue'import GalleryThumbnail from './GalleryThumbnail.vue'import InfoPanel from './InfoPanel.vue'+import ReactionPicker from './ReactionPicker.vue'import type { LoadingIndicatorRef } from './LoadingIndicator.vue'interface Props {@@ -38,6 +39,44 @@ const zoomLevel = ref(0)const showZoomLevel = ref(false)const zoomLevelTimer = ref<NodeJS.Timeout | null>(null)+// Reaction state+const showReactionPicker = ref(false)+const selectedReaction = ref<string | null>(null)+const reactionCounts = ref<Record<string, number>>({})+const isLoadingReaction = ref(false)++// 表态图标映射+const reactionIcons: Record<string, string> = {+ 'like': 'fluent-emoji-flat:thumbs-up',+ 'love': 'fluent-emoji-flat:red-heart',+ 'amazing': 'fluent-emoji-flat:smiling-face-with-heart-eyes',+ 'funny': 'fluent-emoji-flat:face-with-tears-of-joy',+ 'wow': 'fluent-emoji-flat:face-with-open-mouth',+ 'sad': 'fluent-emoji-flat:crying-face',+ 'fire': 'fluent-emoji-flat:fire',+ 'sparkle': 'fluent-emoji-flat:sparkles',+}++const currentReactionIcon = computed(() => {+ return selectedReaction.value ? reactionIcons[selectedReaction.value] : null+})++// 计算总表态数+const totalReactions = computed(() => {+ return Object.values(reactionCounts.value).reduce((sum, count) => sum + count, 0)+})++// 加载照片表态数据+const loadPhotoReactions = async (photoId: string) => {+ try {+ const data = await $fetch(`/api/photos/${photoId}/reactions`) as any+ selectedReaction.value = data.userReaction || null+ reactionCounts.value = data.reactions || {}+ } catch (error) {+ console.error('Failed to load reactions:', error)+ }+}+// LivePhoto stateconst isLivePhotoHovering = ref(false)const isLivePhotoPlaying = ref(false)@@ -75,6 +114,10 @@ watch(zoomLevel.value = 0showZoomLevel.value = false+ // Reset reaction state+ showReactionPicker.value = false+ selectedReaction.value = null+// Reset LivePhoto stateisLivePhotoHovering.value = falseisLivePhotoPlaying.value = false@@ -118,6 +161,10 @@ watch(isImageZoomed.value = falsezoomLevel.value = 0+ // Reset reaction state when switching photos+ showReactionPicker.value = false+ selectedReaction.value = null+// Reset LivePhoto state when switching photosisLivePhotoPlaying.value = falseisLivePhotoHovering.value = false@@ -347,6 +394,71 @@ const handleLivePhotoVideoEnded = () => {}}+// Reaction handlers+const handleReactionSelect = async (reactionId: string) => {+ if (!currentPhoto.value) return++ isLoadingReaction.value = true++ try {+ if (selectedReaction.value === reactionId) {+ // 取消表态+ await $fetch(`/api/photos/${currentPhoto.value.id}/reactions`, {+ method: 'DELETE',+ })+ selectedReaction.value = null+ // 减少计数+ if (reactionCounts.value[reactionId]) {+ reactionCounts.value[reactionId]--+ }+ } else {+ // 如果之前有表态,先减少旧表态的计数+ const oldReaction = selectedReaction.value+ if (oldReaction && reactionCounts.value[oldReaction] !== undefined) {+ reactionCounts.value[oldReaction]--+ }++ // 添加或更新表态+ await $fetch(`/api/photos/${currentPhoto.value.id}/reactions`, {+ method: 'POST',+ body: { reactionType: reactionId },+ })++ selectedReaction.value = reactionId+ // 增加计数+ reactionCounts.value[reactionId] = (reactionCounts.value[reactionId] || 0) + 1+ }+ } catch (error: any) {+ console.error('Failed to update reaction:', error)++ // 显示错误提示+ if (error?.statusCode === 429) {+ alert('操作过于频繁,请稍后再试')+ } else {+ alert('表态失败,请稍后重试')+ }+ } finally {+ isLoadingReaction.value = false+ }++ showReactionPicker.value = false+}++const toggleReactionPicker = () => {+ showReactionPicker.value = !showReactionPicker.value+}++// 监听当前照片变化,加载表态数据+watch(+ () => currentPhoto.value?.id,+ (newPhotoId) => {+ if (newPhotoId) {+ loadPhotoReactions(newPhotoId)+ }+ },+ { immediate: true }+)+defineShortcuts({escape: () => {emit('close')@@ -662,6 +774,82 @@ const swiperModules = [Navigation, Keyboard, Virtual]</span></motion.div></AnimatePresence>++ <!-- 表态按钮 -->+ <AnimatePresence>+ <motion.div+ v-if="!isImageZoomed && !isLivePhotoPlaying"+ :initial="{ opacity: 0, scale: 0.8, y: 20 }"+ :animate="{ opacity: 1, scale: 1, y: 0 }"+ :exit="{ opacity: 0, scale: 0.8, y: 20 }"+ :transition="{+ type: 'spring',+ stiffness: 300,+ damping: 20,+ delay: 0.1+ }"+ class="absolute bottom-6 right-6 z-20"+ >+ <div class="relative">+ <!-- 表态选择器 -->+ <ReactionPicker+ :is-open="showReactionPicker"+ :selected-reaction="selectedReaction"+ :reaction-counts="reactionCounts"+ @select="handleReactionSelect"+ @close="showReactionPicker = false"+ />++ <!-- 表态按钮 -->+ <motion.button+ type="button"+ :initial="{ scale: 0.8, opacity: 0 }"+ :animate="{+ scale: showReactionPicker ? 0.92 : 1,+ opacity: 1,+ transition: showReactionPicker+ ? { duration: 0.2, ease: [0.25, 0.1, 0.25, 1] }+ : { type: 'spring', stiffness: 300, damping: 25, mass: 0.8 }+ }"+ :while-hover="{ scale: showReactionPicker ? 0.95 : 1.05 }"+ :while-tap="{ scale: 0.88 }"+ :class="[+ 'pointer-events-auto flex items-center justify-center gap-2',+ 'px-4 h-11 rounded-full',+ 'backdrop-blur-xl border shadow-lg',+ 'transition-all duration-200',+ selectedReaction+ ? 'bg-blue-500/90 border-blue-400/50 text-white shadow-blue-500/30'+ : 'bg-white/90 dark:bg-neutral-800/90 border-neutral-200/50 dark:border-white/10 text-neutral-700 dark:text-white/80 shadow-black/10 dark:shadow-black/30',+ 'hover:shadow-xl'+ ]"+ @click="toggleReactionPicker"+ >+ <Icon+ v-if="selectedReaction && currentReactionIcon"+ :name="currentReactionIcon"+ class="text-xl leading-none select-none"+ />+ <Icon+ v-else+ name="tabler:mood-smile"+ class="text-xl"+ />+ <div class="flex flex-col items-start gap-0.5">+ <span class="text-sm font-medium leading-none">+ {{ selectedReaction ? $t('viewer.reaction.change') : $t('viewer.reaction.add') }}+ </span>+ <span+ v-if="totalReactions > 0"+ class="text-[10px] leading-none opacity-70"+ >+ {{ $t('viewer.reaction.count', { count: totalReactions }, totalReactions) }}+ </span>+ </div>+ </motion.button>+ </div>+ </motion.div>+ </AnimatePresence></motion.div></SwiperSlide></Swiper>diff --git a/i18n/locales/en.json b/i18n/locales/en.jsonindex 85cff862..0a22aaf9 100644--- a/i18n/locales/en.json+++ b/i18n/locales/en.json@@ -123,6 +123,11 @@},"mobile": "Double-click or pinch zoom","desktop": "Double-click or zoom with the mouse wheel"+ },+ "reaction": {+ "add": "React",+ "change": "Reacted",+ "count": "no reactions | {count} reaction | {count} reactions"}},"exif": {diff --git a/i18n/locales/ja.json b/i18n/locales/ja.jsonindex 243f766f..27a62ce2 100644--- a/i18n/locales/ja.json+++ b/i18n/locales/ja.json@@ -123,6 +123,11 @@},"mobile": "ダブルタップまたはピンチでズーム","desktop": "ダブルクリックまたはマウスホイールでズーム"+ },+ "reaction": {+ "add": "リアクション",+ "change": "リアクション済み",+ "count": "リアクションなし | {count} 件のリアクション | {count} 件のリアクション"}},"exif": {diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.jsonindex fbd202ba..aa21d352 100644--- a/i18n/locales/zh-Hans.json+++ b/i18n/locales/zh-Hans.json@@ -120,6 +120,11 @@},"mobile": "双击或捏合缩放","desktop": "双击或用鼠标滚轮缩放"+ },+ "reaction": {+ "add": "表态",+ "change": "已表态",+ "count": "无表态 | {count} 个表态 | {count} 个表态"}},"exif": {diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.jsonindex e4d2d54e..e11bfb97 100644--- a/i18n/locales/zh-Hant-HK.json+++ b/i18n/locales/zh-Hant-HK.json@@ -120,6 +120,11 @@},"mobile": "點兩下或兩指縮放","desktop": "點兩下或用滑鼠滾輪縮放"+ },+ "reaction": {+ "add": "表態",+ "change": "已表態",+ "count": "無表態 | {count} 個表態 | {count} 個表態"}},"exif": {diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.jsonindex f5c14fc4..ef2dcc0c 100644--- a/i18n/locales/zh-Hant-TW.json+++ b/i18n/locales/zh-Hant-TW.json@@ -120,6 +120,11 @@},"mobile": "點兩下或雙指縮放","desktop": "點兩下或使用滑鼠滾輪縮放"+ },+ "reaction": {+ "add": "表態",+ "change": "已表態",+ "count": "無表態 | {count} 個表態 | {count} 個表態"}},"exif": {diff --git a/server/api/photos/[id]/reactions.ts b/server/api/photos/[id]/reactions.tsnew file mode 100644index 00000000..befd3328--- /dev/null+++ b/server/api/photos/[id]/reactions.ts@@ -0,0 +1,225 @@+import type { H3Event } from 'h3'+import { useDB, tables, eq, and, sql } from '~~/server/utils/db'++const REACTION_TYPES = ['like', 'love', 'amazing', 'funny', 'wow', 'sad', 'fire', 'sparkle'] as const+const RATE_LIMIT_WINDOW = 60 * 1000 // 1分钟+const MAX_REACTIONS_PER_WINDOW = 10 // 每分钟最多10次表态++// 客户端指纹+function generateFingerprint(event: H3Event): string {+ const headers = getHeaders(event)+ const ip = getRequestIP(event, { xForwardedFor: true }) || 'unknown'+ const userAgent = headers['user-agent'] || 'unknown'+ const acceptLanguage = headers['accept-language'] || 'unknown'+ const acceptEncoding = headers['accept-encoding'] || 'unknown'++ // 组合多个特征+ const fingerprint = `${ip}|${userAgent}|${acceptLanguage}|${acceptEncoding}`++ // 使用简单的哈希+ return Buffer.from(fingerprint).toString('base64')+}++// 检查速率限制+async function checkRateLimit(fingerprint: string): Promise<boolean> {+ const db = useDB()+ const now = Date.now()+ const windowStart = new Date(now - RATE_LIMIT_WINDOW)++ const recentReactions = await db+ .select({ count: sql<number>`count(*)` })+ .from(tables.photoReactions)+ .where(+ and(+ eq(tables.photoReactions.fingerprint, fingerprint),+ sql`${tables.photoReactions.createdAt} > ${Math.floor(windowStart.getTime() / 1000)}`+ )+ )+ .get()++ return (recentReactions?.count || 0) < MAX_REACTIONS_PER_WINDOW+}++export default defineEventHandler(async (event) => {+ const photoId = getRouterParam(event, 'id')++ if (!photoId) {+ throw createError({+ statusCode: 400,+ message: 'Photo ID is required',+ })+ }++ const db = useDB()+ const method = event.method++ // GET: 获取照片的表态统计+ if (method === 'GET') {+ const reactions = await db+ .select({+ reactionType: tables.photoReactions.reactionType,+ count: sql<number>`count(*)`,+ })+ .from(tables.photoReactions)+ .where(eq(tables.photoReactions.photoId, photoId))+ .groupBy(tables.photoReactions.reactionType)+ .all()++ // 获取当前用户的表态+ const fingerprint = generateFingerprint(event)+ const userReaction = await db+ .select()+ .from(tables.photoReactions)+ .where(+ and(+ eq(tables.photoReactions.photoId, photoId),+ eq(tables.photoReactions.fingerprint, fingerprint)+ )+ )+ .get()++ // 格式化返回数据+ const reactionCounts: Record<string, number> = {}+ for (const type of REACTION_TYPES) {+ reactionCounts[type] = 0+ }++ reactions.forEach((r) => {+ if (r.reactionType) {+ reactionCounts[r.reactionType] = r.count+ }+ })++ return {+ photoId,+ reactions: reactionCounts,+ userReaction: userReaction?.reactionType || null,+ }+ }++ // POST: 添加或更新表态+ if (method === 'POST') {+ const body = await readBody(event)+ const { reactionType } = body++ if (!reactionType || !REACTION_TYPES.includes(reactionType)) {+ throw createError({+ statusCode: 400,+ message: 'Invalid reaction type',+ })+ }++ const fingerprint = generateFingerprint(event)++ // 检查速率限制+ const canReact = await checkRateLimit(fingerprint)+ if (!canReact) {+ throw createError({+ statusCode: 429,+ message: 'Too many reactions. Please try again later.',+ })+ }++ // 检查照片是否存在+ const photo = await db+ .select()+ .from(tables.photos)+ .where(eq(tables.photos.id, photoId))+ .get()++ if (!photo) {+ throw createError({+ statusCode: 404,+ message: 'Photo not found',+ })+ }++ // 获取额外信息用于审计+ const headers = getHeaders(event)+ const ipAddress = getRequestIP(event, { xForwardedFor: true })+ const userAgent = headers['user-agent']++ // 检查用户是否已经对该照片表态+ const existingReaction = await db+ .select()+ .from(tables.photoReactions)+ .where(+ and(+ eq(tables.photoReactions.photoId, photoId),+ eq(tables.photoReactions.fingerprint, fingerprint)+ )+ )+ .get()++ if (existingReaction) {+ // 更新现有表态+ await db+ .update(tables.photoReactions)+ .set({+ reactionType,+ updatedAt: new Date(),+ })+ .where(eq(tables.photoReactions.id, existingReaction.id))++ return {+ success: true,+ action: 'updated',+ reactionType,+ }+ } else {+ // 创建新表态+ await db+ .insert(tables.photoReactions)+ .values({+ photoId,+ reactionType,+ fingerprint,+ ipAddress,+ userAgent,+ })++ return {+ success: true,+ action: 'created',+ reactionType,+ }+ }+ }++ // DELETE: 删除表态+ if (method === 'DELETE') {+ const fingerprint = generateFingerprint(event)++ const existingReaction = await db+ .select()+ .from(tables.photoReactions)+ .where(+ and(+ eq(tables.photoReactions.photoId, photoId),+ eq(tables.photoReactions.fingerprint, fingerprint)+ )+ )+ .get()++ if (!existingReaction) {+ throw createError({+ statusCode: 404,+ message: 'Reaction not found',+ })+ }++ await db+ .delete(tables.photoReactions)+ .where(eq(tables.photoReactions.id, existingReaction.id))++ return {+ success: true,+ action: 'deleted',+ }+ }++ throw createError({+ statusCode: 405,+ message: 'Method not allowed',+ })+})diff --git a/server/api/photos/reactions.get.ts b/server/api/photos/reactions.get.tsnew file mode 100644index 00000000..06c9c9e9--- /dev/null+++ b/server/api/photos/reactions.get.ts@@ -0,0 +1,58 @@+import { useDB, tables, sql, inArray } from '~~/server/utils/db'++export default defineEventHandler(async (event) => {+ const query = getQuery(event)+ const photoIds = query.ids++ if (!photoIds) {+ throw createError({+ statusCode: 400,+ message: 'Photo IDs are required',+ })+ }++ // 支持单个或多个 ID+ const ids = Array.isArray(photoIds) ? photoIds : [photoIds]++ if (ids.length === 0) {+ return {}+ }++ const db = useDB()++ // 获取所有照片的表态统计+ const reactions = await db+ .select({+ photoId: tables.photoReactions.photoId,+ reactionType: tables.photoReactions.reactionType,+ count: sql<number>`count(*)`,+ })+ .from(tables.photoReactions)+ .where(inArray(tables.photoReactions.photoId, ids as string[]))+ .groupBy(tables.photoReactions.photoId, tables.photoReactions.reactionType)+ .all()++ const result: Record<string, Record<string, number>> = {}++ ids.forEach((id) => {+ result[id as string] = {+ like: 0,+ love: 0,+ amazing: 0,+ funny: 0,+ wow: 0,+ sad: 0,+ fire: 0,+ sparkle: 0,+ }+ })++ // 填充实际的计数+ reactions.forEach((r) => {+ if (r.photoId && r.reactionType) {+ result[r.photoId][r.reactionType] = r.count+ }+ })++ return result+})diff --git a/server/database/migrations/0007_uneven_spectrum.sql b/server/database/migrations/0007_uneven_spectrum.sqlnew file mode 100644index 00000000..b83ae24d--- /dev/null+++ b/server/database/migrations/0007_uneven_spectrum.sql@@ -0,0 +1,11 @@+CREATE TABLE `photo_reactions` (+ `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,+ `photo_id` text NOT NULL,+ `reaction_type` text NOT NULL,+ `fingerprint` text NOT NULL,+ `ip_address` text,+ `user_agent` text,+ `created_at` integer DEFAULT (unixepoch()) NOT NULL,+ `updated_at` integer DEFAULT (unixepoch()) NOT NULL,+ FOREIGN KEY (`photo_id`) REFERENCES `photos`(`id`) ON UPDATE no action ON DELETE cascade+);diff --git a/server/database/migrations/meta/0007_snapshot.json b/server/database/migrations/meta/0007_snapshot.jsonnew file mode 100644index 00000000..83411c66--- /dev/null+++ b/server/database/migrations/meta/0007_snapshot.json@@ -0,0 +1,448 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "3675d681-215a-456e-b291-4a89d8745143",+ "prevId": "f395c220-c4ec-46f8-a0bf-4fda6e692f7c",+ "tables": {+ "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 d3b16d87..1387569f 100644--- a/server/database/migrations/meta/_journal.json+++ b/server/database/migrations/meta/_journal.json@@ -50,6 +50,13 @@"when": 1758723057975,"tag": "0006_flaky_the_enforcers","breakpoints": true+ },+ {+ "idx": 7,+ "version": "6",+ "when": 1759771246422,+ "tag": "0007_uneven_spectrum",+ "breakpoints": true}]}\ No newline at end of filediff --git a/server/database/schema.ts b/server/database/schema.tsindex 7108f0ce..a64452a9 100644--- a/server/database/schema.ts+++ b/server/database/schema.ts@@ -82,3 +82,22 @@ export const pipelineQueue = sqliteTable('pipeline_queue', {.default(sql`(unixepoch())`),completedAt: integer('completed_at', { mode: 'timestamp' }),})++// 照片表态表+export const photoReactions = sqliteTable('photo_reactions', {+ id: integer('id').primaryKey({ autoIncrement: true }),+ photoId: text('photo_id').notNull().references(() => photos.id, { onDelete: 'cascade' }),+ reactionType: text('reaction_type', {+ enum: ['like', 'love', 'amazing', 'funny', 'wow', 'sad', 'fire', 'sparkle'],+ }).notNull(),+ // 使用指纹而不是 IP 地址,更准确且支持匿名用户+ fingerprint: text('fingerprint').notNull(),+ ipAddress: text('ip_address'),+ userAgent: text('user_agent'),+ createdAt: integer('created_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+ updatedAt: integer('updated_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+})diff --git a/server/utils/db.ts b/server/utils/db.tsindex 3e18a8b1..a1fc0af5 100644--- a/server/utils/db.ts+++ b/server/utils/db.ts@@ -3,7 +3,7 @@ import { drizzle } from 'drizzle-orm/better-sqlite3'import Database from 'better-sqlite3'import * as schema from '../database/schema'-export { sql, eq, and, or } from 'drizzle-orm'+export { sql, eq, and, or, inArray } from 'drizzle-orm'export const tables = schema