-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add max file size constraint per user
- Loading branch information
1 parent
1c6c553
commit 09eea33
Showing
10 changed files
with
239 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
web-app/server/src/db/models/FileData/streamDataLimiter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { UserInputError } from "apollo-server-core"; | ||
import { Transform, TransformCallback } from "stream"; | ||
|
||
export class FileSizeLimiter extends Transform { | ||
maxSize: number; | ||
currentSize = 0; | ||
|
||
constructor(maxSize: number) { | ||
super(); | ||
this.maxSize = maxSize; | ||
} | ||
|
||
override _transform( | ||
chunk: any, | ||
encoding: BufferEncoding, | ||
callback: TransformCallback | ||
) { | ||
this.currentSize += chunk.length; | ||
|
||
if (this.currentSize > this.maxSize) { | ||
this.destroy( | ||
new UserInputError( | ||
`Remaining file size of ${this.maxSize} bytes exceeded` | ||
) | ||
); | ||
return; | ||
} | ||
|
||
this.push(chunk); | ||
callback(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.