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: preserve MIME and canonical keys for staged metadata
HoshinoSuzumiBot94a5527af118
diff --git a/packages/core/README.md b/packages/core/README.mdindex 30a99f04..4c299030 100644--- a/packages/core/README.md+++ b/packages/core/README.md@@ -22,10 +22,8 @@ password hashing, object I/O, native EXIF editing, and task dispatch. SQLiteadapters keep multi-row album changes transactional. HTTP validation, translatedmessages, signed cookies, upload transport, and runtime effects remain in Nuxt.-Photo object edits and database updates retain the existing cross-system-consistency boundary; source-version fencing and durable task recovery belong-to the later jobs batch. Self-hosted account-wide quota remains unlimited while-per-file limits continue to apply.+Self-hosted account-wide quota remains unlimited while per-file limits continue+to apply.Photo metadata edits stage a unique source object before publication. The databasechecks the captured source version and atomically updates the photo reference,diff --git a/server/services/resources/photo-metadata.ts b/server/services/resources/photo-metadata.tsindex 63607ca3..cbd8c326 100644--- a/server/services/resources/photo-metadata.ts+++ b/server/services/resources/photo-metadata.ts@@ -78,7 +78,25 @@ export async function editPhotoMetadata(await mkdir(tempRoot, { recursive: true })const tempDir = await mkdtemp(path.join(tempRoot, 'cframe-edit-'))const stagedKey = `.generated/metadata/${randomUUID()}/${path.posix.basename(photo.storageKey)}`- const ext = path.extname(photo.storageKey) || '.jpg'+ let cleanupKey = stagedKey+ const ext = path.extname(photo.storageKey).toLowerCase() || '.jpg'+ const contentType =+ (+ {+ '.jpg': 'image/jpeg',+ '.jpeg': 'image/jpeg',+ '.png': 'image/png',+ '.webp': 'image/webp',+ '.gif': 'image/gif',+ '.bmp': 'image/bmp',+ '.tif': 'image/tiff',+ '.tiff': 'image/tiff',+ '.avif': 'image/avif',+ '.heic': 'image/heic',+ '.heif': 'image/heif',+ '.hif': 'image/heif',+ } as Record<string, string>+ )[ext] ?? 'application/octet-stream'const tempFile = path.join(tempDir, `edited${ext}`)try {@@ -92,7 +110,12 @@ export async function editPhotoMetadata(// Publish to a unique object. The original stays untouched until the// database atomically selects this revision and enqueues follow-up work.const exifData = await extractExifData(updatedBuffer)- const staged = await storageProvider.create(stagedKey, updatedBuffer)+ const staged = await storageProvider.create(+ stagedKey,+ updatedBuffer,+ contentType,+ )+ cleanupKey = staged.keyreturn {exif: exifData,@@ -102,11 +125,11 @@ export async function editPhotoMetadata(originalUrl: /\.(?:heic|heif|hif)$/i.test(photo.storageKey)? photo.originalUrl: storageProvider.getPublicUrl(staged.key),- discard: () => storageProvider.delete(stagedKey),+ discard: () => storageProvider.delete(staged.key),}} catch (error) {try {- await storageProvider.delete(stagedKey)+ await storageProvider.delete(cleanupKey)} catch (cleanupError) {logger.image.warn('Failed to discard staged metadata object',diff --git a/tests/review-runtime.test.ts b/tests/review-runtime.test.tsindex 12bd2efb..954e29aa 100644--- a/tests/review-runtime.test.ts+++ b/tests/review-runtime.test.ts@@ -325,3 +325,74 @@ test('native metadata editing stages a unique object and discard preserves origiawait rm(root, { recursive: true, force: true })}})++test('S3 metadata publication uses image MIME and the returned prefixed key for both cleanup paths', async () => {+ const { S3StorageProvider } = await import('@chronoframe/storage')+ const original = await sharp({+ create: { width: 2, height: 3, channels: 3, background: 'red' },+ })+ .jpeg()+ .toBuffer()+ for (const failAfterCreate of [false, true]) {+ const provider = new S3StorageProvider({+ provider: 's3',+ bucket: 'test',+ region: 'us-east-1',+ prefix: 'photos',+ endpoint: 'https://storage.example.com',+ accessKeyId: 'test',+ secretAccessKey: 'test',+ })+ const objects = new Map<string, Buffer>([['photos/original.JPG', original]])+ const writes: { Key: string; ContentType: string }[] = []+ const deletes: string[] = []+ ;(provider as any).client.send = async (command: any) => {+ const input = command.input+ if (command.constructor.name === 'GetObjectCommand')+ return {+ Body: { transformToByteArray: async () => objects.get(input.Key)! },+ }+ if (command.constructor.name === 'PutObjectCommand') {+ writes.push(input)+ objects.set(input.Key, input.Body)+ return {}+ }+ if (command.constructor.name === 'DeleteObjectCommand') {+ deletes.push(input.Key)+ objects.delete(input.Key)+ return {}+ }+ throw new Error('Unexpected S3 command')+ }+ if (failAfterCreate)+ provider.getPublicUrl = () => {+ throw new Error('URL construction failed')+ }+ const adapter = load('server/services/resources/photo-metadata.ts', {+ '../image/exif': { extractExifData: async () => null },+ '../../utils/logger': {+ logger: { image: { error: () => {}, warn: () => {} } },+ },+ }).editPhotoMetadata+ if (failAfterCreate)+ await assert.rejects(+ adapter({ storageKey: 'photos/original.JPG' }, {}, provider),+ /Failed to update photo metadata/,+ )+ else {+ const staged = await adapter(+ { storageKey: 'photos/original.JPG' },+ {},+ provider,+ )+ assert.equal(staged.storageKey, writes[0]!.Key)+ await staged.discard()+ }+ assert.equal(writes.length, 1)+ assert.equal(writes[0]!.ContentType, 'image/jpeg')+ assert.ok(writes[0]!.Key.startsWith('photos/.generated/metadata/'))+ assert.deepEqual(deletes, [writes[0]!.Key])+ assert.deepEqual([...objects.keys()], ['photos/original.JPG'])+ assert.deepEqual(objects.get('photos/original.JPG'), original)+ }+})