import type { CreatorConnections, CreatorProfile, CreatorRelationshipResponse, } from '../../packages/shared/src/contracts/creator'; import { requestJson as requestApiJson } from './apiClient'; export type CreatorConnectionKind = 'following' | 'followers'; export type CreatorAction = 'follow' | 'unfollow' | 'remove-follower'; export const creatorPath = (id: string) => `/creators?id=${encodeURIComponent(id)}`; export const connectionsPath = (id: string, tab: CreatorConnectionKind) => `/creators/connections?id=${encodeURIComponent(id)}&tab=${tab}`; const userPath = (id: string) => `/api/creators/${encodeURIComponent(id)}`; export function getCreator(id: string) { return requestApiJson( userPath(id), { method: 'GET' }, '读取创作者资料失败', { skipAuth: true, skipRefresh: true }, ); } export function getCreatorRelationship(id: string) { return requestApiJson( `${userPath(id)}/relationship`, { method: 'GET' }, '读取关注状态失败', ); } export function getCreatorConnections( id: string, kind: CreatorConnectionKind, cursor: string | null, authenticated: boolean, ) { const query = new URLSearchParams({ limit: '20' }); if (cursor) query.set('cursor', cursor); return requestApiJson( `${userPath(id)}/${kind}?${query}`, { method: 'GET' }, '读取用户列表失败', authenticated ? undefined : { skipAuth: true, skipRefresh: true }, ); } export function changeCreatorRelationship(id: string, action: CreatorAction) { const path = action === 'remove-follower' ? `/api/creators/me/followers/${encodeURIComponent(id)}` : `${userPath(id)}/follow`; return requestApiJson( path, { method: action === 'follow' ? 'PUT' : 'DELETE' }, '关注操作失败', { // 写入不自动重放,包括鉴权刷新后的重放;失败由业务层回读确认。 skipRefresh: true, retry: { maxRetries: 0 }, }, ); }