mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-13 09:28:50 +01:00
Add more unfurling
- Fix regex - Handle trunks.social and Phanpy links too
This commit is contained in:
parent
7c8d310ed9
commit
83bdc82049
2 changed files with 21 additions and 5 deletions
|
@ -2158,10 +2158,24 @@ function _unfurlMastodonLink(instance, url) {
|
|||
|
||||
let remoteInstanceFetch;
|
||||
let theURL = url;
|
||||
if (/\/\/elk\.[^\/]+\/[^.]+\.[^.]+/i.test(theURL)) {
|
||||
// E.g. https://elk.zone/domain.com/@stest/123 -> https://domain.com/@stest/123
|
||||
|
||||
// https://elk.zone/domain.com/@stest/123 -> https://domain.com/@stest/123
|
||||
if (/\/\/elk\.[^\/]+\/[^\/]+\.[^\/]+/i.test(theURL)) {
|
||||
theURL = theURL.replace(/elk\.[^\/]+\//i, '');
|
||||
}
|
||||
|
||||
// https://trunks.social/status/domain.com/@stest/123 -> https://domain.com/@stest/123
|
||||
if (/\/\/trunks\.[^\/]+\/status\/[^\/]+\.[^\/]+/i.test(theURL)) {
|
||||
theURL = theURL.replace(/trunks\.[^\/]+\/status\//i, '');
|
||||
}
|
||||
|
||||
// https://phanpy.social/#/domain.com/s/123 -> https://domain.com/statuses/123
|
||||
if (/\/#\/[^\/]+\.[^\/]+\/s\/.+/i.test(theURL)) {
|
||||
const urlAfterHash = theURL.split('/#/')[1];
|
||||
const finalURL = urlAfterHash.replace(/\/s\//i, '/@fakeUsername/');
|
||||
theURL = `https://${finalURL}`;
|
||||
}
|
||||
|
||||
const urlObj = new URL(theURL);
|
||||
const domain = urlObj.hostname;
|
||||
const path = urlObj.pathname;
|
||||
|
@ -2189,7 +2203,7 @@ function _unfurlMastodonLink(instance, url) {
|
|||
const { masto } = api({ instance });
|
||||
const mastoSearchFetch = masto.v2.search
|
||||
.fetch({
|
||||
q: url,
|
||||
q: theURL,
|
||||
type: 'statuses',
|
||||
resolve: true,
|
||||
limit: 1,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
export default function isMastodonLinkMaybe(url) {
|
||||
const { pathname } = new URL(url);
|
||||
const { pathname, hash } = new URL(url);
|
||||
return (
|
||||
/^\/.*\/\d+$/i.test(pathname) ||
|
||||
/^\/@[^/]+\/(statuses|posts)\/\w+\/?$/i.test(pathname) || // GoToSocial, Takahe
|
||||
/^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Calckey
|
||||
/^\/(notice|objects)\/[a-z0-9-]+$/i.test(pathname) // Pleroma
|
||||
/^\/notes\/[a-z0-9]+$/i.test(pathname) || // Misskey, Calckey
|
||||
/^\/(notice|objects)\/[a-z0-9-]+$/i.test(pathname) || // Pleroma
|
||||
/#\/[^\/]+\.[^\/]+\/s\/.+/i.test(hash) // Phanpy 🫣
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue