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(onboarding): allow skipping the map token

Ahmet Ömer48dff902f0e6
diff --git a/app/components/map/Provider.vue b/app/components/map/Provider.vue
index a2152eed..692a3756 100644
--- a/app/components/map/Provider.vue
+++ b/app/components/map/Provider.vue
@@ -2,11 +2,12 @@
import type { AttributionControlOptions, StyleSpecification } from 'maplibre-gl'
import { twMerge } from 'tailwind-merge'
import type { MapboxMap, MapInstance, MaplibreMap } from '~~/shared/types/map'
+import { isMapServiceConfigured } from '~~/shared/utils/map-service'
import ChronoFrameLightStyle from '~/assets/mapStyles/chronoframe_light.json'
import ChronoFrameDarkStyle from '~/assets/mapStyles/chronoframe_dark.json'
-withDefaults(
+const props = withDefaults(
defineProps<{
class?: string
mapId?: string
@@ -15,6 +16,7 @@ withDefaults(
interactive?: boolean
attributionControl?: false | AttributionControlOptions
language?: string
+ setupNotice?: boolean
}>(),
{
class: undefined,
@@ -24,6 +26,7 @@ withDefaults(
interactive: true,
attributionControl: false,
language: undefined,
+ setupNotice: false,
},
)
@@ -40,6 +43,31 @@ const mapConfig = computed(() => {
})
const provider = computed(() => mapConfig.value.provider || 'maplibre')
+const isConfigured = computed(() =>
+ isMapServiceConfigured(mapConfig.value as Record<string, unknown>),
+)
+
+const { show: showMapSetupNotice, hide: hideMapSetupNotice } =
+ useMapSetupNotice()
+
+const syncMapSetupNotice = () => {
+ if (!props.setupNotice) return
+ if (isConfigured.value) {
+ hideMapSetupNotice()
+ return
+ }
+ showMapSetupNotice()
+}
+
+onMounted(syncMapSetupNotice)
+watch([isConfigured, () => props.setupNotice], () => {
+ if (import.meta.client) syncMapSetupNotice()
+})
+onBeforeUnmount(() => {
+ if (!props.setupNotice) return
+ hideMapSetupNotice()
+})
+
const mapStyle = computed(() => {
if (provider.value === 'mapbox') {
return mapConfig.value['mapbox.style'] || `mapbox://styles/mapbox/standard`
@@ -65,7 +93,16 @@ const mapStyle = computed(() => {
<template>
<div :class="twMerge('w-full h-full', $props.class)">
- <ClientOnly>
+ <div
+ v-if="!isConfigured"
+ class="flex h-full w-full items-center justify-center bg-neutral-100 dark:bg-neutral-900"
+ >
+ <UIcon
+ name="tabler:map-off"
+ class="size-10 text-neutral-400"
+ />
+ </div>
+ <ClientOnly v-else>
<MglMap
v-if="provider === 'maplibre'"
class="w-full h-full"
diff --git a/app/components/map/SetupNotice.vue b/app/components/map/SetupNotice.vue
new file mode 100644
index 00000000..e459251f
--- /dev/null
+++ b/app/components/map/SetupNotice.vue
@@ -0,0 +1,38 @@
+<script setup lang="ts">
+const { isOpen, isAdmin, dismiss } = useMapSetupNotice()
+
+async function openSettings() {
+ dismiss()
+ await navigateTo('/dashboard/settings/map')
+}
+</script>
+
+<template>
+ <UModal
+ v-model:open="isOpen"
+ :title="$t('map.setupNotice.title')"
+ :description="$t('map.setupNotice.description')"
+ :ui="{
+ overlay: 'z-[80]',
+ content: 'z-[80]',
+ footer: 'justify-end',
+ }"
+ >
+ <template #footer>
+ <UButton
+ color="neutral"
+ variant="outline"
+ @click="dismiss"
+ >
+ {{ $t('map.setupNotice.dismiss') }}
+ </UButton>
+ <UButton
+ v-if="isAdmin"
+ icon="tabler:settings"
+ @click="openSettings"
+ >
+ {{ $t('map.setupNotice.openSettings') }}
+ </UButton>
+ </template>
+ </UModal>
+</template>
diff --git a/app/composables/useMapSetupNotice.ts b/app/composables/useMapSetupNotice.ts
new file mode 100644
index 00000000..4b1b89b7
--- /dev/null
+++ b/app/composables/useMapSetupNotice.ts
@@ -0,0 +1,43 @@
+type MapSetupNoticeState = {
+ open: boolean
+ dismissedPath: string
+}
+
+export function useMapSetupNotice() {
+ const route = useRoute()
+ const { user } = useUserSession()
+ const state = useState<MapSetupNoticeState>('map-setup-notice', () => ({
+ open: false,
+ dismissedPath: '',
+ }))
+
+ const isAdmin = computed(() => Boolean(user.value?.isAdmin))
+
+ const isOpen = computed({
+ get: () => state.value.open,
+ set: (value: boolean) => {
+ if (value) {
+ state.value.open = true
+ return
+ }
+ if (!state.value.open) return
+ state.value.open = false
+ state.value.dismissedPath = route.fullPath
+ },
+ })
+
+ function show() {
+ if (state.value.dismissedPath === route.fullPath) return
+ state.value.open = true
+ }
+
+ function hide() {
+ state.value.open = false
+ }
+
+ function dismiss() {
+ isOpen.value = false
+ }
+
+ return { isOpen, isAdmin, show, hide, dismiss }
+}
diff --git a/app/pages/globe.vue b/app/pages/globe.vue
index bc0dfd1f..b202edfe 100644
--- a/app/pages/globe.vue
+++ b/app/pages/globe.vue
@@ -760,8 +760,10 @@ onBeforeUnmount(() => {
class="w-full h-full"
>
<ClientOnly>
+ <MapSetupNotice />
<!-- mapbox://styles/hoshinosuzumi/cmev0eujf01dw01pje3g9cmlg -->
<MapProvider
+ setup-notice
class="w-full h-full"
:map-id="generateRandomKey()"
:zoom="mapViewState.zoom"
diff --git a/app/pages/onboarding/complete.vue b/app/pages/onboarding/complete.vue
index d7075ff5..64c7e1a5 100644
--- a/app/pages/onboarding/complete.vue
+++ b/app/pages/onboarding/complete.vue
@@ -44,7 +44,7 @@ async function onComplete() {
const mapData = {
provider: mapProvider,
- token: mapState[mapTokenKey],
+ token: mapState[mapTokenKey] || '',
style: mapState[mapStyleKey],
}
diff --git a/app/pages/onboarding/map.vue b/app/pages/onboarding/map.vue
index ae27d6c8..646b7c51 100644
--- a/app/pages/onboarding/map.vue
+++ b/app/pages/onboarding/map.vue
@@ -73,6 +73,10 @@ function onSubmit() {
/>
</template>
+ <p class="text-sm text-neutral-400">
+ {{ $t('onboarding.map.tokenOptional') }}
+ </p>
+
<UForm
id="map-form"
:state="state"
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 27e5be84..33df29db 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -167,6 +167,12 @@
"createdTooltip": "Created: {date}"
},
"map": {
+ "setupNotice": {
+ "title": "Map service is not set up",
+ "description": "This map needs a MapTiler or Mapbox access token before it can load. An administrator can add one in Map & Location settings. A custom MapLibre style URL can be used instead of a MapTiler token.",
+ "openSettings": "Open map settings",
+ "dismiss": "Close"
+ },
"cluster": {
"details": "Click to view details",
"nearbyPhotos": "{0} photos nearby",
@@ -1506,7 +1512,8 @@
},
"map": {
"title": "Map Service",
- "description": "Configure map service for globe view and photo minimap"
+ "description": "Configure map service for globe view and photo minimap",
+ "tokenOptional": "The access token is optional. You can add it later in Map & Location settings. Until then, the globe, photo minimap, and location picker stay blank. A custom MapLibre style URL works without a MapTiler token."
},
"complete": {
"title": "Almost Done!",
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index 441e1b7c..247c4986 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -167,6 +167,12 @@
"createdTooltip": "作成日:{date}"
},
"map": {
+ "setupNotice": {
+ "title": "地図サービスが未設定です",
+ "description": "この地図を表示するには MapTiler または Mapbox のアクセストークンが必要です。管理者は「地図と場所」の設定から追加できます。MapTiler トークンの代わりに、カスタム MapLibre スタイル URL を使うこともできます。",
+ "openSettings": "地図設定を開く",
+ "dismiss": "閉じる"
+ },
"cluster": {
"details": "クリックして詳細を見る",
"nearbyPhotos": "近くに {0} 枚の写真",
@@ -1432,7 +1438,8 @@
},
"map": {
"title": "地図サービス",
- "description": "グローブ表示と写真詳細のミニマップ向けに地図サービスを設定します"
+ "description": "グローブ表示と写真詳細のミニマップ向けに地図サービスを設定します",
+ "tokenOptional": "アクセストークンは任意です。あとから「地図と場所」の設定で追加できます。追加するまで、グローブ、写真のミニマップ、位置選択は空白のままです。カスタム MapLibre スタイル URL なら MapTiler トークンなしで利用できます。"
},
"complete": {
"title": "まもなく完了です!",
diff --git a/i18n/locales/ru.json b/i18n/locales/ru.json
index fe0ad581..97de1c68 100644
--- a/i18n/locales/ru.json
+++ b/i18n/locales/ru.json
@@ -167,6 +167,12 @@
"createdTooltip": "Создан: {date}"
},
"map": {
+ "setupNotice": {
+ "title": "Картографический сервис не настроен",
+ "description": "Этой карте нужен токен доступа MapTiler или Mapbox. Администратор может добавить его в разделе «Карта и геолокация». Вместо токена MapTiler можно указать собственный URL стиля MapLibre.",
+ "openSettings": "Открыть настройки карты",
+ "dismiss": "Закрыть"
+ },
"cluster": {
"details": "Нажмите, чтобы посмотреть подробности",
"nearbyPhotos": "Фотографий рядом: {0}",
@@ -1492,7 +1498,8 @@
},
"map": {
"title": "Картографический сервис",
- "description": "Настройте карты для фотоглобуса и мини-карты фотографий"
+ "description": "Настройте карты для фотоглобуса и мини-карты фотографий",
+ "tokenOptional": "Токен доступа необязателен. Его можно добавить позже в разделе «Карта и геолокация». До этого фотоглобус, мини-карта и выбор места останутся пустыми. Собственный URL стиля MapLibre работает без токена MapTiler."
},
"complete": {
"title": "Почти готово!",
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index 7c9e28dc..b4078793 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -1,5 +1,11 @@
{
"map": {
+ "setupNotice": {
+ "title": "地图服务尚未配置",
+ "description": "此地图需要 MapTiler 或 Mapbox 访问令牌才能加载。管理员可以在“地图和位置”设置中添加令牌。也可以使用自定义 MapLibre 样式 URL 代替 MapTiler 令牌。",
+ "openSettings": "打开地图设置",
+ "dismiss": "关闭"
+ },
"cluster": {
"details": "点击图片查看详情",
"nearbyPhotos": "附近有 {0} 张照片",
@@ -1506,7 +1512,8 @@
},
"map": {
"title": "地图服务",
- "description": "为地球仪视图以及照片详情中的小地图配置地图服务"
+ "description": "为地球仪视图以及照片详情中的小地图配置地图服务",
+ "tokenOptional": "访问令牌是可选的。你可以稍后在“地图和位置”设置中添加。在此之前,地球仪、照片小地图和位置选择器会保持空白。自定义 MapLibre 样式 URL 可以在没有 MapTiler 令牌的情况下使用。"
},
"complete": {
"title": "即将完成!",
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index 3444f32d..e9c1ab5e 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -1,5 +1,11 @@
{
"map": {
+ "setupNotice": {
+ "title": "地圖服務尚未設定",
+ "description": "此地圖需要 MapTiler 或 Mapbox 存取權杖才能載入。管理員可以在「地圖和位置」設定中新增權杖。也可以使用自訂 MapLibre 樣式 URL 代替 MapTiler 權杖。",
+ "openSettings": "開啟地圖設定",
+ "dismiss": "關閉"
+ },
"cluster": {
"details": "點擊圖片查看詳情",
"nearbyPhotos": "附近有 {0} 張相片",
@@ -1432,7 +1438,8 @@
},
"map": {
"title": "地圖服務",
- "description": "為地球儀檢視與照片詳情小地圖設定地圖服務"
+ "description": "為地球儀檢視與照片詳情小地圖設定地圖服務",
+ "tokenOptional": "存取權杖為選填。你可以稍後在「地圖和位置」設定中新增。在此之前,地球儀、照片小地圖和位置選擇器會保持空白。自訂 MapLibre 樣式 URL 可以在沒有 MapTiler 權杖的情況下使用。"
},
"complete": {
"title": "即將完成!",
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index 9b2d86bd..2dee7422 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -1,5 +1,11 @@
{
"map": {
+ "setupNotice": {
+ "title": "地圖服務尚未設定",
+ "description": "此地圖需要 MapTiler 或 Mapbox 存取權杖才能載入。管理員可以在「地圖和位置」設定中新增權杖。也可以使用自訂 MapLibre 樣式 URL 代替 MapTiler 權杖。",
+ "openSettings": "開啟地圖設定",
+ "dismiss": "關閉"
+ },
"cluster": {
"details": "點選圖片查看詳細資訊",
"nearbyPhotos": "附近有 {0} 張相片",
@@ -1432,7 +1438,8 @@
},
"map": {
"title": "地圖服務",
- "description": "為地球儀檢視與照片詳情小地圖設定地圖服務"
+ "description": "為地球儀檢視與照片詳情小地圖設定地圖服務",
+ "tokenOptional": "存取權杖為選填。你可以稍後在「地圖和位置」設定中新增。在此之前,地球儀、照片小地圖和位置選擇器會保持空白。自訂 MapLibre 樣式 URL 可以在沒有 MapTiler 權杖的情況下使用。"
},
"complete": {
"title": "即將完成!",
diff --git a/server/api/wizard/map.post.ts b/server/api/wizard/map.post.ts
index 7c341530..4a39f222 100644
--- a/server/api/wizard/map.post.ts
+++ b/server/api/wizard/map.post.ts
@@ -6,18 +6,19 @@ export default eventHandler(async (event) => {
event,
z.object({
provider: z.enum(['mapbox', 'maplibre']),
- token: z.string().min(1),
+ token: z.string().optional().default(''),
style: z.string().optional(),
}).parse,
)
await settingsManager.set('map', 'provider', body.provider)
+ const mapToken = body.token.trim()
if (body.provider === 'mapbox') {
- await settingsManager.set('map', 'mapbox.token', body.token)
+ if (mapToken) await settingsManager.set('map', 'mapbox.token', mapToken)
if (body.style) await settingsManager.set('map', 'mapbox.style', body.style)
} else {
- await settingsManager.set('map', 'maplibre.token', body.token)
+ if (mapToken) await settingsManager.set('map', 'maplibre.token', mapToken)
if (body.style)
await settingsManager.set('map', 'maplibre.style', body.style)
}
diff --git a/server/api/wizard/schema.get.ts b/server/api/wizard/schema.get.ts
index 3787b8d9..2ce398d6 100644
--- a/server/api/wizard/schema.get.ts
+++ b/server/api/wizard/schema.get.ts
@@ -262,6 +262,19 @@ export default eventHandler(async (event) => {
}
}
+ if (
+ query.namespace === 'map' &&
+ (setting.key === 'mapbox.token' || setting.key === 'maplibre.token')
+ ) {
+ return {
+ ...setting,
+ ui: {
+ ...(uiConfig || { type: 'password' as const }),
+ required: false,
+ },
+ }
+ }
+
return {
...setting,
ui: uiConfig || {
diff --git a/server/api/wizard/submit.post.ts b/server/api/wizard/submit.post.ts
index 3e939c95..aa268051 100644
--- a/server/api/wizard/submit.post.ts
+++ b/server/api/wizard/submit.post.ts
@@ -24,7 +24,7 @@ export default eventHandler(async (event) => {
}),
map: z.object({
provider: z.enum(['mapbox', 'maplibre']),
- token: z.string().min(1),
+ token: z.string().optional().default(''),
style: z.string().optional(),
}),
}).parse,
@@ -88,12 +88,15 @@ export default eventHandler(async (event) => {
// 4. Handle Map Settings
await settingsManager.set('map', 'provider', body.map.provider)
+ const mapToken = body.map.token.trim()
if (body.map.provider === 'mapbox') {
- await settingsManager.set('map', 'mapbox.token', body.map.token)
+ if (mapToken)
+ await settingsManager.set('map', 'mapbox.token', mapToken)
if (body.map.style)
await settingsManager.set('map', 'mapbox.style', body.map.style)
} else {
- await settingsManager.set('map', 'maplibre.token', body.map.token)
+ if (mapToken)
+ await settingsManager.set('map', 'maplibre.token', mapToken)
if (body.map.style)
await settingsManager.set('map', 'maplibre.style', body.map.style)
}
diff --git a/shared/utils/map-service.ts b/shared/utils/map-service.ts
new file mode 100644
index 00000000..c9bf832a
--- /dev/null
+++ b/shared/utils/map-service.ts
@@ -0,0 +1,21 @@
+type MapServiceConfig = Record<string, unknown> | null | undefined
+
+const text = (config: MapServiceConfig, key: string) =>
+ String(config?.[key] ?? '').trim()
+
+/**
+ * Default MapLibre styles call MapTiler, and Mapbox styles need an access token.
+ * A custom MapLibre style URL can load without a MapTiler token.
+ */
+export function isMapServiceConfigured(config: MapServiceConfig): boolean {
+ const provider = text(config, 'provider') || 'maplibre'
+
+ if (provider === 'mapbox') {
+ return text(config, 'mapbox.token').length > 0
+ }
+
+ return (
+ text(config, 'maplibre.token').length > 0 ||
+ text(config, 'maplibre.style').length > 0
+ )
+}