fix multipart/form-data decoding
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import fs from 'node:fs';
|
||||
import * as tmp from 'tmp';
|
||||
|
||||
export function createTemp(): Promise<[string, () => void]> {
|
||||
@@ -27,3 +29,14 @@ export function createTempDir(): Promise<[string, () => void]> {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream): Promise<string> {
|
||||
const [filepath, cleanup] = await createTemp();
|
||||
try {
|
||||
await pipeline(stream, fs.createWriteStream(filepath));
|
||||
return filepath;
|
||||
} catch (e) {
|
||||
cleanup();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user