Support Pleroma's /notice unfurl
This commit is contained in:
parent
7da1745cca
commit
7be1e589ab
|
@ -9,6 +9,20 @@ export const throttle = pThrottle({
|
||||||
interval: 1000,
|
interval: 1000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const STATUS_ID_REGEXES = [
|
||||||
|
/\/@[^@\/]+@?[^\/]+?\/(\d+)$/i, // Mastodon
|
||||||
|
/\/notice\/(\w+)$/i, // Pleroma
|
||||||
|
];
|
||||||
|
function getStatusID(path) {
|
||||||
|
for (let i = 0; i < STATUS_ID_REGEXES.length; i++) {
|
||||||
|
const statusMatchID = path.match(STATUS_ID_REGEXES[i])?.[1];
|
||||||
|
if (statusMatchID) {
|
||||||
|
return statusMatchID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const denylistDomains = /(twitter|github)\.com/i;
|
const denylistDomains = /(twitter|github)\.com/i;
|
||||||
const failedUnfurls = {};
|
const failedUnfurls = {};
|
||||||
function _unfurlMastodonLink(instance, url) {
|
function _unfurlMastodonLink(instance, url) {
|
||||||
|
@ -53,11 +67,11 @@ function _unfurlMastodonLink(instance, url) {
|
||||||
}
|
}
|
||||||
const domain = urlObj.hostname;
|
const domain = urlObj.hostname;
|
||||||
const path = urlObj.pathname;
|
const path = urlObj.pathname;
|
||||||
// Regex /:username/:id, where username = @username or @username@domain, id = number
|
// Regex /:username/:id, where username = @username or @username@domain, id = post ID
|
||||||
const statusRegex = /\/@([^@\/]+)@?([^\/]+)?\/(\d+)$/i;
|
let statusMatchID = getStatusID(path);
|
||||||
const statusMatch = statusRegex.exec(path);
|
|
||||||
if (statusMatch) {
|
if (statusMatchID) {
|
||||||
const id = statusMatch[3];
|
const id = statusMatchID;
|
||||||
const { masto } = api({ instance: domain });
|
const { masto } = api({ instance: domain });
|
||||||
remoteInstanceFetch = masto.v1.statuses
|
remoteInstanceFetch = masto.v1.statuses
|
||||||
.$select(id)
|
.$select(id)
|
||||||
|
|
Loading…
Reference in a new issue