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(site): preserve published photo operations during reprocessing
Timothy Yinf00755a321ae
diff --git a/apps/site/server/api/public/photos/[photoId]/[operation].ts b/apps/site/server/api/public/photos/[photoId]/[operation].tsindex 14285253..6356f9bf 100644--- a/apps/site/server/api/public/photos/[photoId]/[operation].ts+++ b/apps/site/server/api/public/photos/[photoId]/[operation].ts@@ -19,7 +19,7 @@ export default definePlatformHandler(async (event) => {const db = platformDatabase(event)const photo = await db.prepare(- `SELECT p.id FROM cloud_photos p WHERE p.site_id=? AND p.id=? AND p.deleted=0 AND p.metadata_json IS NOT NULL AND EXISTS(SELECT 1 FROM cloud_processing_jobs j WHERE j.site_id=p.site_id AND j.photo_id=p.id AND j.source_version=p.source_version AND j.state='succeeded')`,+ `SELECT p.id FROM cloud_photos p WHERE p.site_id=? AND p.id=? AND p.deleted=0 AND p.metadata_json IS NOT NULL AND EXISTS(SELECT 1 FROM cloud_media_assets a WHERE a.site_id=p.site_id AND a.photo_id=p.id AND a.source_version=p.source_version AND a.role='thumbnail')`,).bind(context.site.id, id).first()diff --git a/tests/processor-media-access.test.ts b/tests/processor-media-access.test.tsindex 8fea52dc..36a8019b 100644--- a/tests/processor-media-access.test.ts+++ b/tests/processor-media-access.test.ts@@ -1,3 +1,4 @@+import { REACTION_TYPES } from '../packages/contracts/src/reactions.ts'import test from 'node:test'import assert from 'node:assert/strict'import Database from 'better-sqlite3'@@ -18,9 +19,9 @@ test('published photo streams remain available throughout maintenance and after)const db = {prepare: (sql: string) => {- let values: any[] = []+ let values: (string | number | null)[] = []const statement = {- bind: (...v: any[]) => {+ bind: (...v: (string | number | null)[]) => {values = vreturn statement},@@ -58,12 +59,53 @@ test('published photo streams remain available throughout maintenance and aftersignGet: async (key: string) => 'https://storage.example/' + key,}),getHeader: () => undefined,- createError: (v: any) => Object.assign(new Error(v.statusMessage), v),+ createError: (v: { statusCode: number; statusMessage?: string }) =>+ Object.assign(new Error(v.statusMessage), v),}const media = new Function(...Object.keys(deps),code + ';return exports.privateMedia',)(...Object.values(deps))+ let denied = false,+ publicSiteId = 1,+ authorizationCalls = 0+ const album = { id: 1, title: 'Album' }+ const publicSource = (+ await readFile(+ 'apps/site/server/api/public/photos/[photoId]/[operation].ts',+ 'utf8',+ )+ ).replace(/^import[\s\S]*?from ['"][^'"]+['"]\s*\n/gm, '')+ const publicCode = ts.transpileModule(publicSource, {+ compilerOptions: {+ module: ts.ModuleKind.CommonJS,+ target: ts.ScriptTarget.ES2022,+ },+ }).outputText+ const publicDeps = {+ ...deps,+ exports: {},+ definePlatformHandler: (f: unknown) => f,+ publicSiteContext: async () => ({ site: { id: publicSiteId } }),+ getRouterParam: (event: { operation: string }, name: string) =>+ name === 'photoId' ? 'photo' : event.operation,+ authorizePublicPhoto: async () => {+ authorizationCalls+++ if (denied)+ throw Object.assign(new Error('Denied'), { statusCode: 403 })+ },+ createCloudResourceRepository: () => ({+ membershipsForPhoto: async () => [{ albumId: 1 }],+ }),+ createResourceReader: () => ({ listAlbums: async () => [album] }),+ createEmailCodeCrypto: async () => ({ mac: async () => 'visitor' }),+ platformRequestURL: () => new URL('https://gallery.example'),+ REACTION_TYPES,+ }+ const publicApi = new Function(+ ...Object.keys(publicDeps),+ publicCode + ';return exports.default',+ )(...Object.values(publicDeps))globalThis.fetch = async () =>new Response('img', {headers: { 'content-length': '3', 'content-type': 'image/jpeg' },@@ -79,13 +121,41 @@ test('published photo streams remain available throughout maintenance and aftersqlite.prepare('UPDATE cloud_processing_jobs SET state=?').run(state)for (const role of ['original', 'display', 'thumbnail', 'live-video'])assert.equal(await (await media({}, 1, 'photo', role)).text(), 'img')+ assert.deepEqual(+ await publicApi({ method: 'GET', operation: 'albums' }),+ [album],+ )+ assert.deepEqual(+ (await publicApi({ method: 'GET', operation: 'reactions' })).reactions,+ Object.fromEntries(REACTION_TYPES.map((type) => [type, 0])),+ )}+ assert.equal(authorizationCalls, 12)+ denied = true+ await assert.rejects(publicApi({ method: 'GET', operation: 'albums' }), {+ statusCode: 403,+ })+ await assert.rejects(publicApi({ method: 'GET', operation: 'reactions' }), {+ statusCode: 403,+ })+ denied = false+ publicSiteId = 2+ await assert.rejects(publicApi({ method: 'GET', operation: 'albums' }), {+ statusCode: 404,+ })+ publicSiteId = 1sqlite.exec('UPDATE cloud_photos SET metadata_json=NULL')+ await assert.rejects(publicApi({ method: 'GET', operation: 'albums' }), {+ statusCode: 404,+ })await assert.rejects(media({}, 1, 'photo', 'thumbnail'), {statusCode: 404,})sqlite.exec("UPDATE cloud_photos SET metadata_json='{}',deleted=1")await assert.rejects(media({}, 1, 'photo', 'original'), { statusCode: 404 })+ await assert.rejects(publicApi({ method: 'GET', operation: 'reactions' }), {+ statusCode: 404,+ })} finally {globalThis.fetch = originalFetchsqlite.close()diff --git a/tests/processor-review.test.ts b/tests/processor-review.test.tsindex e0dd274e..2a4efd8b 100644--- a/tests/processor-review.test.ts+++ b/tests/processor-review.test.ts@@ -81,8 +81,7 @@ test('a bad post-claim configuration promptly fails the claimed attempt instead},}).outputTextconst handlers: Record<string, () => void> = {}- type FailBody = { lease: typeof lease; code: string; retryable: boolean }- const failures: FailBody[] = []+ const failures: Record<string, unknown>[] = []let opened = 0,processed = falseconst lease = { id: 'job', siteId: 1, workerId: nodeId, attemptId: 'attempt' }@@ -90,14 +89,7 @@ test('a bad post-claim configuration promptly fails the claimed attempt insteadif (action === 'register') return {}if (action === 'claim') return { lease, configuration: {} }if (action === 'fail') {- assert.deepEqual(body.lease, lease)- assert.equal(typeof body.code, 'string')- assert.equal(typeof body.retryable, 'boolean')- failures.push({- lease,- code: String(body.code),- retryable: body.retryable === true,- })+ failures.push(body)handlers.SIGTERM!()return { ok: true }}@@ -148,9 +140,11 @@ test('a bad post-claim configuration promptly fails the claimed attempt instead)(...Object.values(deps))assert.equal(processed, false)assert.equal(failures.length, 1)- assert.deepEqual(failures[0].lease, lease)- assert.equal(failures[0].code, 'configuration_invalid')- assert.equal(failures[0].retryable, true)+ const failure = failures[0]+ assert(failure)+ assert.deepEqual(failure.lease, lease)+ assert.equal(failure.code, 'configuration_invalid')+ assert.equal(failure.retryable, true)})test('provider empty results stay successful nulls while transport failures can propagate to processing queues', async () => {