···
import { BskyAgent } from "@atproto/api";
···
48
+
const resolveHandle = async (handle: string) => {
49
+
const agent = new BskyAgent({
50
+
service: "https://public.api.bsky.app",
53
+
const res = await agent.com.atproto.identity.resolveHandle({
57
+
return res.data.did;
60
+
const fetchServiceEndpoint = async (handle: string) => {
61
+
const did = await resolveHandle(handle);
63
+
const res = await fetch(
64
+
did.startsWith("did:web")
65
+
? "https://" + did.split(":")[2] + "/.well-known/did.json"
66
+
: "https://plc.directory/" + did,
69
+
return res.json().then((doc) => {
70
+
for (const service of doc.service) {
71
+
if (service.id.includes("#atproto_pds")) {
72
+
return service.serviceEndpoint;
const unfollowBsky = async (form: Form, preview: boolean) => {
81
+
const serviceURL = await fetchServiceEndpoint(form.handle);
const agent = new BskyAgent({
53
-
service: form.serviceURL,
84
+
service: serviceURL,
···
const UnfollowForm: Component = () => {
const [formStore, setFormStore] = createStore<Form>({
117
-
serviceURL: "https://bsky.social",
···
130
-
placeholder="https://bsky.social (optional)"
132
-
if (e.currentTarget.value)
133
-
setFormStore("serviceURL", e.currentTarget.value);
134
-
else setFormStore("serviceURL", "https://bsky.social");