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
fix: address Workers compatibility and context revalidation review
HoshinoSuzumiBot192742581864
diff --git a/README.md b/README.mdindex 71724610..5446ba30 100644--- a/README.md+++ b/README.md@@ -30,7 +30,7 @@ChronoFrame is a self-hosted photo gallery. Upload your photos and it extracts EXIF, creates previews and identifies shooting locations. Visitors can browse by time, album or map, zoom into large images and play Live Photos.-[Live demo](https://lens.bh8.ga) · [Documentation](https://docs.chronoframe.art/) · [Changelog](https://docs.chronoframe.art/changelog)+[Live demo](https://lens.bh8.ga) · [Documentation](https://docs.chronoframe.art/) · [Changelog](https://docs.chronoframe.art/changelog.html)## ✨ Features@@ -77,7 +77,7 @@ Open `http://localhost:3000` and use the setup wizard to create your administratKeep the `./data` mount: it holds the database, settings, session secret and local photos when using the path above.-Use HTTPS for a public deployment. See [Getting Started](https://docs.chronoframe.art/guide/getting-started) and the [update guide](https://docs.chronoframe.art/guide/updates) for proxies, backups and migration from older versions.+Use HTTPS for a public deployment. See [Getting Started](https://docs.chronoframe.art/guide/getting-started.html) and the [update guide](https://docs.chronoframe.art/guide/updates.html) for proxies, backups and migration from older versions.## 📖 Usage@@ -85,7 +85,7 @@ Sign in and open `/dashboard` to upload and organize photos. After upload, the tFor Apple Live Photos, the image and MOV must share a filename, such as `IMG_1234.heic` and `IMG_1234.mov`; either can be uploaded first. Image formats include JPEG, PNG, WebP, GIF, BMP, TIFF and HEIC / HEIF.-Album passwords control access through ChronoFrame. If S3, OpenList or a CDN exposes public image URLs, manage access in that service too. Read [Using ChronoFrame](https://docs.chronoframe.art/guide/usage) for details.+Album passwords control access through ChronoFrame. If S3, OpenList or a CDN exposes public image URLs, manage access in that service too. Read [Using ChronoFrame](https://docs.chronoframe.art/guide/usage.html) for details.## 📸 Screenshotsdiff --git a/README_zh.md b/README_zh.mdindex 0ae6ea6e..630bd34a 100644--- a/README_zh.md+++ b/README_zh.md@@ -30,7 +30,7 @@ChronoFrame 是一个可以自行部署的照片画廊。上传照片后,应用会提取 EXIF、生成预览并整理拍摄地点;访客可以按时间、相册或地图浏览,也能查看大图和播放实况照片。-[在线演示](https://lens.bh8.ga) · [使用文档](https://docs.chronoframe.art/zh/) · [更新日志](https://docs.chronoframe.art/zh/changelog)+[在线演示](https://lens.bh8.ga) · [使用文档](https://docs.chronoframe.art/zh/) · [更新日志](https://docs.chronoframe.art/zh/changelog.html)## ✨ 功能@@ -77,7 +77,7 @@ docker run -d --name chronoframe --restart unless-stopped \请保留 `./data` 挂载,其中包含数据库、设置、会话密钥,以及采用上述路径时的本地照片。-部署到公网时使用 HTTPS。反向代理、数据备份和旧版迁移见[快速开始](https://docs.chronoframe.art/zh/guide/getting-started)和[升级指南](https://docs.chronoframe.art/zh/guide/updates)。+部署到公网时使用 HTTPS。反向代理、数据备份和旧版迁移见[快速开始](https://docs.chronoframe.art/zh/guide/getting-started.html)和[升级指南](https://docs.chronoframe.art/zh/guide/updates.html)。## 📖 使用@@ -85,7 +85,7 @@ docker run -d --name chronoframe --restart unless-stopped \Apple Live Photo 的图片和 MOV 文件需要相同文件名,例如 `IMG_1234.heic` 和 `IMG_1234.mov`,上传顺序不限。照片支持 JPEG、PNG、WebP、GIF、BMP、TIFF、HEIC / HEIF 等格式。-密码相册限制的是通过 ChronoFrame 访问的内容。如果 S3、OpenList 或 CDN 提供公开的图片直链,需要同时管理外部服务的权限。详见[日常使用](https://docs.chronoframe.art/zh/guide/usage)。+密码相册限制的是通过 ChronoFrame 访问的内容。如果 S3、OpenList 或 CDN 提供公开的图片直链,需要同时管理外部服务的权限。详见[日常使用](https://docs.chronoframe.art/zh/guide/usage.html)。## 📸 截图diff --git a/apps/cloud/app/middleware/platform.global.ts b/apps/cloud/app/middleware/platform.global.tsindex 4fa4922f..670e2c80 100644--- a/apps/cloud/app/middleware/platform.global.ts+++ b/apps/cloud/app/middleware/platform.global.ts@@ -5,7 +5,13 @@ import type {export default defineNuxtRouteMiddleware(async (to) => {const path = to.path.toLowerCase()const context = useEntryContext()- context.value = null+ const detail = /^\/sites\/([1-9][0-9]*)$/.exec(path)+ if (+ !detail ||+ context.value?.siteId !== Number(detail[1]) ||+ context.value?.audience !== 'portal'+ )+ context.value = nullconst catalog = useState<EntrySiteCatalog | null>('platform-site-catalog',() => null,@@ -23,12 +29,15 @@ export default defineNuxtRouteMiddleware(async (to) => {}>('/api/auth/session').catch((error) => {if ([401, 403].includes(error.statusCode ?? error.status))return { authenticated: false, user: null }+ context.value = nullthrow error})useState<number | null>('platform-user-id', () => null).value =session.user?.id ?? null- if (!session.authenticated || !session.user)+ if (!session.authenticated || !session.user) {+ context.value = nullreturn navigateTo('/signin', { redirectCode: 302 })+ }if (path === '/sites') {const result = await fetcher<{ sites: EntrySiteSummary[] }>('/api/sites')catalog.value = { userId: session.user.id, sites: result.sites }@@ -42,6 +51,7 @@ export default defineNuxtRouteMiddleware(async (to) => {try {context.value = await fetcher(`/api/sites/${match[1]}/context`)} catch (error) {+ context.value = nullreturn abortNavigation(error as Error)}}diff --git a/apps/platform-crypto.ts b/apps/platform-crypto.tsindex 04fcdaaa..9c972cea 100644--- a/apps/platform-crypto.ts+++ b/apps/platform-crypto.ts@@ -33,3 +33,31 @@ export async function createEmailCodeCrypto(},}}++// Conservative cost for Workers deployments that enforce the Web Crypto PBKDF2 cap.+export const VISITOR_PBKDF2_ITERATIONS = 100_000+export async function visitorPasswordHash(+ password: string,+ salt: string,+): Promise<string> {+ const key = await crypto.subtle.importKey(+ 'raw',+ new TextEncoder().encode(password),+ 'PBKDF2',+ false,+ ['deriveBits'],+ )+ const bits = await crypto.subtle.deriveBits(+ {+ name: 'PBKDF2',+ hash: 'SHA-256',+ salt: new TextEncoder().encode(salt),+ iterations: VISITOR_PBKDF2_ITERATIONS,+ },+ key,+ 256,+ )+ return Array.from(new Uint8Array(bits), (b) =>+ b.toString(16).padStart(2, '0'),+ ).join('')+}diff --git a/apps/platform-visitor.ts b/apps/platform-visitor.tsindex c3cdfc24..b9c5e34e 100644--- a/apps/platform-visitor.ts+++ b/apps/platform-visitor.ts@@ -6,32 +6,15 @@ import type {} from '../packages/core/src/platform.ts'import { hasSiteVisitorGrant } from '../packages/core/src/platform.ts'import { platformDatabase, platformRequestURL } from './platform.runtime.ts'-import { createEmailCodeCrypto } from './platform-crypto.ts'+import {+ createEmailCodeCrypto,+ visitorPasswordHash,+} from './platform-crypto.ts'+export { visitorPasswordHash } from './platform-crypto.ts'const encoder = new TextEncoder()const COOKIE = '__Host-chronoframe-visitor'const TTL = 60 * 60 * 1000-const iterations = 600_000-export async function visitorPasswordHash(- password: string,- salt: string,-): Promise<string> {- const key = await crypto.subtle.importKey(- 'raw',- encoder.encode(password),- 'PBKDF2',- false,- ['deriveBits'],- )- const bits = await crypto.subtle.deriveBits(- { name: 'PBKDF2', hash: 'SHA-256', salt: encoder.encode(salt), iterations },- key,- 256,- )- return Array.from(new Uint8Array(bits), (b) =>- b.toString(16).padStart(2, '0'),- ).join('')-}async function signingKey(secret: string) {if (encoder.encode(secret).length < 32) throw createError({ statusCode: 503 })return crypto.subtle.importKey(diff --git a/apps/site/app/middleware/site.global.ts b/apps/site/app/middleware/site.global.tsindex 7cf1eae9..33254c6b 100644--- a/apps/site/app/middleware/site.global.ts+++ b/apps/site/app/middleware/site.global.ts@@ -1,24 +1,28 @@export default defineNuxtRouteMiddleware(async (to) => {const context = useEntryContext()- context.value = nullif (to.path.toLowerCase() === '/dashboard' ||to.path.toLowerCase().startsWith('/dashboard/')- )+ ) {+ context.value = nullreturn abortNavigation(createError({ statusCode: 404, statusMessage: 'Page not found' }),)+ }try {context.value = await useRequestFetch()('/api/public/context')} catch (error) {+ context.value = nullreturn abortNavigation(error as Error)}// Photo repositories are delivered in P4; never fall back to Self-hosted data.- if (to.path !== '/')+ if (to.path !== '/') {+ context.value = nullreturn abortNavigation(createError({statusCode: 503,statusMessage: 'Gallery content is not available yet',}),)+ }})diff --git a/tests/site-middleware.test.ts b/tests/site-middleware.test.tsnew file mode 100644index 00000000..a9fffebb--- /dev/null+++ b/tests/site-middleware.test.ts@@ -0,0 +1,53 @@+import assert from 'node:assert/strict'+import test from 'node:test'+import { readFileSync } from 'node:fs'+import vm from 'node:vm'+import ts from 'typescript'+import { ref, watch } from 'vue'++test('same-Site hydration preserves state; scope changes and rejected navigation clear it', async () => {+ const context = ref<{ scope: string } | null>({ scope: 'site:one:public' })+ let next: { scope: string } | Error = { scope: 'site:one:public' }+ const changes: unknown[] = []+ const stop = watch(+ () => context.value?.scope,+ (value) => changes.push(value),+ { flush: 'sync' },+ )+ const exports: Record<string, any> = {}+ const code = ts.transpileModule(+ readFileSync('apps/site/app/middleware/site.global.ts', 'utf8'),+ { compilerOptions: { module: ts.ModuleKind.CommonJS } },+ ).outputText+ vm.runInNewContext(code, {+ exports,+ defineNuxtRouteMiddleware: (fn: unknown) => fn,+ useEntryContext: () => context,+ useRequestFetch: () => async () => {+ if (next instanceof Error) throw next+ return next+ },+ createError: (error: unknown) => error,+ abortNavigation: (error: unknown) => error,+ })+ try {+ await exports.default({ path: '/' })+ await exports.default({ path: '/' })+ assert.deepEqual(+ changes,+ [],+ 'hydration/revalidation must not reset the same scope',+ )+ next = { scope: 'site:two:public' }+ await exports.default({ path: '/' })+ assert.deepEqual(changes, ['site:two:public'])+ next = new Error('Host mapping revoked')+ await exports.default({ path: '/' })+ assert.equal(context.value, null)+ context.value = { scope: 'site:one:public' }+ await exports.default({ path: '/dashboard' })+ assert.equal(context.value, null)+ } finally {+ stop()+ }+})diff --git a/tests/visitor-worker-crypto.test.ts b/tests/visitor-worker-crypto.test.tsnew file mode 100644index 00000000..3c822d1d--- /dev/null+++ b/tests/visitor-worker-crypto.test.ts@@ -0,0 +1,54 @@+import assert from 'node:assert/strict'+import test from 'node:test'+import { createRequire } from 'node:module'+import { pbkdf2Sync } from 'node:crypto'+import { fileURLToPath } from 'node:url'+import { VISITOR_PBKDF2_ITERATIONS } from '../apps/platform-crypto.ts'++test('visitor password hashing stays within the portable Workers budget and executes in workerd', async () => {+ assert.ok(+ VISITOR_PBKDF2_ITERATIONS > 0 && VISITOR_PBKDF2_ITERATIONS <= 100_000,+ )+ const require = createRequire(import.meta.url)+ const wranglerRequire = createRequire(+ require.resolve('wrangler/package.json'),+ )+ const { build } = wranglerRequire('esbuild')+ const { Miniflare, convertV4MiniflareOptions } = wranglerRequire('miniflare')+ const module = fileURLToPath(+ new URL('../apps/platform-crypto.ts', import.meta.url),+ )+ const bundle = await build({+ stdin: {+ resolveDir: fileURLToPath(new URL('../', import.meta.url)),+ contents: `import {visitorPasswordHash} from ${JSON.stringify(module)};export default {async fetch(){return Response.json({hash:await visitorPasswordHash('test-password','unique-test-salt')})}}`,+ },+ bundle: true,+ write: false,+ format: 'esm',+ platform: 'browser',+ target: 'es2022',+ })+ const mf = new Miniflare(+ convertV4MiniflareOptions({+ modules: true,+ compatibilityDate: '2026-10-22',+ script: bundle.outputFiles[0].text,+ }),+ )+ try {+ const result = await mf.dispatchFetch('http://worker.example.com')+ assert.equal(result.status, 200)+ assert.deepEqual(await result.json(), {+ hash: pbkdf2Sync(+ 'test-password',+ 'unique-test-salt',+ VISITOR_PBKDF2_ITERATIONS,+ 32,+ 'sha256',+ ).toString('hex'),+ })+ } finally {+ await mf.dispose()+ }+})