feat: add scoped upload tokens
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user