feat: add scoped upload tokens

This commit is contained in:
Ludwig Lehnert
2026-06-18 19:17:51 +00:00
parent a2b6054440
commit 0ed32f7623
17 changed files with 592 additions and 95 deletions

View File

@@ -131,14 +131,18 @@ export async function streamBodyToPath(request, options) {
},
});
const writeStream = fs.createWriteStream(targetPath, { flags: 'wx' });
let opened = false;
writeStream.on('open', () => {
opened = true;
});
try {
await pipeline(
Readable.fromWeb(request.body),
counter,
fs.createWriteStream(targetPath, { flags: 'wx' })
);
await pipeline(Readable.fromWeb(request.body), counter, writeStream);
} catch (error) {
await fs.promises.rm(targetPath, { force: true }).catch(() => undefined);
if (opened) {
await fs.promises.rm(targetPath, { force: true }).catch(() => undefined);
}
throw error;
}