feat: store editor images in upload bind

This commit is contained in:
2026-08-06 15:52:54 +00:00
parent 9046a131f2
commit dc0e1a6da9
8 changed files with 91 additions and 27 deletions
+16 -4
View File
@@ -13,19 +13,20 @@ test('stores uploads only in the bind directory and persists replay state', asyn
const filename = `${'a'.repeat(32)}.png`;
const store = new UploadStore(config);
await store.initialize();
const first = await store.store({ requestKey: 'core2026:request-1', client: 'core2026', filename, body });
const first = await store.store({ requestKey: 'core2026:request-1', category: 'user-icons', client: 'core2026', filename, body });
assert.deepEqual(first, { duplicate: false, path: `icons/users/core2026/${filename}` });
assert.equal(await readFile(join(root, 'uploads', 'core2026', filename), 'utf8'), 'immutable image bytes');
assert.equal(await readFile(join(root, 'uploads', 'user-icons', 'core2026', filename), 'utf8'), 'immutable image bytes');
const restarted = new UploadStore(config);
await restarted.initialize();
assert.deepEqual(
await restarted.store({ requestKey: 'core2026:request-1', client: 'core2026', filename, body }),
await restarted.store({ requestKey: 'core2026:request-1', category: 'user-icons', client: 'core2026', filename, body }),
{ duplicate: true, path: `icons/users/core2026/${filename}` },
);
await assert.rejects(
restarted.store({
requestKey: 'core2026:request-1',
category: 'user-icons',
client: 'core2026',
filename: `${'b'.repeat(32)}.png`,
body,
@@ -33,7 +34,18 @@ test('stores uploads only in the bind directory and persists replay state', asyn
/already used/,
);
await assert.rejects(
restarted.store({ requestKey: 'core2026:request-2', client: '../escape', filename, body }),
restarted.store({ requestKey: 'core2026:request-2', category: 'user-icons', client: '../escape', filename, body }),
/Invalid upload path/,
);
const contentFilename = `${'c'.repeat(32)}.webp`;
assert.deepEqual(
await restarted.store({
requestKey: 'core2026:content-1',
category: 'content',
client: 'core2026',
filename: contentFilename,
body: Buffer.from('content image'),
}),
{ duplicate: false, path: `uploads/core2026/${contentFilename}` },
);
});