From 32a12068c69187d5c5f452af60df5d20fad25b67 Mon Sep 17 00:00:00 2001 From: jubnl Date: Thu, 20 Aug 2026 18:50:38 +0200 Subject: [PATCH] =?UTF-8?q?feat(server):=20allow=20mirrors=20on=20any=20st?= =?UTF-8?q?orage=20category=20=E2=80=94=20lift=20the=20backups-only=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/nest/storage/drivers/mirror.driver.ts | 6 +++-- .../nest/storage/storage-registry.service.ts | 3 --- .../storage/storage-registry.service.test.ts | 27 +++++++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/server/src/nest/storage/drivers/mirror.driver.ts b/server/src/nest/storage/drivers/mirror.driver.ts index b89cf91d1..bcdb26996 100644 --- a/server/src/nest/storage/drivers/mirror.driver.ts +++ b/server/src/nest/storage/drivers/mirror.driver.ts @@ -26,8 +26,10 @@ export interface ReplicaFailure { /** * Composite backend: one primary (source of truth) plus best-effort replicas. * Runs entirely over the driver interface — the second in-tree consumer of - * the contract suite. Only the `backups` category may be assigned a mirror - * (registry validation enforces it). + * the contract suite. Any category may be assigned a mirror (the v1 + * backups-only rule was lifted by the replicas-on-primary spec); replica + * writes are synchronous in the request path, which is why hot categories + * carry an advisory in the admin UI rather than a prohibition here. * * Writes hit the primary first and must succeed; replica failures are * reported through `onReplicaFailure` (surfaced as health status), never diff --git a/server/src/nest/storage/storage-registry.service.ts b/server/src/nest/storage/storage-registry.service.ts index 44f4e4e4a..cbae84a22 100644 --- a/server/src/nest/storage/storage-registry.service.ts +++ b/server/src/nest/storage/storage-registry.service.ts @@ -459,8 +459,5 @@ function validateConfig(backends: Map, categories: Map { expect(registry.resolve('files').backendName).toBe('uploads-local'); }); + it('a mirror may serve any category — the backups-only rule is lifted (replicas-on-primary spec)', () => { + const extraRoot = makeTmpDir(); + const { registry, uploadsRoot } = makeRegistry({ + backends: [ + { name: 'extra-local', type: 'local', options: { root: extraRoot } }, + { name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } }, + ], + categories: { covers: 'm' }, + }); + const covers = registry.resolve('covers'); + expect(covers.backendName).toBe('m'); + expect(covers.driver).toBeInstanceOf(MirrorDriver); + expect(covers.keyPrefix).toBe('covers/'); + // Hot-path reads stay free: getLocalPath delegates to the local primary. + expect(covers.driver.getLocalPath!('covers/x.jpg')).toBe( + path.join(fs.realpathSync(uploadsRoot), 'covers/x.jpg'), + ); + }); + it.each([ ['unknown backend name in categories', undefined, JSON.stringify({ files: 'nope' })], - [ - 'mirror assigned to a non-backups category', - JSON.stringify([ - { name: 'extra-local', type: 'local', options: { root: '/tmp/x' } }, - { name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } }, - ]), - JSON.stringify({ files: 'm' }), - ], [ 'nested mirror', JSON.stringify([