loadUrlPreview () {
const urlRegex = /(https?):\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi
const foundLinks = this.content.post.match(urlRegex)
if (!foundLinks) {
this.preview = null
return
}
const link = foundLinks[foundLinks.length - 1]
if (!this.preview || this.preview.link !== link) {
chatAxios.post('/cards/preview', {
url: encodeURI(link)
}).then(res => {
if (res.data.data.ogTitle) {
this.preview = {
url: link,
provider: res.data.data.ogSiteName,
domain: new URL(link).hostname,
title: res.data.data.ogTitle,
description: res.data.data.ogDescription,
image: res.data.data.ogImage,
video: res.data.data.ogVideo
}
}
})
}
}
- Copy Link
- Send via Direct Message
7 months ago