Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!data.title || !data.url) {
return;
}
const {description = '', site_name, title = '', url: dataUrl} = data;
const truncatedDescription = truncate(deArrayify(description), config.MAXIMUM_LINK_PREVIEW_CHARS);
const truncatedTitle = truncate(deArrayify(title), config.MAXIMUM_LINK_PREVIEW_CHARS);
const protoArticle = new Article({
permanentUrl: deArrayify(dataUrl),
summary: truncatedDescription,
title: truncatedTitle,
}); // deprecated format
const protoLinkPreview = new LinkPreview({
article: protoArticle,
permanentUrl: deArrayify(dataUrl),
summary: truncatedDescription,
title: truncatedTitle,
url: link,
urlOffset: offset,
});
if (deArrayify(site_name) === 'Twitter' && isTweetUrl(deArrayify(dataUrl))) {
const author = deArrayify(title)
.replace('on Twitter', '')
.trim();
const username = deArrayify(dataUrl).match(/com\/([^/]*)\//)[1];
const protoTweet = new Tweet({author, username});
protoLinkPreview[PROTO_MESSAGE_TYPE.TWEET] = protoTweet;
assetEntity.previews().map(linkPreview => {
linkPreview.obfuscate();
const protoArticle = new Article({permanentUrl: linkPreview.url, title: linkPreview.title}); // deprecated format
const linkPreviewProto = new LinkPreview({
article: protoArticle,
permanentUrl: linkPreview.url,
title: linkPreview.title,
url: linkPreview.url,
urlOffset: 0,
});
return arrayToBase64(LinkPreview.encode(linkPreviewProto).finish());
}),
);
it('maps text messages with deprecated link preview format', async () => {
const event_id = createRandomUuid();
const article = new Article({
permanentUrl: 'test.com',
summary: 'Test description',
title: 'Test title',
});
const link_preview = new LinkPreview({
article,
url: 'test.com',
urlOffset: 0,
});
const base64LinkPreview = await arrayToBase64(LinkPreview.encode(link_preview).finish());
const event = {
conversation: conversation_et.id,
data: {
content: 'test.com',
nonce: event_id,
previews: [base64LinkPreview],
},
from: createRandomUuid,
id: event_id,
it('maps text messages with link preview', async () => {
const event_id = createRandomUuid();
const link_preview = new LinkPreview({
article: null,
permanentUrl: 'test.com/perm',
summary: 'Test description',
title: 'Test title',
url: 'test.com',
urlOffset: 0,
});
const base64Preview = await arrayToBase64(LinkPreview.encode(link_preview).finish());
const event = {
conversation: conversation_et.id,
data: {
content: 'test.com',
nonce: event_id,
previews: [base64Preview],