summaryrefslogtreecommitdiff
path: root/packages/backend/src/misc
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-06 18:26:33 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-08 11:23:20 -0400
commit89cab66898f4edb238eee2321564337034dfa2bc (patch)
treeb5eb15d4a45219019dd0b36d229558b0c07e1d20 /packages/backend/src/misc
parentcorrectly parse response errors for logging (diff)
downloadsharkey-89cab66898f4edb238eee2321564337034dfa2bc.tar.gz
sharkey-89cab66898f4edb238eee2321564337034dfa2bc.tar.bz2
sharkey-89cab66898f4edb238eee2321564337034dfa2bc.zip
fix multipart/form-data decoding
Diffstat (limited to 'packages/backend/src/misc')
-rw-r--r--packages/backend/src/misc/create-temp.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/packages/backend/src/misc/create-temp.ts b/packages/backend/src/misc/create-temp.ts
index 6cc896046f..fda63c7a9d 100644
--- a/packages/backend/src/misc/create-temp.ts
+++ b/packages/backend/src/misc/create-temp.ts
@@ -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;
+ }
+}