From 27bd2ac7689871d0ab7f873e21ccd7443b1b6617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Tue, 25 Aug 2026 05:27:52 +0000 Subject: [PATCH] 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 Officer-Session: 656f5c85-e49a-4f1f-b9f3-042a04b4d043 --- src/servers/api/upload/upload.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/servers/api/upload/upload.ts b/src/servers/api/upload/upload.ts index b7cb970f..c932ec6f 100644 --- a/src/servers/api/upload/upload.ts +++ b/src/servers/api/upload/upload.ts @@ -2,6 +2,7 @@ import { createRouter } from '../../create-router'; import { mkdir } from 'node:fs/promises'; import { join } from 'node:path'; import { getTmpAttachmentsDir, getAttachmentsDir } from '@@/data-path'; +import { writeAtomic } from '@@/write-atomic'; 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. */ @@ -49,8 +50,7 @@ uploadRouter.post('/', async (ctx) => { saveDir = getTmpAttachmentsDir(user.email); } - await mkdir(saveDir, { recursive: true }); - await Bun.write(join(saveDir, filename), buffer); + await writeAtomic(join(saveDir, filename), buffer); // Only an image gets a data URL. Building one for a PDF would mean carrying megabytes through the // browser for a preview nothing renders.