Mattermost, Inc.

How to fix preview links in chats retaining old urls for pic preview after migrating mm to new domain?

Summary

After moving mattermost to a new domain name and new server (basically moving docker containers and updating the base url) link previews from before the migration still refers to the old url.

Eg, the HTML for a link preview in the previous instance would look like this:

<img class="attachment__image attachment__image--opengraph large_image" aria-label="miniature de fichier" tabindex="0" src="https://mattermost.olddomain.tld/api/v4/image?url=https%3A%2F%2Fmedia.newyorker.com%2Fphotos%2F5b17fc3416b67244b57c2a0a%2F16%3A9%2Fw_1200%2Ch_630%2Cc_limit%2F180618_r32233.jpg">

But in the new instance there’s en empty SVG tag instead:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1120 630" style="max-height: 630px; max-width: 1120px; vertical-align: middle;"></svg>

If I play around with the previous URL and replace the domain, like this:

<img class="attachment__image attachment__image--opengraph large_image" aria-label="miniature de fichier" tabindex="0" src="https://subdomain.newdomain.tld/mattermost/api/v4/image?url=https%3A%2F%2Fmedia.newyorker.com%2Fphotos%2F5b17fc3416b67244b57c2a0a%2F16%3A9%2Fw_1200%2Ch_630%2Cc_limit%2F180618_r32233.jpg">

Then the image is fetched and displayed.

I also have some recursive paths going on sometimes:

https://mattermost.olddomain.tld/mattermost/api/v4/image?url=https%3A%2F%2Fsubdomain.newdomain.tld%2Fmattermost%2Fapi%2Fv4%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.wsj.net%252Fim-20349%252Fsocial

Which leads to:

error fetching remote image: Get https://subdomain.newdomain.tld/mattermost/api/v4/image?url=https%3A%2F%2Fimages.wsj.net%2Fim-20349%2Fsocial#0x0: Get https://subdomain.newdomain.tld/mattermost/api/v4/image?url=https%3A%2F%2Fimages.wsj.net%2Fim-20349%2Fsocial: address forbidden, you may need to set AllowedUntrustedInternalConnections to allow an integration access to your internal network

Any ideas how I could restore link and picture preview in links posted before the migration ?

It also seems half of the link I post don’t generate a preview anymore but that might not be related. Looks like something is timing out ; also, even though both the old server and the new are running the same versions and databases and files the preview link layout is smaller in the new server.

It also doesn’t fetch/display the same OG info.

Thanks :).

I’m not 100% certain about this, so please make a backup of your database first just in case, but I’ve had a look through the Mattermost Server code, and I think the data stored in the LinkMetadata table is a cache of the various metadata that is related to some (or all) of the issues you are seeing here. If it is deleted, it should be recreated with the correct URL on the next request for the effected posts. So, my suggestion is, on your database, do a DELETE from LinkMetadata; and clear that table out, and then see if the problem is resolved.

As I said at the beginning though, make sure to take a backup of your database just in case this has other side-effects I haven’t spotted!

1 Like

Thanks a lot for digging out. Sorry for the late reply, I was afk for a week.

I’ll be trying out your suggestion in the coming days and will let you know how it went.