Public
Back
Version 2
2/29/2024
import { getPostThread, resolveHandle } from "https://esm.town/v/vladimyr/libbluesky";
import ky from "npm:ky";
export async function fetchPost(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: Iterable<Array<string>> = Object.groupBy(pathSegments, (_, index) => Math.floor(index / 2));
const { profile, post } = Object.fromEntries(Object.values(pairs));
const { did } = await resolveHandle(profile);
return getPostThread(`at://${did}/post/${post}`);
}
console.log(await fetchPost("https://bsky.app/profile/vladimyr.bsky.social/post/3kmhgnwtct72o"));
Updated: March 2, 2024