1
0
Fork 0

Prioritise local instance unfurl over remote

This commit is contained in:
Lim Chee Aun 2023-12-28 11:58:50 +08:00
parent 39bcb01894
commit e13a2feec8

View file

@ -2364,9 +2364,18 @@ function _unfurlMastodonLink(instance, url) {
}
if (remoteInstanceFetch) {
return Promise.any([remoteInstanceFetch, mastoSearchFetch])
.then(handleFulfill)
.catch(handleCatch);
// return Promise.any([remoteInstanceFetch, mastoSearchFetch])
// .then(handleFulfill)
// .catch(handleCatch);
// If mastoSearchFetch is fulfilled within 3s, return it, else return remoteInstanceFetch
const finalPromise = Promise.race([
mastoSearchFetch,
new Promise((resolve, reject) => setTimeout(reject, 3000)),
]).catch(() => {
// If remoteInstanceFetch is fullfilled, return it, else return mastoSearchFetch
return remoteInstanceFetch.catch(() => mastoSearchFetch);
});
return finalPromise.then(handleFulfill).catch(handleCatch);
} else {
return mastoSearchFetch.then(handleFulfill).catch(handleCatch);
}