mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
merge: Check for truncated uploads in Mastodon API (!998)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/998 Approved-by: Marie <github@yuugi.dev> Approved-by: dakkar <dakkar@thenautilus.net>
This commit is contained in:
commit
093f67ae55
2 changed files with 10 additions and 3 deletions
|
@ -30,13 +30,20 @@ export function createTempDir(): Promise<[string, () => void]> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream): Promise<string> {
|
||||
export async function saveToTempFile(stream: NodeJS.ReadableStream & { truncated?: boolean }): Promise<[string, () => void]> {
|
||||
const [filepath, cleanup] = await createTemp();
|
||||
|
||||
try {
|
||||
await pipeline(stream, fs.createWriteStream(filepath));
|
||||
return filepath;
|
||||
} catch (e) {
|
||||
cleanup();
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (stream.truncated) {
|
||||
cleanup();
|
||||
throw new Error('Read failed: input stream truncated');
|
||||
}
|
||||
|
||||
return [filepath, cleanup];
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ export class ServerUtilityService {
|
|||
}
|
||||
} else { // Otherwise it's a file
|
||||
try {
|
||||
const filepath = await saveToTempFile(part.file);
|
||||
const [filepath] = await saveToTempFile(part.file);
|
||||
|
||||
const tmpUploads = (request.tmpUploads ??= []);
|
||||
tmpUploads.push(filepath);
|
||||
|
|
Loading…
Add table
Reference in a new issue