Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix: keep protected album photo shares in album scope

Timothy Yin6d01682e650f
diff --git a/app/app.vue b/app/app.vue
index c6967553..586731aa 100644
--- a/app/app.vue
+++ b/app/app.vue
@@ -66,7 +66,13 @@ const viewerPhotos = computed(() => scopedPhotos.value ?? photos.value)
const handleIndexChange = (newIndex: number) => {
switchToIndex(newIndex)
- router.replace(`/${viewerPhotos.value[newIndex]?.id}`)
+ const photoId = viewerPhotos.value[newIndex]?.id
+ if (!photoId) return
+ if (returnRoute.value?.startsWith('/albums/') && route.path === returnRoute.value) {
+ router.replace({ path: route.path, query: { ...route.query, photo: photoId } })
+ } else {
+ router.replace(`/${photoId}`)
+ }
}
const handleClose = () => {
diff --git a/app/components/photo/ShareModal.vue b/app/components/photo/ShareModal.vue
index edfab32e..0c7019e7 100644
--- a/app/components/photo/ShareModal.vue
+++ b/app/components/photo/ShareModal.vue
@@ -13,9 +13,13 @@ const emit = defineEmits<{
const toast = useToast()
const { gtag } = useGtag()
+const { returnRoute } = storeToRefs(useViewerState())
const shareUrl = computed(() => {
if (typeof window !== 'undefined') {
+ if (returnRoute.value && /^\/albums\/\d+$/.test(returnRoute.value)) {
+ return `${window.location.origin}${returnRoute.value}?photo=${encodeURIComponent(props.photo.id)}`
+ }
return `${window.location.origin}/${props.photo.id}`
}
return ''
diff --git a/app/pages/albums/[albumId].vue b/app/pages/albums/[albumId].vue
index 8a2280c7..b258f9b9 100644
--- a/app/pages/albums/[albumId].vue
+++ b/app/pages/albums/[albumId].vue
@@ -128,10 +128,29 @@ const handleOpenViewer = (index: number) => {
// Scope the viewer to the album's photos so prev/next stays within this album.
// The fetched photos are serialized rows of the same shape as Photo.
openViewer(index, albumRoute, photos as Photo[])
- router.push(`/${photos[index].id}`)
+ router.push({ path: albumRoute, query: { photo: photos[index].id } })
}
}
+watch(
+ [() => route.query.photo, () => albumData.value?.photos],
+ ([requestedPhoto, photos]) => {
+ const viewer = useViewerState()
+ if (typeof requestedPhoto !== 'string' || !photos) {
+ if (viewer.returnRoute === `/albums/${albumId.value}`) viewer.closeViewer()
+ return
+ }
+ const index = photos.findIndex((photo) => photo.id === requestedPhoto)
+ if (index < 0) {
+ if (viewer.returnRoute === `/albums/${albumId.value}`) viewer.closeViewer()
+ return
+ }
+ const { openViewer } = viewer
+ openViewer(index, `/albums/${albumId.value}`, photos as Photo[])
+ },
+ { immediate: true },
+)
+
const coverPhoto = computed(() => {
const album = albumData.value
if (!album?.photos) return null
diff --git a/app/stores/viewer.ts b/app/stores/viewer.ts
index 57d9f974..649914dd 100644
--- a/app/stores/viewer.ts
+++ b/app/stores/viewer.ts
@@ -24,6 +24,7 @@ export const useViewerState = defineStore('photo-viewer-state', () => {
returnRoute.value = route
isDirectAccess.value = false
} else {
+ returnRoute.value = null
isDirectAccess.value = true
}
}