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(photos): add rating editing feature to photo metadata

Timothy Yin0e91374df53b
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 1e59787d..6856e3ef 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -101,6 +101,7 @@ interface EditFormState {
title: string
description: string
tags: string[]
+ rating: number | null
}
const editingPhoto = ref<Photo | null>(null)
@@ -111,6 +112,7 @@ const editFormState = reactive<EditFormState>({
title: '',
description: '',
tags: [],
+ rating: null,
})
const originalMetadata = ref<{
@@ -118,11 +120,13 @@ const originalMetadata = ref<{
description: string
tags: string[]
location: { latitude: number; longitude: number } | null
+ rating: number | null
}>({
title: '',
description: '',
tags: [],
location: null,
+ rating: null,
})
const locationSelection = ref<{ latitude: number; longitude: number } | null>(
@@ -195,12 +199,17 @@ const locationChanged = computed(() => {
)
})
+const ratingChanged = computed(
+ () => editFormState.rating !== originalMetadata.value.rating,
+)
+
const isMetadataDirty = computed(
() =>
titleChanged.value ||
descriptionChanged.value ||
tagsChanged.value ||
- locationChanged.value,
+ locationChanged.value ||
+ ratingChanged.value,
)
const formattedCoordinates = computed(() => {
@@ -426,11 +435,13 @@ watch(isEditModalOpen, (open) => {
editFormState.title = ''
editFormState.description = ''
editFormState.tags = []
+ editFormState.rating = null
originalMetadata.value = {
title: '',
description: '',
tags: [],
location: null,
+ rating: null,
}
locationSelection.value = null
locationTouched.value = false
@@ -1060,6 +1071,7 @@ const openMetadataEditor = (photo: Photo) => {
editFormState.title = initialTitle
editFormState.description = initialDescription
editFormState.tags = [...initialTags]
+ editFormState.rating = typeof photo.exif?.Rating === 'number' ? photo.exif.Rating : null
const initialLocation = hasCoordinates
? {
@@ -1073,6 +1085,7 @@ const openMetadataEditor = (photo: Photo) => {
description: initialDescription,
tags: [...initialTags],
location: initialLocation ? { ...initialLocation } : null,
+ rating: typeof photo.exif?.Rating === 'number' ? photo.exif.Rating : null,
}
locationSelection.value = initialLocation ? { ...initialLocation } : null
@@ -1102,6 +1115,7 @@ const saveMetadataChanges = async () => {
description?: string
tags?: string[]
location?: { latitude: number; longitude: number } | null
+ rating?: number | null
} = {}
if (titleChanged.value) {
@@ -1125,6 +1139,10 @@ const saveMetadataChanges = async () => {
: null
}
+ if (ratingChanged.value) {
+ payload.rating = editFormState.rating
+ }
+
if (Object.keys(payload).length === 0) {
isEditModalOpen.value = false
return
@@ -2122,6 +2140,47 @@ onUnmounted(() => {
</div>
</div>
+ <div class="space-y-2">
+ <label
+ class="text-sm font-medium text-neutral-700 dark:text-neutral-200"
+ >
+ {{ $t('dashboard.photos.editModal.fields.rating') }}
+ </label>
+ <div class="flex items-center gap-2">
+ <div class="flex gap-1">
+ <UButton
+ v-for="star in 5"
+ :key="star"
+ variant="ghost"
+ size="sm"
+ :icon="
+ star <= (editFormState.rating || 0)
+ ? 'tabler:star-filled'
+ : 'tabler:star'
+ "
+ :color="
+ star <= (editFormState.rating || 0)
+ ? 'warning'
+ : 'neutral'
+ "
+ @click="
+ editFormState.rating =
+ editFormState.rating === star ? null : star
+ "
+ />
+ </div>
+ <span v-if="editFormState.rating" class="text-sm text-neutral-600 dark:text-neutral-400">
+ {{ editFormState.rating }} / 5
+ </span>
+ <span v-else class="text-sm text-neutral-500 dark:text-neutral-500">
+ {{ $t('dashboard.photos.editModal.fields.noRating') }}
+ </span>
+ </div>
+ <p class="text-xs text-neutral-500 dark:text-neutral-400">
+ {{ $t('dashboard.photos.editModal.fields.ratingHint') }}
+ </p>
+ </div>
+
<div
class="flex items-center justify-end gap-2 pt-4 border-t border-neutral-200 dark:border-neutral-800"
>
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 87e6650e..463df336 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -635,7 +635,10 @@
"locationHint": "Click on the map to set the shooting location.",
"clearLocation": "Clear location",
"coordinates": "Coordinates",
- "noLocation": "No location selected"
+ "noLocation": "No location selected",
+ "rating": "Rating",
+ "ratingHint": "Click on the stars to set the photo rating (0-5 stars).",
+ "noRating": "No rating"
},
"actions": {
"cancel": "Cancel",
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index f41eda69..43962b63 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -578,7 +578,10 @@
"locationHint": "地図をクリックして撮影場所を選択してください。",
"clearLocation": "位置情報をクリア",
"coordinates": "座標",
- "noLocation": "位置情報が未設定です"
+ "noLocation": "位置情報が未設定です",
+ "rating": "評価",
+ "ratingHint": "星をクリックして写真の評価を設定します(0~5つ星)。",
+ "noRating": "未評価"
},
"actions": {
"cancel": "キャンセル",
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index b648512a..200c42f8 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -635,7 +635,10 @@
"locationHint": "点击地图选择或更新拍摄位置。",
"clearLocation": "清除位置",
"coordinates": "坐标",
- "noLocation": "未选择位置"
+ "noLocation": "未选择位置",
+ "rating": "评分",
+ "ratingHint": "点击星星为照片设置评分(0-5 星)。",
+ "noRating": "未评分"
},
"actions": {
"cancel": "取消",
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index 5e01bdce..b6271479 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -578,7 +578,10 @@
"locationHint": "點擊地圖選擇或更新拍攝位置。",
"clearLocation": "清除位置",
"coordinates": "座標",
- "noLocation": "未選擇位置"
+ "noLocation": "未選擇位置",
+ "rating": "評分",
+ "ratingHint": "點擊星星為相片設定評分(0-5 星)。",
+ "noRating": "未評分"
},
"actions": {
"cancel": "取消",
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index 5f106be0..6d0d4642 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -578,7 +578,10 @@
"locationHint": "點擊地圖選擇或更新拍攝位置。",
"clearLocation": "清除位置",
"coordinates": "座標",
- "noLocation": "未選擇位置"
+ "noLocation": "未選擇位置",
+ "rating": "評分",
+ "ratingHint": "點擊星星為照片設定評分(0-5 星)。",
+ "noRating": "未評分"
},
"actions": {
"cancel": "取消",
diff --git a/server/api/photos/[photoId]/index.put.ts b/server/api/photos/[photoId]/index.put.ts
index db634cbf..f84b13a1 100644
--- a/server/api/photos/[photoId]/index.put.ts
+++ b/server/api/photos/[photoId]/index.put.ts
@@ -26,6 +26,7 @@ const bodySchema = z.object({
z.null(),
])
.optional(),
+ rating: z.union([z.number().int().min(0).max(5), z.null()]).optional(),
})
const normalizeTags = (tags: string[] | undefined) => {
@@ -54,7 +55,8 @@ export default eventHandler(async (event) => {
payload.title === undefined &&
payload.description === undefined &&
payload.tags === undefined &&
- payload.location === undefined
+ payload.location === undefined &&
+ payload.rating === undefined
) {
throw createError({
statusCode: 400,
@@ -150,6 +152,10 @@ export default eventHandler(async (event) => {
}
}
+ if (payload.rating !== undefined) {
+ exifUpdates.Rating = payload.rating !== null ? payload.rating : null
+ }
+
const tempDir = await mkdtemp(path.join(tmpdir(), 'cframe-edit-'))
const ext = path.extname(photo.storageKey) || '.jpg'
const tempFile = path.join(tempDir, `edited${ext}`)