@@ -251,23 +251,21 @@ module.exports = class AzureAttachmentsService extends require("./basic") {
251251 } )
252252
253253 // Initiate malware scan if configured
254- if ( this . kind === 'azure' ) {
255- logConfig . debug ( 'Initiating malware scan for uploaded file' , {
256- fileId : metadata . ID ,
257- filename : metadata . filename
258- } )
254+ logConfig . debug ( 'Initiating malware scan for uploaded file' , {
255+ fileId : metadata . ID ,
256+ filename : metadata . filename
257+ } )
259258
260- const scanRequestJob = cds . spawn ( async ( ) => {
261- await scanRequest ( attachments , { ID : metadata . ID } )
262- } )
259+ const scanRequestJob = cds . spawn ( async ( ) => {
260+ await scanRequest ( attachments , { ID : metadata . ID } )
261+ } )
263262
264- scanRequestJob . on ( 'error' , ( err ) => {
265- logConfig . withSuggestion ( 'error' ,
266- 'Failed to initiate malware scan for attachment' , err ,
267- 'Check malware scanner configuration and connectivity' ,
268- { fileId : metadata . ID , filename : metadata . filename , errorMessage : err . message } )
269- } )
270- }
263+ scanRequestJob . on ( 'error' , ( err ) => {
264+ logConfig . withSuggestion ( 'error' ,
265+ 'Failed to initiate malware scan for attachment' , err ,
266+ 'Check malware scanner configuration and connectivity' ,
267+ { fileId : metadata . ID , filename : metadata . filename , errorMessage : err . message } )
268+ } )
271269 } catch ( err ) {
272270 const duration = Date . now ( ) - startTime
273271 logConfig . withSuggestion ( 'error' ,
@@ -428,11 +426,25 @@ module.exports = class AzureAttachmentsService extends require("./basic") {
428426 registerDraftUpdateHandlers ( srv , mediaElements ) {
429427 for ( const mediaElement of mediaElements ) {
430428 srv . prepend ( ( ) => {
431- srv . on (
432- "PUT" ,
433- mediaElement ,
434- this . updateContentHandler . bind ( this )
435- )
429+ if ( mediaElement . drafts ) {
430+ srv . on (
431+ "PUT" ,
432+ mediaElement . drafts ,
433+ this . updateContentHandler . bind ( this )
434+ )
435+
436+ // case: attachments uploaded in draft and deleted before saving
437+ srv . before (
438+ "DELETE" ,
439+ mediaElement . drafts ,
440+ this . attachDraftDeletionData . bind ( this )
441+ )
442+ srv . after (
443+ "DELETE" ,
444+ mediaElement . drafts ,
445+ this . deleteAttachmentsWithKeys . bind ( this )
446+ )
447+ }
436448 } )
437449 }
438450 }
0 commit comments