From 6b62f1f2e07989ce709a797cb62c1f2802cc6406 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Fri, 12 Dec 2025 18:18:52 +0400 Subject: [PATCH] use bluesky api for profile data --- .../p/[didOrHandle]/ProfileHeader.tsx | 11 +++---- app/(home-pages)/p/[didOrHandle]/layout.tsx | 18 +++++++---- app/api/rpc/[command]/get_profile_data.ts | 32 +++++++------------ components/ProfilePopover.tsx | 2 +- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/(home-pages)/p/[didOrHandle]/ProfileHeader.tsx b/app/(home-pages)/p/[didOrHandle]/ProfileHeader.tsx index ce5c5cd6..392a060f 100644 --- a/app/(home-pages)/p/[didOrHandle]/ProfileHeader.tsx +++ b/app/(home-pages)/p/[didOrHandle]/ProfileHeader.tsx @@ -8,20 +8,19 @@ import { colorToString } from "components/ThemeManager/useColorAttribute"; import { PubIcon } from "components/ActionBar/Publications"; import { Json } from "supabase/database.types"; import { BlueskyTiny } from "components/Icons/BlueskyTiny"; +import { ProfileViewDetailed } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; export const ProfileHeader = (props: { - profile: ProfileData; + profile: ProfileViewDetailed; publications: { record: Json; uri: string }[]; }) => { - let profileRecord = props.profile.record as AppBskyActorProfile.Record; + console.log(props.profile); + let profileRecord = props.profile; return (
; @@ -33,16 +34,21 @@ export default async function ProfilePageLayout(props: { did = resolved; } - let { data: profile } = await supabaseServerClient - .from("bsky_profiles") - .select(`*`) - .eq("did", did) - .single(); - let { data: publications } = await supabaseServerClient + let agent = new Agent({ + service: "https://public.api.bsky.app", + }); + let profileReq = agent.app.bsky.actor.getProfile({ actor: did }); + + let publicationsReq = supabaseServerClient .from("publications") .select("*") .eq("identity_did", did); + let [{ data: profile }, { data: publications }] = await Promise.all([ + profileReq, + publicationsReq, + ]); + if (!profile) return null; return ( diff --git a/app/api/rpc/[command]/get_profile_data.ts b/app/api/rpc/[command]/get_profile_data.ts index 1e3dceb6..8a74bdde 100644 --- a/app/api/rpc/[command]/get_profile_data.ts +++ b/app/api/rpc/[command]/get_profile_data.ts @@ -2,6 +2,8 @@ import { z } from "zod"; import { makeRoute } from "../lib"; import type { Env } from "./route"; import { idResolver } from "app/(home-pages)/reader/idResolver"; +import { supabaseServerClient } from "supabase/serverClient"; +import { Agent } from "@atproto/api"; export type GetProfileDataReturnType = Awaited< ReturnType<(typeof get_profile_data)["handler"]> @@ -24,32 +26,20 @@ export const get_profile_data = makeRoute({ did = resolved; } - // Fetch profile - const { data: profile, error: profileError } = await supabase - .from("bsky_profiles") - .select("*") - .eq("did", did) - .single(); - - if (profileError) { - throw new Error(`Failed to fetch profile: ${profileError.message}`); - } + let agent = new Agent({ + service: "https://public.api.bsky.app", + }); + let profileReq = agent.app.bsky.actor.getProfile({ actor: did }); - if (!profile) { - throw new Error("Profile not found"); - } - - // Fetch publications for the DID - const { data: publications, error: publicationsError } = await supabase + let publicationsReq = supabaseServerClient .from("publications") .select("*") .eq("identity_did", did); - if (publicationsError) { - throw new Error( - `Failed to fetch publications: ${publicationsError.message}`, - ); - } + let [{ data: profile }, { data: publications }] = await Promise.all([ + profileReq, + publicationsReq, + ]); return { result: { diff --git a/components/ProfilePopover.tsx b/components/ProfilePopover.tsx index 1a890cc5..7c664524 100644 --- a/components/ProfilePopover.tsx +++ b/components/ProfilePopover.tsx @@ -1,9 +1,9 @@ "use client"; -import { ProfileHeader } from "app/p/[didOrHandle]/(profile)/ProfileHeader"; import { Popover } from "./Popover"; import useSWR from "swr"; import { callRPC } from "app/api/rpc/client"; import { useState } from "react"; +import { ProfileHeader } from "app/(home-pages)/p/[didOrHandle]/ProfileHeader"; export const ProfilePopover = (props: { trigger: React.ReactNode; -- 2.51.2