Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions app/api/artist/route.tsx

This file was deleted.

19 changes: 12 additions & 7 deletions hooks/useArtistInstruction.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { useQuery } from "@tanstack/react-query";
import { usePrivy } from "@privy-io/react-auth";
import getArtist from "@/lib/getArtist";

export function useArtistInstruction(artistId?: string) {
const { getAccessToken, authenticated } = usePrivy();

return useQuery<string | undefined>({
queryKey: ["artist-instruction", artistId],
enabled: Boolean(artistId),
enabled: Boolean(artistId) && authenticated,
queryFn: async () => {
if (!artistId) return undefined;
const res = await fetch(`/api/artist?artistId=${encodeURIComponent(artistId)}`);
if (!res.ok) return undefined;
const json = await res.json();
return json?.artist?.instruction || undefined;
const accessToken = await getAccessToken();
if (!accessToken) {
throw new Error("Please sign in to view artist details");
}

const artist = await getArtist(artistId, accessToken);
return artist?.instruction || undefined;
},
staleTime: 5 * 60 * 1000,
});
}

export default useArtistInstruction;


20 changes: 12 additions & 8 deletions hooks/useArtistKnowledge.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { useQuery } from "@tanstack/react-query";
import { usePrivy } from "@privy-io/react-auth";
import getArtist from "@/lib/getArtist";
import type { KnowledgeBaseEntry } from "@/lib/supabase/getArtistKnowledge";

export function useArtistKnowledge(artistId?: string) {
const { getAccessToken, authenticated } = usePrivy();

return useQuery<KnowledgeBaseEntry[]>({
queryKey: ["artist-knowledge", artistId],
enabled: Boolean(artistId),
enabled: Boolean(artistId) && authenticated,
queryFn: async () => {
if (!artistId) return [];
const res = await fetch(`/api/artist?artistId=${encodeURIComponent(artistId)}`);
if (!res.ok) return [];
const json = await res.json();
const knowledges: KnowledgeBaseEntry[] =
json?.artist?.account_info?.[0]?.knowledges || json?.artist?.knowledges || [];
const accessToken = await getAccessToken();
if (!accessToken) {
throw new Error("Please sign in to view artist details");
}

const artist = await getArtist(artistId, accessToken);
const knowledges: KnowledgeBaseEntry[] = artist?.knowledges || [];
return Array.isArray(knowledges) ? knowledges : [];
},
staleTime: 5 * 60 * 1000,
});
}

export default useArtistKnowledge;


32 changes: 25 additions & 7 deletions lib/getArtist.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
const getArtist = async (artistId: string) => {
try {
const response = await fetch(`/api/artist?artistId=${artistId}`);
import { getClientApiBaseUrl } from "@/lib/api/getClientApiBaseUrl";
import type { ArtistRecord } from "@/types/Artist";

const data = await response.json();
const getArtist = async (
artistId: string,
accessToken: string,
) : Promise<ArtistRecord | null> => {
const response = await fetch(
`${getClientApiBaseUrl()}/api/artists/${encodeURIComponent(artistId)}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);

return data?.artist;
} catch (error) {
return { error };
if (!response.ok) {
const responseText = await response.text();
throw new Error(
responseText
? `Failed to fetch artist: ${response.status} ${responseText}`
: `Failed to fetch artist: ${response.status}`,
);
}

const data = await response.json();

return data?.artist ?? null;
};

export default getArtist;
Loading