|
@@ -17,7 +17,7 @@ const _ = require('underscore')
|
|
|
const Settings = require('settings-sharelatex')
|
|
const Settings = require('settings-sharelatex')
|
|
|
const request = require('request')
|
|
const request = require('request')
|
|
|
const { Transform, pipeline } = require('stream')
|
|
const { Transform, pipeline } = require('stream')
|
|
|
-const { InvalidError } = require('../Features/Errors/Errors')
|
|
|
|
|
|
|
+const { FileTooLargeError } = require('../Features/Errors/Errors')
|
|
|
const { promisifyAll } = require('../util/promises')
|
|
const { promisifyAll } = require('../util/promises')
|
|
|
|
|
|
|
|
class SizeLimitedStream extends Transform {
|
|
class SizeLimitedStream extends Transform {
|
|
@@ -44,7 +44,7 @@ class SizeLimitedStream extends Transform {
|
|
|
this.bytes += chunk.length
|
|
this.bytes += chunk.length
|
|
|
if (this.sizeLimit && this.bytes > this.sizeLimit) {
|
|
if (this.sizeLimit && this.bytes > this.sizeLimit) {
|
|
|
return done(
|
|
return done(
|
|
|
- new InvalidError({
|
|
|
|
|
|
|
+ new FileTooLargeError({
|
|
|
message: 'stream size limit reached',
|
|
message: 'stream size limit reached',
|
|
|
info: { size: this.bytes }
|
|
info: { size: this.bytes }
|
|
|
})
|
|
})
|
|
@@ -130,6 +130,15 @@ const FileWriter = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pipeline(stream, passThrough, writeStream, function(err) {
|
|
pipeline(stream, passThrough, writeStream, function(err) {
|
|
|
|
|
+ if (
|
|
|
|
|
+ passThrough.bytes >= options.maxSizeBytes &&
|
|
|
|
|
+ !(err instanceof FileTooLargeError)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ err = new FileTooLargeError({
|
|
|
|
|
+ message: 'stream size limit reached',
|
|
|
|
|
+ info: { size: passThrough.bytes }
|
|
|
|
|
+ }).withCause(err || {})
|
|
|
|
|
+ }
|
|
|
if (err) {
|
|
if (err) {
|
|
|
logger.warn(
|
|
logger.warn(
|
|
|
{ err, identifier, fsPath },
|
|
{ err, identifier, fsPath },
|