@@ -20,6 +20,7 @@ const {
20
20
readEnvValue,
21
21
getServiceHostname,
22
22
getByteSize,
23
+ formatByteSize,
23
24
getDuration,
24
25
parseSignedFormData,
25
26
updatePublicInterfaces,
@@ -275,10 +276,35 @@ const configWebhooksSchema = {
275
276
notifyHeaders : Joi . string ( ) . empty ( '' ) . trim ( ) ,
276
277
notifyText : Joi . boolean ( ) . truthy ( 'Y' , 'true' , '1' , 'on' ) . falsy ( 'N' , 'false' , 0 , '' ) . default ( false ) ,
277
278
notifyWebSafeHtml : Joi . boolean ( ) . truthy ( 'Y' , 'true' , '1' , 'on' ) . falsy ( 'N' , 'false' , 0 , '' ) . default ( false ) ,
278
- notifyTextSize : Joi . number ( ) . integer ( ) . empty ( '' ) ,
279
+
280
+ notifyTextSize : Joi . alternatives ( ) . try (
281
+ Joi . number ( ) . empty ( '' ) . integer ( ) . min ( 0 ) ,
282
+ // If it's a string, parse and convert it to bytes
283
+ Joi . string ( ) . custom ( ( value , helpers ) => {
284
+ let nr = getByteSize ( value ) ;
285
+ if ( typeof nr !== 'number' || nr < 0 ) {
286
+ return helpers . error ( 'any.invalid' ) ;
287
+ }
288
+ return nr ;
289
+ } , 'Byte size conversion' )
290
+ ) ,
291
+
279
292
notifyCalendarEvents : Joi . boolean ( ) . truthy ( 'Y' , 'true' , '1' , 'on' ) . falsy ( 'N' , 'false' , 0 , '' ) . default ( false ) ,
280
293
inboxNewOnly : Joi . boolean ( ) . truthy ( 'Y' , 'true' , '1' , 'on' ) . falsy ( 'N' , 'false' , 0 , '' ) . default ( false ) ,
281
294
295
+ notifyAttachments : Joi . boolean ( ) . truthy ( 'Y' , 'true' , '1' , 'on' ) . falsy ( 'N' , 'false' , 0 , '' ) . default ( false ) ,
296
+ notifyAttachmentSize : Joi . alternatives ( ) . try (
297
+ Joi . number ( ) . empty ( '' ) . integer ( ) . min ( 0 ) ,
298
+ // If it's a string, parse and convert it to bytes
299
+ Joi . string ( ) . custom ( ( value , helpers ) => {
300
+ let nr = getByteSize ( value ) ;
301
+ if ( typeof nr !== 'number' || nr < 0 ) {
302
+ return helpers . error ( 'any.invalid' ) ;
303
+ }
304
+ return nr ;
305
+ } , 'Byte size conversion' )
306
+ ) ,
307
+
282
308
customHeaders : Joi . string ( )
283
309
. allow ( '' )
284
310
. trim ( )
@@ -1029,6 +1055,10 @@ function applyRoutes(server, call) {
1029
1055
const notifyWebSafeHtml = ( await settings . get ( 'notifyWebSafeHtml' ) ) || false ;
1030
1056
const notifyTextSize = Number ( await settings . get ( 'notifyTextSize' ) ) || 0 ;
1031
1057
const notifyCalendarEvents = ( await settings . get ( 'notifyCalendarEvents' ) ) || false ;
1058
+
1059
+ const notifyAttachments = ( await settings . get ( 'notifyAttachments' ) ) || false ;
1060
+ const notifyAttachmentSize = Number ( await settings . get ( 'notifyAttachmentSize' ) ) || 0 ;
1061
+
1032
1062
const inboxNewOnly = ( await settings . get ( 'inboxNewOnly' ) ) || false ;
1033
1063
const customHeaders = ( await settings . get ( 'webhooksCustomHeaders' ) ) || [ ] ;
1034
1064
@@ -1047,9 +1077,12 @@ function applyRoutes(server, call) {
1047
1077
. join ( '\n' ) ,
1048
1078
notifyText,
1049
1079
notifyWebSafeHtml,
1050
- notifyTextSize : notifyTextSize ? notifyTextSize : '' ,
1080
+ notifyTextSize : notifyTextSize ? formatByteSize ( notifyTextSize ) : '' ,
1051
1081
notifyCalendarEvents,
1052
1082
1083
+ notifyAttachments,
1084
+ notifyAttachmentSize : notifyAttachmentSize ? formatByteSize ( notifyAttachmentSize ) : '' ,
1085
+
1053
1086
customHeaders : [ ]
1054
1087
. concat ( customHeaders || [ ] )
1055
1088
. map ( entry => `${ entry . key } : ${ entry . value } ` . trim ( ) )
@@ -1109,6 +1142,10 @@ function applyRoutes(server, call) {
1109
1142
notifyWebSafeHtml : request . payload . notifyWebSafeHtml ,
1110
1143
notifyTextSize : request . payload . notifyTextSize || 0 ,
1111
1144
notifyCalendarEvents : request . payload . notifyCalendarEvents ,
1145
+
1146
+ notifyAttachments : request . payload . notifyAttachments ,
1147
+ notifyAttachmentSize : request . payload . notifyAttachmentSize ,
1148
+
1112
1149
inboxNewOnly : request . payload . inboxNewOnly ,
1113
1150
1114
1151
webhookEvents : notificationTypes . filter ( type => ! ! request . payload [ `notify_${ type . name } ` ] ) . map ( type => type . name ) ,
0 commit comments