mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(web): load space profile from profile API (#1079)
This commit is contained in:
parent
a068a794dd
commit
9ab2e7e64f
1 changed files with 31 additions and 11 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { useQuery } from "@tanstack/react-query"
|
||||
import { $fetch } from "@lib/api"
|
||||
import { useAuth } from "@lib/auth-context"
|
||||
|
||||
export type SpaceProfile = {
|
||||
|
|
@ -7,6 +6,16 @@ export type SpaceProfile = {
|
|||
dynamic: string[]
|
||||
}
|
||||
|
||||
const API_BASE =
|
||||
process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"
|
||||
|
||||
type SpaceProfileResponse = {
|
||||
profile?: {
|
||||
static?: string[] | null
|
||||
dynamic?: string[] | null
|
||||
} | null
|
||||
}
|
||||
|
||||
export function useSpaceProfile(containerTag: string) {
|
||||
const { org } = useAuth()
|
||||
const orgId = org?.id ?? ""
|
||||
|
|
@ -14,21 +23,32 @@ export function useSpaceProfile(containerTag: string) {
|
|||
return useQuery({
|
||||
queryKey: ["space-profile", orgId, containerTag],
|
||||
queryFn: async (): Promise<SpaceProfile> => {
|
||||
const response = await $fetch(
|
||||
"@get/container-tags/:containerTag/profile",
|
||||
{
|
||||
params: { containerTag },
|
||||
const response = await fetch(`${API_BASE}/v4/profile`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-App-Source": "nova",
|
||||
},
|
||||
)
|
||||
if (response.error) {
|
||||
body: JSON.stringify({ containerTag }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => ({}))) as {
|
||||
error?: string
|
||||
message?: string
|
||||
}
|
||||
throw new Error(
|
||||
response.error.message || "Failed to load space profile",
|
||||
body.message ?? body.error ?? "Failed to load space profile",
|
||||
)
|
||||
}
|
||||
const profile = response.data.profile
|
||||
|
||||
const data = (await response.json()) as SpaceProfileResponse
|
||||
const profile = data.profile
|
||||
|
||||
return {
|
||||
static: profile.static ?? [],
|
||||
dynamic: profile.dynamic ?? [],
|
||||
static: profile?.static ?? [],
|
||||
dynamic: profile?.dynamic ?? [],
|
||||
}
|
||||
},
|
||||
enabled: !!orgId && !!containerTag,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue