Fix attachment downloads for zero cdnId
This commit is contained in:
parent
ddbbe3a6b1
commit
e4efa01073
2 changed files with 24 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
/* eslint-disable no-restricted-syntax */
|
/* eslint-disable no-restricted-syntax */
|
||||||
|
|
||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
|
import Long from 'long';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
processDataMessage,
|
processDataMessage,
|
||||||
|
@ -49,6 +50,24 @@ describe('processDataMessage', () => {
|
||||||
assert.deepStrictEqual(out.attachments, [PROCESSED_ATTACHMENT]);
|
assert.deepStrictEqual(out.attachments, [PROCESSED_ATTACHMENT]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should process attachments with 0 cdnId', async () => {
|
||||||
|
const out = await check({
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
...UNPROCESSED_ATTACHMENT,
|
||||||
|
cdnId: new Long(0),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepStrictEqual(out.attachments, [
|
||||||
|
{
|
||||||
|
...PROCESSED_ATTACHMENT,
|
||||||
|
cdnId: undefined,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw on too many attachments', async () => {
|
it('should throw on too many attachments', async () => {
|
||||||
const attachments: Array<Proto.IAttachmentPointer> = [];
|
const attachments: Array<Proto.IAttachmentPointer> = [];
|
||||||
for (let i = 0; i < ATTACHMENT_MAX + 1; i += 1) {
|
for (let i = 0; i < ATTACHMENT_MAX + 1; i += 1) {
|
||||||
|
|
|
@ -43,10 +43,14 @@ export function processAttachment(
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { cdnId } = attachment;
|
||||||
|
const hasCdnId = cdnId instanceof Long ? !cdnId.isZero() : Boolean(cdnId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...shallowDropNull(attachment),
|
...shallowDropNull(attachment),
|
||||||
|
|
||||||
cdnId: attachment.cdnId ? attachment.cdnId.toString() : undefined,
|
cdnId: hasCdnId ? String(cdnId) : undefined,
|
||||||
key: attachment.key ? Bytes.toBase64(attachment.key) : undefined,
|
key: attachment.key ? Bytes.toBase64(attachment.key) : undefined,
|
||||||
digest: attachment.digest ? Bytes.toBase64(attachment.digest) : undefined,
|
digest: attachment.digest ? Bytes.toBase64(attachment.digest) : undefined,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue