@@ -26,7 +26,7 @@ export const verify = async (
2626 if ( algo === 'stream' ) {
2727 sizeBytes = await calculateSizeStream ( value , limitBytes ) ;
2828 } else {
29- sizeBytes = calculateSizeStringify ( value ) ;
29+ sizeBytes = await calculateSizeStringify ( value ) ;
3030 }
3131
3232 if ( sizeBytes > limitBytes ) {
@@ -39,10 +39,13 @@ export const verify = async (
3939 }
4040} ;
4141
42- export const calculateSizeStringify = ( value : any ) : number => {
43- const str = typeof value === 'string' ? value : JSON . stringify ( value ) ;
44- const size_bytes = Buffer . byteLength ( str , 'utf8' ) ;
45- return size_bytes ;
42+ export const calculateSizeStringify = ( value : any ) : Promise < number > => {
43+ return new Promise ( ( resolve ) => {
44+ const str = typeof value === 'string' ? value : JSON . stringify ( value ) ;
45+ const size_bytes = Buffer . byteLength ( str , 'utf8' ) ;
46+ setTimeout ( ( ) => resolve ( size_bytes ) , 10 ) ;
47+ return size_bytes ;
48+ } ) ;
4649} ;
4750
4851export const calculateSizeStream = async (
@@ -87,7 +90,7 @@ export default async (payload: any, limit_mb: number = 10) => {
8790 for ( const key of KEYS_TO_VERIFY ) {
8891 if ( key in payload ) {
8992 try {
90- await verify ( payload [ key ] , limit_mb , 'stream ' ) ;
93+ await verify ( payload [ key ] , limit_mb , 'stringify ' ) ;
9194 } catch ( e : any ) {
9295 if ( e . name === 'PAYLOAD_TOO_LARGE' ) {
9396 Object . assign (
@@ -96,7 +99,7 @@ export default async (payload: any, limit_mb: number = 10) => {
9699 ) ;
97100 newPayload . redacted = true ;
98101 } else {
99- console . log ( e )
102+ console . log ( e ) ;
100103 }
101104 }
102105 }
0 commit comments