chat attachments too

the one the sweep missed. an image or a PDF dropped into a chat went
straight to its final name in the attachments directory, and the mkdir
above it was redundant once Bun.write creates the parent chain anyway.

no `Bun.write` left under src/servers/api that is not writeAtomic.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Officer-Session: 656f5c85-e49a-4f1f-b9f3-042a04b4d043
This commit is contained in:
2026-08-25 05:27:52 +00:00
co-authored by Claude Opus 5
parent e87323f71a
commit 27bd2ac768
+2 -2
View File
@@ -2,6 +2,7 @@ import { createRouter } from '../../create-router';
import { mkdir } from 'node:fs/promises'; import { mkdir } from 'node:fs/promises';
import { join } from 'node:path'; import { join } from 'node:path';
import { getTmpAttachmentsDir, getAttachmentsDir } from '@@/data-path'; import { getTmpAttachmentsDir, getAttachmentsDir } from '@@/data-path';
import { writeAtomic } from '@@/write-atomic';
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5 MB const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5 MB
/** PDFs never enter a prompt whole — the agent reads them from disk — so the ceiling is storage, not context. */ /** PDFs never enter a prompt whole — the agent reads them from disk — so the ceiling is storage, not context. */
@@ -49,8 +50,7 @@ uploadRouter.post('/', async (ctx) => {
saveDir = getTmpAttachmentsDir(user.email); saveDir = getTmpAttachmentsDir(user.email);
} }
await mkdir(saveDir, { recursive: true }); await writeAtomic(join(saveDir, filename), buffer);
await Bun.write(join(saveDir, filename), buffer);
// Only an image gets a data URL. Building one for a PDF would mean carrying megabytes through the // Only an image gets a data URL. Building one for a PDF would mean carrying megabytes through the
// browser for a preview nothing renders. // browser for a preview nothing renders.