Public
Back
Version 7
3/2/2024
import { getPostThread, resolveHandle } from "https://esm.town/v/vladimyr/libbluesky";
import { toPairs } from "https://esm.town/v/vladimyr/toPairs";
import ky from "npm:ky";
export async function fetchPost(url: string | URL) {
const postURL = new URL(url);
if (postURL.hostname !== "bsky.app") {
throw new TypeError("Invalid post URL");
}
const pathSegments = postURL.pathname.split("/").filter(Boolean);
const pairs = toPairs(pathSegments);
const { profile, post } = Object.fromEntries(pairs as Iterable<[PropertyKey, string]>);
const { did } = await resolveHandle(profile);
const { thread } = await getPostThread(`at://${did}/app.bsky.feed.post/${post}`);
return thread.post;
}
Updated: March 2, 2024