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
This commit is contained in:
Ulf Rompe 2025-08-01 17:33:22 +02:00
parent d9e4c7d198
commit 5e118fdbd0
2 changed files with 21 additions and 14 deletions

View file

@ -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)
}
}

View file

@ -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"
);
}
});
}
})