Skip to content

Commit 47700a6

Browse files
committed
Refactor malware scan initiation for AWS and Azure attachment services
1 parent 8c1f81c commit 47700a6

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

lib/aws-s3.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,23 +274,21 @@ module.exports = class AWSAttachmentsService extends require("./basic") {
274274
})
275275

276276
// Initiate malware scan if configured
277-
if (this.kind === 's3') {
278-
logConfig.debug('Initiating malware scan for uploaded file', {
279-
fileId: metadata.ID,
280-
filename: metadata.filename
281-
})
277+
logConfig.debug('Initiating malware scan for uploaded file', {
278+
fileId: metadata.ID,
279+
filename: metadata.filename
280+
})
282281

283-
const scanRequestJob = cds.spawn(async () => {
284-
await scanRequest(attachments, { ID: metadata.ID })
285-
})
282+
const scanRequestJob = cds.spawn(async () => {
283+
await scanRequest(attachments, { ID: metadata.ID })
284+
})
286285

287-
scanRequestJob.on('error', (err) => {
288-
logConfig.withSuggestion('error',
289-
'Failed to initiate malware scan for attachment', err,
290-
'Check malware scanner configuration and connectivity',
291-
{ fileId: metadata.ID, filename: metadata.filename, errorMessage: err.message })
292-
})
293-
}
286+
scanRequestJob.on('error', (err) => {
287+
logConfig.withSuggestion('error',
288+
'Failed to initiate malware scan for attachment', err,
289+
'Check malware scanner configuration and connectivity',
290+
{ fileId: metadata.ID, filename: metadata.filename, errorMessage: err.message })
291+
})
294292
} catch (err) {
295293
const duration = Date.now() - startTime
296294
logConfig.withSuggestion('error',

lib/azure-blob-storage.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)