fix(handler-filter): Filter handler response includes file content sha256 hash ZMS-176 (#739)

* filter handler response includes file content sha256 hash

* fix tests
This commit is contained in:
NickOvt 2024-10-03 11:11:02 +03:00 committed by GitHub
parent 6dac6ae256
commit 37374be439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View file

@ -619,17 +619,21 @@ class Indexer {
}
let node = nodes[pos++];
this.attachmentStorage.create(node, (err, id) => {
this.attachmentStorage.create(node, (err, id, fileContentHash) => {
if (err) {
return callback(err);
}
mimeTree.attachmentMap[node.attachmentId] = id;
let attachmentInfo = maildata.attachments && maildata.attachments.find(a => a.id === node.attachmentId);
let attachmentInfo = maildata.attachments && maildata.attachments.find(a => a.id === node.attachmentId); // get reference to attachment info
if (attachmentInfo && node.body) {
attachmentInfo.size = node.body.length;
}
if (fileContentHash) {
attachmentInfo.fileContentHash = fileContentHash;
}
return storeNode();
});
};

View file

@ -716,6 +716,12 @@ class FilterHandler {
if (binaryHash) {
resp.encodedSha256 = binaryHash.toString('base64');
}
let attachmentInfo = maildata.attachments.find(a => a.id === att.id);
if (attachmentInfo && attachmentInfo.fileContentHash) {
resp.fileContentHash = attachmentInfo.fileContentHash;
}
return resp;
})
},

View file

@ -592,6 +592,7 @@ describe('API tests', function () {
{
contentType: 'image/png',
disposition: 'inline',
fileContentHash: 'SnEfXNA8Cf15ri8Zuy9xFo5xwYt1YmJqGujZnrwyEv8=',
filename: 'attachment-1.png',
hash: '6bb932138c9062004611ca0170d773e78d79154923c5daaf6d8a2f27361c33a2',
id: 'ATT00001',