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(processor): preserve keys across Compose environment variants
Timothy Yin000f7b2c7288
diff --git a/scripts/processor-environment.mjs b/scripts/processor-environment.mjsindex 35f9fad4..4108df9e 100644--- a/scripts/processor-environment.mjs+++ b/scripts/processor-environment.mjs@@ -1,15 +1,25 @@/** Preserve a registered node key and optional Access settings when setup is rerun. */export function processorEnvironment(portal, suppliedKey, existing = '') {const stored =- /^CHRONOFRAME_PROCESSOR_KEY=(.*)$/m.exec(existing)?.[1].trim() ?? ''+ [+ ...existing.matchAll(+ /^[\t ]*CHRONOFRAME_PROCESSOR_KEY[\t ]*=[\t ]*(.*)$/gm,+ ),+ ]+ .at(-1)?.[1]+ .trim() ?? ''const unquote = (value) =>/^(['"]).*\1$/.test(value) ? value.slice(1, -1) : value- const key = unquote(suppliedKey?.trim() || stored)+ const key =+ unquote(suppliedKey?.trim() ?? '').trim() || unquote(stored).trim()if (key && !/^pn_[a-f0-9-]{36}\.[A-Za-z0-9_-]{43}$/.test(key))throw new Error('Invalid processing node connection key')const extra = existing.split(/\r?\n/)- .filter((line) => !/^CHRONOFRAME_(PORTAL_ORIGIN|PROCESSOR_KEY)=/.test(line))+ .filter(+ (line) =>+ !/^[\t ]*CHRONOFRAME_(PORTAL_ORIGIN|PROCESSOR_KEY)[\t ]*=/.test(line),+ ).join('\n').trim()return `CHRONOFRAME_PORTAL_ORIGIN=${portal}\nCHRONOFRAME_PROCESSOR_KEY=${key}\n${extra ? extra + '\n' : ''}`diff --git a/tests/processor-nodes.test.ts b/tests/processor-nodes.test.tsindex 9061ef47..173c343d 100644--- a/tests/processor-nodes.test.ts+++ b/tests/processor-nodes.test.ts@@ -7,6 +7,7 @@ import { readFile, readdir } from 'node:fs/promises'import { splitSqlQuery } from './helpers/sql.ts'import {processorCipher,+ type ProcessorConfiguration,processorKeyHash,DEFAULT_PROCESSOR_LIMITS,parseProcessorLimits,@@ -207,7 +208,7 @@ test('registered node auth revokes old keys; full schema preserves assets and fe)const decoded = await (await processorCipher(key)- ).open<any>(+ ).open<ProcessorConfiguration>(config.envelope,`${id}:${config.revision}:${config.issuedAt}:${config.expiresAt}:${config.nonce}`,)diff --git a/tests/processor-review.test.ts b/tests/processor-review.test.tsindex 7b118509..e0dd274e 100644--- a/tests/processor-review.test.ts+++ b/tests/processor-review.test.ts@@ -80,16 +80,24 @@ test('a bad post-claim configuration promptly fails the claimed attempt insteadtarget: ts.ScriptTarget.ES2022,},}).outputText- const handlers: Record<string, () => void> = {},- failures: any[] = []+ const handlers: Record<string, () => void> = {}+ type FailBody = { lease: typeof lease; code: string; retryable: boolean }+ const failures: FailBody[] = []let opened = 0,processed = falseconst lease = { id: 'job', siteId: 1, workerId: nodeId, attemptId: 'attempt' }- const rpc = async (action: string, body: any) => {+ const rpc = async (action: string, body: Record<string, unknown>) => {if (action === 'register') return {}if (action === 'claim') return { lease, configuration: {} }if (action === 'fail') {- failures.push(body)+ 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,+ })handlers.SIGTERM!()return { ok: true }}@@ -195,7 +203,7 @@ test('provider empty results stay successful nulls while transport failures cantest('rerunning media setup retains its registered key and optional Access credentials', () => {const existing = `CHRONOFRAME_PORTAL_ORIGIN=https://old.example\nCHRONOFRAME_PROCESSOR_KEY=${key}\nCHRONOFRAME_ACCESS_CLIENT_SECRET=private-access-example\n`- for (const supplied of [undefined, '']) {+ for (const supplied of [undefined, '', '""', "''", ' "" ', " '' "]) {const result = processorEnvironment('https://new.example',supplied,@@ -226,6 +234,35 @@ test('rerunning media setup retains its registered key and optional Access crede)})+test('spaced Compose assignments are normalized and the last stored key survives rotation or setup', () => {+ const second = `pn_${nodeId}.${'b'.repeat(43)}`+ const existing = `CHRONOFRAME_PROCESSOR_KEY=${key}\r\n CHRONOFRAME_PROCESSOR_KEY \t = "${second}"\r\n CHRONOFRAME_PORTAL_ORIGIN = https://old.example\r\nCHRONOFRAME_ACCESS_CLIENT_SECRET=keep-me\r\n`+ const preserved = processorEnvironment(+ 'https://new.example',+ undefined,+ existing,+ )+ assert(preserved.includes('CHRONOFRAME_PROCESSOR_KEY=' + second))+ const rotated = processorEnvironment('https://new.example', key, existing)+ assert.equal(+ rotated+ .split('\n')+ .filter((line) => /^[\t ]*CHRONOFRAME_PROCESSOR_KEY[\t ]*=/.test(line))+ .length,+ 1,+ )+ assert.equal(+ rotated+ .split('\n')+ .filter((line) => /^[\t ]*CHRONOFRAME_PORTAL_ORIGIN[\t ]*=/.test(line))+ .length,+ 1,+ )+ assert(rotated.includes('CHRONOFRAME_PROCESSOR_KEY=' + key))+ assert(!rotated.includes(second))+ assert(rotated.includes('CHRONOFRAME_ACCESS_CLIENT_SECRET=keep-me'))+})+test('batch processing reports conflicts but propagates unexpected queue failures', async () => {const source = (await readFile(