mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
better content length handling
This commit is contained in:
parent
0db8c10601
commit
1915e3ceb2
1 changed files with 8 additions and 13 deletions
|
|
@ -310,10 +310,13 @@ export class AssetUploadService extends BaseService {
|
|||
req.on('data', (data: Buffer) => {
|
||||
if (receivedLength + data.length > size) {
|
||||
writeStream.destroy();
|
||||
req.destroy();
|
||||
void this.onCancel(id, path)
|
||||
.catch((error: any) => this.logger.error(`Failed to remove ${id} after too much data: ${error.message}`))
|
||||
.finally(() => res.status(400).send('Received more data than specified in content-length'));
|
||||
void this.onCancel(id, path).catch((error: any) =>
|
||||
this.logger.error(`Failed to remove ${id} after too much data: ${error.message}`),
|
||||
);
|
||||
if (!res.headersSent) {
|
||||
res.status(400).send('Received more data than specified in content-length');
|
||||
}
|
||||
res.on('finish', () => req.destroy());
|
||||
return;
|
||||
}
|
||||
receivedLength += data.length;
|
||||
|
|
@ -323,15 +326,7 @@ export class AssetUploadService extends BaseService {
|
|||
}
|
||||
});
|
||||
|
||||
req.on('end', () => {
|
||||
if (receivedLength === size) {
|
||||
return writeStream.end();
|
||||
}
|
||||
writeStream.destroy();
|
||||
void this.onCancel(id, path)
|
||||
.catch((error: any) => this.logger.error(`Failed to remove ${id} after unexpected length: ${error.message}`))
|
||||
.finally(() => res.status(400).send(`Received ${receivedLength} bytes when expecting ${size}`));
|
||||
});
|
||||
req.on('end', () => writeStream.end());
|
||||
|
||||
return writeStream;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue