Last active
November 29, 2022 19:13
-
-
Save niklaskorz/cfbd196e48cdfeb27fdd2a19aef40d6b to your computer and use it in GitHub Desktop.
Getting your local instance's URL for an external status on Mastodon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const instance = "https://rheinneckar.social"; | |
async function getLocalPost(url) { | |
const encodedUrl = encodeURIComponent(url); | |
const resp = await fetch(`${instance}/api/v2/search?q=${encodedUrl}&resolve=true&limit=1`, { credentials: "include" }); | |
const data = await resp.json(); | |
const status = data.statuses[0]; | |
const id = status.id; | |
const acct = status.account.acct; | |
return `${instance}/${acct}/${id}`; | |
} | |
console.log(await getLocalPost("https://fosstodon.org/@rauschma/109428469327665227")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment