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(cloud): preserve rotated storage access and atomic cleanup
Timothy Yin8faa557940d5
diff --git a/.github/workflows/deploy-saas.yml b/.github/workflows/deploy-saas.ymlindex fccc8b99..c2438d26 100644--- a/.github/workflows/deploy-saas.yml+++ b/.github/workflows/deploy-saas.yml@@ -144,6 +144,11 @@ jobs:run: |node --input-type=module <<'NODE'if (process.env.PLATFORM_D1_DATABASE_ID) {+ if ((process.env.PLATFORM_STORAGE_SECRET || '').length < 32) throw new Error('Configure PLATFORM_STORAGE_SECRET with at least 32 characters in the selected GitHub Environment secrets')+ if (process.env.ENTRIES.split(/\s+/).includes('cloud') && (process.env.PLATFORM_WORKER_SECRET || '').length < 32) throw new Error('Configure PLATFORM_WORKER_SECRET with at least 32 characters in the selected GitHub Environment secrets')+ for (const host of (process.env.PLATFORM_S3_ENDPOINT_HOSTS || '').split(',').filter(Boolean)) {+ if (!/^[a-z0-9.-]+$/i.test(host.trim())) throw new Error('PLATFORM_S3_ENDPOINT_HOSTS must contain exact hostnames')+ }for (const entry of process.env.ENTRIES.split(/\s+/).filter(Boolean)) {const key = entry === 'cloud' ? 'CLOUD_PLATFORM_SECRET' : 'SITE_PLATFORM_SECRET'if ((process.env[key] || '').length < 32) throw new Error(`Configure ${key} with at least 32 characters in the selected GitHub Environment secrets`)diff --git a/apps/cloud/app/components/CloudMediaWorkbench.vue b/apps/cloud/app/components/CloudMediaWorkbench.vueindex 771ee250..e9f32520 100644--- a/apps/cloud/app/components/CloudMediaWorkbench.vue+++ b/apps/cloud/app/components/CloudMediaWorkbench.vue@@ -135,7 +135,7 @@ async function loadPhoto() {const data = await api<{ photo: Photo; revision: number }>(base.value + '/photos/' + editPhoto.id,)- editPhoto.title = data.photo.title+ editPhoto.title = data.photo.title ?? 'Untitled photograph'editPhoto.description = data.photo.description ?? ''editPhoto.revision = data.revision}@@ -202,8 +202,8 @@ async function sendFile(file: File, liveVideo?: File) {localStorage.setItem(cache, id)activeResumeKey = cacheif (controller?.signal.aborted) {- await api(base.value + '/uploads/' + id, {- method: 'DELETE',+ await api(base.value + '/uploads/' + id + '/cancel', {+ method: 'POST',body: {},}).catch(() => {})localStorage.removeItem(cache)@@ -224,8 +224,12 @@ async function sendFile(file: File, liveVideo?: File) {localStorage.removeItem(cache)return}- if (plan.state !== 'pending' || !plan.mode)+ if (plan.state !== 'pending' || !plan.mode) {+ localStorage.removeItem(cache)+ activeResumeKey = undefined+ activeUpload = undefinedthrow new Error('Upload unavailable')+ }async function put(url: string, body: Blob, type?: string) {for (let attempt = 0; attempt < 3; attempt++) {controller?.signal.throwIfAborted()@@ -317,8 +321,8 @@ async function cancel() {if (activeResumeKey) localStorage.removeItem(activeResumeKey)activeResumeKey = undefinedif (activeUpload)- await api(base.value + '/uploads/' + activeUpload, {- method: 'DELETE',+ await api(base.value + '/uploads/' + activeUpload + '/cancel', {+ method: 'POST',body: {},}).catch(() => {})activeUpload = undefined@@ -331,7 +335,11 @@ async function removePhoto(id: string) {)returnawait action(- () => api(base.value + '/photos/' + id, { method: 'DELETE', body: {} }),+ () =>+ api(base.value + '/photos/' + id + '/delete', {+ method: 'POST',+ body: {},+ }),'Photograph deleted. Managed storage files are queued for cleanup.',)}@@ -357,8 +365,8 @@ async function removeAlbum() {returnawait action(() =>- api(base.value + '/albums/' + albumId.value, {- method: 'DELETE',+ api(base.value + '/albums/' + albumId.value + '/delete', {+ method: 'POST',body: {},}),'Album deleted. Photographs remain in your library.',@@ -374,8 +382,8 @@ async function removeFromAlbum() {returnawait action(() =>- api(base.value + '/albums/' + albumId.value + '/photos', {- method: 'DELETE',+ api(base.value + '/albums/' + albumId.value + '/remove-photo', {+ method: 'POST',body: { photoId: photoId.value },}),'Photograph removed from album.',diff --git a/apps/cloud/server/api/internal/worker/[action].post.ts b/apps/cloud/server/api/internal/worker/[action].post.tsindex b41c23e2..4f81a0b6 100644--- a/apps/cloud/server/api/internal/worker/[action].post.ts+++ b/apps/cloud/server/api/internal/worker/[action].post.ts@@ -53,7 +53,7 @@ export default definePlatformHandler(async (event) => {raw,siteId,await createStorageCipher(config.storageSecret),- ).get(id, revision)+ ).resolve(id, revision)if (!item) throw createError({ statusCode: 503 })return createCloudS3({ ...item.config, ...item.credentials },diff --git a/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts b/apps/cloud/server/api/sites/[siteId]/media/[...operation].tsindex c929d157..9a7ce19a 100644--- a/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts+++ b/apps/cloud/server/api/sites/[siteId]/media/[...operation].ts@@ -36,7 +36,8 @@ export default definePlatformHandler(async (event) => {const { siteId, userId, site, db, raw, sql, repository, vault } = ctxconst operation = getRouterParam(event, 'operation') ?? ''const [kind, id, action] = operation.split('/')- const body = mutation ? await siteManagementBody(event) : {}+ const body =+ mutation && event.method !== 'DELETE' ? await siteManagementBody(event) : {}const now = Date.now()if (kind === 'storage' && !id) {if (event.method === 'GET') return { connections: await vault.list() }@@ -265,38 +266,30 @@ export default definePlatformHandler(async (event) => {urls,}}- if (event.method === 'DELETE') {+ if (+ event.method === 'DELETE' ||+ (event.method === 'POST' && action === 'cancel')+ ) {if (upload.state !== 'pending') throw createError({ statusCode: 409 })- await repository.cancelUpload(id, userId)- await db.batch([- db+ const changes = await raw.batch([+ raw.prepare(- `INSERT INTO cloud_cleanup_requests(site_id,id,connection_id,connection_revision,object_key,provider_upload_id,available_at) VALUES(?,?,?,?,?,?,?) ON CONFLICT DO NOTHING`,+ `INSERT INTO cloud_cleanup_requests(site_id,id,connection_id,connection_revision,object_key,provider_upload_id,available_at) SELECT site_id,'upload-'||id,connection_id,connection_revision,object_key,provider_upload_id,? FROM cloud_uploads WHERE site_id=? AND id=? AND owner_id=? AND state='pending' ON CONFLICT DO NOTHING`,)- .bind(- siteId,- 'upload-' + id,- upload.connection_id,- detail.connection_revision,- upload.object_key,- upload.provider_upload_id,- now + 360000,- ),- ])- if (detail.video_key)- await raw+ .bind(now + 360000, siteId, id, userId),+ raw.prepare(- `INSERT INTO cloud_cleanup_requests(site_id,id,connection_id,connection_revision,object_key,available_at) VALUES(?,?,?,?,?,?) ON CONFLICT DO NOTHING`,+ `INSERT INTO cloud_cleanup_requests(site_id,id,connection_id,connection_revision,object_key,available_at) SELECT site_id,'upload-video-'||id,connection_id,connection_revision,video_key,? FROM cloud_uploads WHERE site_id=? AND id=? AND owner_id=? AND state='pending' AND video_key IS NOT NULL ON CONFLICT DO NOTHING`,)- .bind(- siteId,- 'upload-video-' + id,- upload.connection_id,- detail.connection_revision,- detail.video_key,- now + 360000,+ .bind(now + 360000, siteId, id, userId),+ raw+ .prepare(+ `UPDATE cloud_uploads SET state='cancelled' WHERE site_id=? AND id=? AND owner_id=? AND state='pending'`,)- .run()+ .bind(siteId, id, userId),+ ])+ if (!(changes[2] as { meta?: { changes?: number } }).meta?.changes)+ throw createError({ statusCode: 409 })return { ok: true }}if (event.method === 'POST' && action === 'complete') {@@ -396,14 +389,26 @@ export default definePlatformHandler(async (event) => {if (!changed) throw createError({ statusCode: 409 })return { revision: revision + 1 }}- if (kind === 'photos' && id && event.method === 'DELETE') {+ if (+ kind === 'photos' &&+ id &&+ (event.method === 'DELETE' ||+ (event.method === 'POST' && action === 'delete'))+ ) {const found = await raw.prepare('SELECT id FROM cloud_photos WHERE site_id=? AND id=?').bind(siteId, ID(id)).first()if (!found) throw createError({ statusCode: 404 })- await repository.deletePhoto(id)await db.batch([+ db+ .prepare('UPDATE cloud_photos SET deleted=1 WHERE site_id=? AND id=?')+ .bind(siteId, id),+ db+ .prepare(+ "UPDATE cloud_processing_jobs SET state='cancelled' WHERE site_id=? AND photo_id=? AND state IN ('queued','running','retry_wait')",+ )+ .bind(siteId, id),db.prepare(`INSERT INTO cloud_cleanup_requests(site_id,id,connection_id,connection_revision,object_key,provider_upload_id,available_at) SELECT site_id,'original-'||id,connection_id,connection_revision,object_key,NULL,? FROM cloud_uploads WHERE site_id=? AND photo_id=? ON CONFLICT DO NOTHING`,@@ -445,18 +450,24 @@ export default definePlatformHandler(async (event) => {return { id: Number(albumId) }}}- if (kind === 'albums' && id && event.method === 'DELETE') {+ if (+ kind === 'albums' &&+ id &&+ (event.method === 'DELETE' ||+ (event.method === 'POST' &&+ ['delete', 'remove-photo'].includes(action ?? '')))+ ) {const albumId = String(number(Number(id)))if (!(await repository.album(albumId)))throw createError({ statusCode: 404 })- if (action === 'photos') {+ if (action === 'photos' || action === 'remove-photo') {await raw.prepare('DELETE FROM cloud_album_photos WHERE site_id=? AND album_id=? AND photo_id=?',).bind(siteId, albumId, ID(body.photoId)).run()- } else if (!action) {+ } else if (!action || action === 'delete') {await raw.batch([raw.prepare(diff --git a/apps/cloud/server/utils/cloud-media.ts b/apps/cloud/server/utils/cloud-media.tsindex 44e52bce..b6f9a30c 100644--- a/apps/cloud/server/utils/cloud-media.ts+++ b/apps/cloud/server/utils/cloud-media.ts@@ -58,7 +58,7 @@ export async function cloudMedia(event: H3Event, mutation = false) {.map((h) => h.trim()).filter(Boolean)async function storage(id: string, revision?: number) {- const item = await vault.get(id, revision)+ const item = await vault.resolve(id, revision)if (!item) throw createError({ statusCode: 404 })return {revision: item.revision,diff --git a/apps/shared/platform/media.ts b/apps/shared/platform/media.tsindex 3c88ea42..a598bd6e 100644--- a/apps/shared/platform/media.ts+++ b/apps/shared/platform/media.ts@@ -103,7 +103,7 @@ export async function privateMedia(siteId,await createStorageCipher(config.storageSecret),)- const stored = await vault.get(+ const stored = await vault.resolve(object.connection_id,object.connection_revision,)diff --git a/packages/database/src/cloud-media.ts b/packages/database/src/cloud-media.tsindex b43483c5..eae88264 100644--- a/packages/database/src/cloud-media.ts+++ b/packages/database/src/cloud-media.ts@@ -74,6 +74,8 @@ export function createCloudMediaRepository()},async createAlbum(id: string, title: string) {+ if (!/^[1-9][0-9]*$/.test(id) || !Number.isSafeInteger(Number(id)))+ throw new CoreError(400, 'Canonical numeric album ID required')await db.batch([statement('INSERT INTO cloud_albums(site_id,id,title) SELECT ?,?,? WHERE (SELECT COUNT(*) FROM cloud_albums WHERE site_id=?)<100 ON CONFLICT DO NOTHING',diff --git a/packages/database/src/cloud-resources.ts b/packages/database/src/cloud-resources.tsindex d2db6c6d..2e19635d 100644--- a/packages/database/src/cloud-resources.ts+++ b/packages/database/src/cloud-resources.ts@@ -64,7 +64,9 @@ export function createCloudResourceRepository(id: Number(r.id),title: String(r.title),description: r.description ? String(r.description) : null,- coverPhotoId: r.cover_photo_id ? String(r.cover_photo_id) : null,+ coverPhotoId: r.ready_cover_photo_id+ ? String(r.ready_cover_photo_id)+ : null,isHidden: !!r.hidden,position: Number(r.position),createdAt: new Date(Number(r.created_at)).toISOString(),@@ -73,7 +75,7 @@ export function createCloudResourceRepository(},passwordHash: r.password_hash ? String(r.password_hash) : null,})- const albumSelect = `SELECT a.*,v.password_hash FROM cloud_albums a LEFT JOIN platform_album_access v ON v.site_id=a.site_id AND CAST(v.album_id AS TEXT)=a.id WHERE a.site_id=?`+ const albumSelect = `SELECT a.*,v.password_hash,(SELECT p.id FROM cloud_photos p WHERE p.site_id=a.site_id AND p.id=a.cover_photo_id AND ${ready}) AS ready_cover_photo_id FROM cloud_albums a LEFT JOIN platform_album_access v ON v.site_id=a.site_id AND CAST(v.album_id AS TEXT)=a.id WHERE a.site_id=?`async function memberships(photoId?: string) {return (await all<{@@ -132,7 +134,7 @@ export function createCloudResourceRepository(async listAlbumPhotoIds(id) {return (await all<{ photo_id: string }>(- 'SELECT photo_id FROM cloud_album_photos WHERE site_id=? AND album_id=? ORDER BY position,photo_id LIMIT 1000',+ `SELECT a.photo_id FROM cloud_album_photos a JOIN cloud_photos p ON p.site_id=a.site_id AND p.id=a.photo_id WHERE a.site_id=? AND a.album_id=? AND ${ready} ORDER BY a.position,a.photo_id LIMIT 1000`,String(id),)).map((r) => r.photo_id)diff --git a/packages/platform/migrations/0005_media_catalog.sql b/packages/platform/migrations/0005_media_catalog.sqlindex db36bc33..35ed0e85 100644--- a/packages/platform/migrations/0005_media_catalog.sql+++ b/packages/platform/migrations/0005_media_catalog.sql@@ -31,7 +31,6 @@ CREATE TABLE cloud_uploads (object_key TEXT NOT NULL,provider_upload_id TEXT,expected_bytes INTEGER NOT NULL CHECK (expected_bytes > 0),- expected_video_bytes INTEGER NOT NULL DEFAULT 0 CHECK(expected_video_bytes>=0),expires_at INTEGER NOT NULL,state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','completed','cancelled')),PRIMARY KEY (site_id,id),@@ -53,12 +52,3 @@ CREATE TABLE cloud_processing_jobs ();CREATE INDEX cloud_jobs_dispatch ON cloud_processing_jobs(site_id,state,created_at,id);CREATE INDEX cloud_uploads_expiry ON cloud_uploads(site_id,state,expires_at);--CREATE TABLE cloud_usage_events (- site_id INTEGER NOT NULL,- upload_id TEXT NOT NULL,- bytes INTEGER NOT NULL,- created_at INTEGER NOT NULL,- PRIMARY KEY(site_id,upload_id),- FOREIGN KEY(site_id,upload_id) REFERENCES cloud_uploads(site_id,id)-);diff --git a/packages/platform/migrations/0009_cloud_usage_events.sql b/packages/platform/migrations/0009_cloud_usage_events.sqlnew file mode 100644index 00000000..678f2020--- /dev/null+++ b/packages/platform/migrations/0009_cloud_usage_events.sql@@ -0,0 +1,10 @@+ALTER TABLE cloud_uploads ADD COLUMN expected_video_bytes INTEGER NOT NULL DEFAULT 0 CHECK(expected_video_bytes>=0);++CREATE TABLE cloud_usage_events (+ site_id INTEGER NOT NULL,+ upload_id TEXT NOT NULL,+ bytes INTEGER NOT NULL,+ created_at INTEGER NOT NULL,+ PRIMARY KEY(site_id,upload_id),+ FOREIGN KEY(site_id,upload_id) REFERENCES cloud_uploads(site_id,id)+);diff --git a/packages/platform/src/storage-vault.ts b/packages/platform/src/storage-vault.tsindex afec465b..a590bb74 100644--- a/packages/platform/src/storage-vault.ts+++ b/packages/platform/src/storage-vault.ts@@ -68,6 +68,30 @@ export function createStorageVault(),}},+ /** Object revisions pin bucket metadata; rotation replaces credentials for that same connection. */+ async resolve(id: string, revision?: number) {+ validId(id)+ const row = await db+ .prepare(+ `SELECT v.revision,v.public_json,c.current_revision,k.secret_ciphertext FROM cloud_storage_connections c JOIN cloud_storage_versions v ON v.site_id=c.site_id AND v.connection_id=c.id AND v.revision=COALESCE(?,c.current_revision) JOIN cloud_storage_versions k ON k.site_id=c.site_id AND k.connection_id=c.id AND k.revision=c.current_revision WHERE c.site_id=? AND c.id=?`,+ )+ .bind(revision ?? null, siteId, id)+ .first<{+ revision: number+ public_json: string+ current_revision: number+ secret_ciphertext: string+ }>()+ if (!row) return null+ return {+ revision: row.revision,+ config: JSON.parse(row.public_json) as CloudStoragePublic,+ credentials: await cipher.open(+ row.secret_ciphertext,+ aad(id, row.current_revision),+ ),+ }+ },async create(id: string,config: CloudStoragePublic,diff --git a/tests/cloud-execution.test.ts b/tests/cloud-execution.test.tsindex 5bbee050..f26dcb77 100644--- a/tests/cloud-execution.test.ts+++ b/tests/cloud-execution.test.ts@@ -34,6 +34,7 @@ test('D1 queue serializes claims, fences expired attempts, retries and refuses d'0005_media_catalog.sql','0006_cloud_execution.sql','0007_cloud_storage.sql',+ '0009_cloud_usage_events.sql',]) {const migration = await readFile(new URL('../packages/platform/migrations/' + name, import.meta.url),diff --git a/tests/cloud-media-repositories.test.ts b/tests/cloud-media-repositories.test.tsindex 6ad083cd..017a0510 100644--- a/tests/cloud-media-repositories.test.ts+++ b/tests/cloud-media-repositories.test.ts@@ -90,19 +90,44 @@ for (const backend of ['SQLite', 'D1'] as const) {await run("INSERT INTO platform_sites(id,workspace_id,name,published) VALUES(1,1,'One',0),(2,1,'Two',0)",)- const migration = await readFile(- new URL(- '../packages/platform/migrations/0005_media_catalog.sql',- import.meta.url,- ),- 'utf8',- )+ const migration =+ (await readFile(+ new URL(+ '../packages/platform/migrations/0005_media_catalog.sql',+ import.meta.url,+ ),+ 'utf8',+ )) ++ '\n' ++ (await readFile(+ new URL(+ '../packages/platform/migrations/0009_cloud_usage_events.sql',+ import.meta.url,+ ),+ 'utf8',+ ))for (const part of migration.replace(/^--.*$/gm, '').split(';').map((s) => s.trim())- .filter(Boolean))+ .filter(Boolean)) {+ if (part.startsWith('ALTER TABLE cloud_uploads'))+ await run(+ "INSERT INTO cloud_uploads(site_id,id,owner_id,photo_id,source_version,connection_id,object_key,expected_bytes,expires_at) VALUES(1,'pre-upgrade',1,'pre-upgrade','v1','storage-1','originals/pre-upgrade',42,1000)",+ )await run(part)+ }+ assert.equal(+ (+ await db+ .prepare(+ "SELECT expected_video_bytes FROM cloud_uploads WHERE site_id=1 AND id='pre-upgrade'",+ )+ .all<{ expected_video_bytes: number }>()+ ).results[0]?.expected_video_bytes,+ 0,+ )+assert.equal((await db@@ -159,26 +184,26 @@ for (const backend of ['SQLite', 'D1'] as const) {await b.completeUpload({ ...complete('same'), title: 'Other tenant' })assert.equal((await a.photo('same'))?.title, 'Photo')assert.equal((await b.photo('same'))?.title, 'Other tenant')- await a.createAlbum('album', 'My album')- await a.createAlbum('album', 'My album')- await assert.rejects(a.createAlbum('album', 'Other'), { statusCode: 409 })- await a.addToAlbum('album', 'same')- await a.addToAlbum('album', 'same')- assert.equal((await a.albumPhotos('album')).length, 1)- assert.equal((await a.albumPhotos('album', 'same')).length, 0)- assert.equal(await b.album('album'), null)- await b.createAlbum('other-album', 'Other')- await assert.rejects(b.addToAlbum('album', 'same'))- await assert.rejects(a.addToAlbum('album', 'missing'))+ for (const id of ['album', '0', '01', '-1', '1.2', '9007199254740992'])+ await assert.rejects(a.createAlbum(id, 'Invalid'), { statusCode: 400 })+ await a.createAlbum('1', 'My album')+ await a.createAlbum('1', 'My album')+ await assert.rejects(a.createAlbum('1', 'Other'), { statusCode: 409 })+ await a.addToAlbum('1', 'same')+ await a.addToAlbum('1', 'same')+ assert.equal((await a.albumPhotos('1')).length, 1)+ assert.equal((await a.albumPhotos('1', 'same')).length, 0)+ assert.equal(await b.album('1'), null)+ await b.createAlbum('2', 'Other')+ await assert.rejects(b.addToAlbum('1', 'same'))+ await assert.rejects(a.addToAlbum('1', 'missing'))// Foreign key failure in the second operation must roll back the first.await assert.rejects(db.batch([db.prepare("INSERT INTO cloud_albums VALUES(1,'rolled-back','Rollback')",),- db.prepare(- "INSERT INTO cloud_album_photos VALUES(2,'other-album','missing')",- ),+ db.prepare("INSERT INTO cloud_album_photos VALUES(2,'2','missing')"),]),)assert.equal(await a.album('rolled-back'), null)@@ -199,9 +224,9 @@ for (const backend of ['SQLite', 'D1'] as const) {})await a.deletePhoto('same')assert.equal(await a.photo('same'), null)- await assert.rejects(a.addToAlbum('album', 'same'), { statusCode: 404 })+ await assert.rejects(a.addToAlbum('1', 'same'), { statusCode: 404 })assert.equal((await a.job('same'))?.state, 'cancelled')- assert.equal((await a.albumPhotos('album')).length, 0)+ assert.equal((await a.albumPhotos('1')).length, 0)assert.equal((await b.photo('same'))?.title, 'Other tenant')assert.equal(await a.completeUpload(complete('same')), 'same')assert.equal(await a.photo('same'), null) // retry cannot resurrect a tombstone@@ -246,13 +271,22 @@ test('D1 media sessions and queued jobs survive a workerd restart', async () =>'INSERT INTO platform_users VALUES(1)',])await db.prepare(sql).run()- const migration = await readFile(- new URL(- '../packages/platform/migrations/0005_media_catalog.sql',- import.meta.url,- ),- 'utf8',- )+ const migration =+ (await readFile(+ new URL(+ '../packages/platform/migrations/0005_media_catalog.sql',+ import.meta.url,+ ),+ 'utf8',+ )) ++ '\n' ++ (await readFile(+ new URL(+ '../packages/platform/migrations/0009_cloud_usage_events.sql',+ import.meta.url,+ ),+ 'utf8',+ ))for (const sql of migration.replace(/^--.*$/gm, '').split(';')diff --git a/tests/cloud-resource-parity.test.ts b/tests/cloud-resource-parity.test.tsindex 40e3611c..866862d0 100644--- a/tests/cloud-resource-parity.test.ts+++ b/tests/cloud-resource-parity.test.ts@@ -197,6 +197,30 @@ test('Cloud D1 and Self-hosted SQLite share ordering, visibility and protected-a'/api/public/media/locked/display',)assert(!JSON.stringify(unlocked).includes('source/locked'))+ await db+ .prepare(+ "UPDATE cloud_albums SET cover_photo_id='old' WHERE site_id=1 AND id='1'",+ )+ .run()+ await media.deletePhoto('old')+ await db+ .prepare(+ "UPDATE cloud_photos SET metadata_json=NULL WHERE site_id=1 AND id='new'",+ )+ .run()+ const current = createCloudResourceRepository(+ db,+ { id: 1 },+ '/api/public/media',+ )+ assert.deepEqual(await current.listAlbumPhotoIds(1), ['hidden', 'locked'])+ assert.equal((await current.getAlbum(1))?.resource.coverPhotoId, null)+ assert.deepEqual(+ (await createResourceReader(current).listAlbums({ admin: false })).find(+ (a) => a.id === 1,+ )?.photoIds,+ [],+ )} finally {sqlite.close()await mf.dispose()diff --git a/tests/cloud-storage.test.ts b/tests/cloud-storage.test.tsindex 579066e5..2a1f95c8 100644--- a/tests/cloud-storage.test.ts+++ b/tests/cloud-storage.test.ts@@ -99,6 +99,7 @@ test('Credential vault authenticates Site/revision, keeps old objects usable and'0005_media_catalog.sql','0006_cloud_execution.sql','0007_cloud_storage.sql',+ '0009_cloud_usage_events.sql',]) {const migration = await readFile(new URL('../packages/platform/migrations/' + name, import.meta.url),@@ -154,6 +155,13 @@ test('Credential vault authenticates Site/revision, keeps old objects usable and])assert.equal(rotated.filter(Boolean).length, 1)assert.equal((await vault.get('storage'))?.revision, 2)+ const resolved = await vault.resolve('storage', 1)+ assert.equal(resolved?.revision, 1)+ assert.equal(+ resolved?.credentials.secretAccessKey,+ (await vault.get('storage'))?.credentials.secretAccessKey,+ )+ assert.equal(resolved?.config.bucket, config.bucket)assert.equal((await vault.get('storage', 1))?.credentials.secretAccessKey,secretAccessKey,