From 5e118fdbd0209903da0e2da210ba60dadd9d3a64 Mon Sep 17 00:00:00 2001 From: Ulf Rompe Date: Fri, 1 Aug 2025 17:33:22 +0200 Subject: [PATCH 1/3] Improve Mastodon profile link detection - Use a regular expression instead of substrings - Detect profile URL schema for Mastodon, Akkoma, Friendica and others - Add more uids to `test.ts` to provide some examples Fixes #10 --- src/Mastodon.ts | 16 ++++++---------- src/test.ts | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Mastodon.ts b/src/Mastodon.ts index 755725e..39b57e4 100644 --- a/src/Mastodon.ts +++ b/src/Mastodon.ts @@ -186,16 +186,12 @@ ${text.split("\n").map(txt => " > " + txt).join("\n")}`) return overview.length + rest.join("\n").length + 1 } - private static notMastodon = ["wiki.openstreetmap.org", "hdyc.neis-one.org", "matrix.to","facebook.com","github", "tasks.hotosm.org","community.openstreetmap.org","mapillary.com","wikimedia.org","wikipedia.org","wikidata.org"] - private static isMastodon = ["en.osm.town", ".social", "mstdn", "mastodon", "mapstodon","masto"] + // Fediverse profiles look like this: + // Mastodon, Akkoma, etc.: https://foo.bar/@user + // Friendica: https://foo.bar/profile/user + private static isProbablyMastodon = new RegExp("^https?://[^/]+/(profile/|@)[^/]+/?$") static isProbablyMastodonLink(link: string) { - if (this.isMastodon.some(white => link.indexOf(white) >= 0)) { - return true - } - if (this.notMastodon.some(black => link.indexOf(black) >= 0)) { - return false - } - return true; // probably? + return this.isProbablyMastodon.test(link) } -} \ No newline at end of file +} diff --git a/src/test.ts b/src/test.ts index 7996b27..9b1731b 100644 --- a/src/test.ts +++ b/src/test.ts @@ -3,10 +3,21 @@ import MastodonPoster from "./Mastodon"; console.log("Hello world") +const uids = [ + 1214300, // tornooc + 4685130, // contrapunctus + 8404193, // queerthoughts + 153277, // rompe +] -new OsmUserInfo(1214300).getMeLinks().then(links => { - console.log("Got links:", links); +for (const uid of uids) { + new OsmUserInfo(uid).getMeLinks().then((links) => { + console.log("Got links for uid", uid, ":", links); for (const link of links) { - console.log(link, MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon") + console.log( + link, + MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon" + ); } -}) \ No newline at end of file + }); +} From 0ed685baa0fbb568ab6a93b46611d36e78f52a2b Mon Sep 17 00:00:00 2001 From: Ulf Rompe Date: Fri, 1 Aug 2025 17:52:13 +0200 Subject: [PATCH 2/3] Add hector to test.ts as he has good test links --- src/test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test.ts b/src/test.ts index 9b1731b..0a6d1d6 100644 --- a/src/test.ts +++ b/src/test.ts @@ -8,6 +8,7 @@ const uids = [ 4685130, // contrapunctus 8404193, // queerthoughts 153277, // rompe + 393359, // hector ] for (const uid of uids) { From 057a2d2f841a9f923ee5458793f661506a9bf604 Mon Sep 17 00:00:00 2001 From: Ulf Rompe Date: Wed, 6 Aug 2025 17:59:35 +0200 Subject: [PATCH 3/3] Detect Pleroma and Pixelfed profile links - Re-introduce the server blacklist unchanged - Incorporate it into the Fediverse profile regex These two platforms sadly have a non-unique URL scheme, so it may be better to keep the blacklist in place to filter out all the github and codeberg URLs. --- src/Mastodon.ts | 4 +++- src/test.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mastodon.ts b/src/Mastodon.ts index 39b57e4..0f907d6 100644 --- a/src/Mastodon.ts +++ b/src/Mastodon.ts @@ -186,10 +186,12 @@ ${text.split("\n").map(txt => " > " + txt).join("\n")}`) return overview.length + rest.join("\n").length + 1 } + private static notMastodon = ["wiki.openstreetmap.org", "hdyc.neis-one.org", "matrix.to","facebook.com","github", "tasks.hotosm.org","community.openstreetmap.org","mapillary.com","wikimedia.org","wikipedia.org","wikidata.org"] // Fediverse profiles look like this: // Mastodon, Akkoma, etc.: https://foo.bar/@user // Friendica: https://foo.bar/profile/user - private static isProbablyMastodon = new RegExp("^https?://[^/]+/(profile/|@)[^/]+/?$") + // Pixelfed, Pleroma: https://foo.bar/user + private static isProbablyMastodon = new RegExp(`^https?://(?!.*(?:${MastodonPoster.notMastodon.join('|')}))[a-zA-Z0-9.-]+/(profile/|@?)[a-zA-Z0-9_.-]+/?$`) static isProbablyMastodonLink(link: string) { return this.isProbablyMastodon.test(link) diff --git a/src/test.ts b/src/test.ts index 0a6d1d6..8e83057 100644 --- a/src/test.ts +++ b/src/test.ts @@ -9,6 +9,7 @@ const uids = [ 8404193, // queerthoughts 153277, // rompe 393359, // hector + 14124839, // ilja has a Pleroma link ] for (const uid of uids) {