kalai-attach 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kalai-attach",
3
3
  "description": "CAP cds-plugin providing image and attachment storing out-of-the-box.",
4
- "version": "1.0.5",
4
+ "version": "1.0.6",
5
5
  "repository": "capjsattachments-kalai",
6
6
  "author": "Kalai",
7
7
  "homepage": "https://github.com/Kalaikovan-airdit",
@@ -110,7 +110,29 @@ module.exports = class AzureAttachmentsService extends require("./object-store")
110
110
 
111
111
  // The file upload has to be done first, so super.put can compute the hash and trigger malware scan
112
112
  await blobClient.upload(_content, contentLength)
113
- await super.put(attachments, metadata)
113
+ // await super.put(attachments, metadata)
114
+
115
+ try {
116
+ const { content, ...metadata } = data;
117
+ const blobName = metadata.url || metadata.ID;
118
+ const blobClient = containerClient.getBlockBlobClient(blobName);
119
+
120
+ // 1. Upload to Azure first (Staging)
121
+ await blobClient.upload(content, content.length);
122
+
123
+ // 2. Call super.put - This triggers the malware scan
124
+ // If the scanner finds a virus, this call will THROW an error
125
+ await super.put(attachments, data);
126
+
127
+ LOG.info(`Scan passed and file uploaded: ${metadata.filename}`);
128
+ } catch (err) {
129
+ // 3. If scan fails (or any other error), clean up Azure
130
+ if (err.code === 403 || err.message.includes('malware')) {
131
+ LOG.error(`Malware detected in ${data.filename}! Deleting from Azure...`);
132
+ await this.delete(data.url || data.ID);
133
+ }
134
+ throw err;
135
+ }
114
136
 
115
137
  const duration = Date.now() - startTime
116
138
  LOG.debug('File upload to Azure Blob Storage completed successfully', {