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) => {
|
req.on('data', (data: Buffer) => {
|
||||||
if (receivedLength + data.length > size) {
|
if (receivedLength + data.length > size) {
|
||||||
writeStream.destroy();
|
writeStream.destroy();
|
||||||
req.destroy();
|
void this.onCancel(id, path).catch((error: any) =>
|
||||||
void this.onCancel(id, path)
|
this.logger.error(`Failed to remove ${id} after too much data: ${error.message}`),
|
||||||
.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'));
|
if (!res.headersSent) {
|
||||||
|
res.status(400).send('Received more data than specified in content-length');
|
||||||
|
}
|
||||||
|
res.on('finish', () => req.destroy());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
receivedLength += data.length;
|
receivedLength += data.length;
|
||||||
|
|
@ -323,15 +326,7 @@ export class AssetUploadService extends BaseService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('end', () => {
|
req.on('end', () => writeStream.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}`));
|
|
||||||
});
|
|
||||||
|
|
||||||
return writeStream;
|
return writeStream;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue