diff --git a/lib/api/chat.ts b/lib/api/chat.ts index 9228d39..1eb3f69 100644 --- a/lib/api/chat.ts +++ b/lib/api/chat.ts @@ -1,18 +1,7 @@ -import { allow, deny } from "@/lib/decision" -import { isApiError, toApiError, type ApiDecision } from "@/lib/errors" +import { deny } from "@/lib/decision" +import type { ApiDecision } from "@/lib/errors" import type { ChatMessage, ChatSession } from "@/lib/types" -import { httpJson } from "./http" - -type Paginated = { - items: T[] - meta: { - total: number - offset: number - limit: number - } -} - export type ListChatSessionsOptions = { offset?: number limit?: number @@ -23,92 +12,30 @@ export type ListChatMessagesOptions = { limit?: number } -function withOffsetLimit(path: string, options?: { offset?: number; limit?: number }): string { - const offset = options?.offset ?? 0 - const limit = options?.limit ?? 100 +const unavailable = "聊天接口暂未开放" - const searchParams = new URLSearchParams({ - offset: String(offset), - limit: String(limit), - }) - - return `${path}?${searchParams.toString()}` +export async function listChatSessions(_options?: ListChatSessionsOptions): Promise { + return [] } -function unwrapItems(value: Paginated | T[]): T[] { - return Array.isArray(value) ? value : value.items -} - -function denyFromError(error: unknown): ApiDecision { - if (error instanceof Error && error.message === "UNAUTHORIZED") { - return deny(401, "请先登录") - } - - const apiError = toApiError(error) - return deny(apiError.code, apiError.msg) -} - -export async function listChatSessions(options?: ListChatSessionsOptions): Promise { - const res = await httpJson | ChatSession[]>( - withOffsetLimit("/api/v1/chat/sessions", options), - { - cache: "no-store", - }, - ) - return unwrapItems(res) -} - -export async function getChatSessionById(sessionId: string): Promise { - try { - return await httpJson(`/api/v1/chat/sessions/${encodeURIComponent(sessionId)}`, { - cache: "no-store", - }) - } catch (error) { - if (error instanceof Error && error.message === "UNAUTHORIZED") { - throw error - } - if (isApiError(error) && error.code === 404) { - return undefined - } - throw error - } +export async function getChatSessionById(_sessionId: string): Promise { + return undefined } export async function listChatMessages( - sessionId: string, - options?: ListChatMessagesOptions, + _sessionId: string, + _options?: ListChatMessagesOptions, ): Promise { - const res = await httpJson | ChatMessage[]>( - withOffsetLimit(`/api/v1/chat/sessions/${encodeURIComponent(sessionId)}/messages`, options), - { - cache: "no-store", - }, - ) - return unwrapItems(res) + return [] } -export async function sendTextMessage(sessionId: string, content: string): Promise { - try { - await httpJson(`/api/v1/chat/sessions/${encodeURIComponent(sessionId)}/messages`, { - method: "POST", - cache: "no-store", - json: { type: "text", content }, - }) - return allow() - } catch (error) { - return denyFromError(error) - } +export async function sendTextMessage(_sessionId: string, _content: string): Promise { + return deny(404, unavailable) } -export async function sendImageMessage(sessionId: string, imageUrl: string): Promise { - try { - await httpJson(`/api/v1/chat/sessions/${encodeURIComponent(sessionId)}/messages`, { - method: "POST", - cache: "no-store", - json: { type: "image", content: imageUrl }, - }) - return allow() - } catch (error) { - return denyFromError(error) - } +export async function sendImageMessage( + _sessionId: string, + _imageUrl: string, +): Promise { + return deny(404, unavailable) } diff --git a/lib/api/players.ts b/lib/api/players.ts index 15b5f80..425a1c9 100644 --- a/lib/api/players.ts +++ b/lib/api/players.ts @@ -36,9 +36,6 @@ export async function getPlayerById(playerId: string): Promise { - const res = await httpJson>( - `/api/v1/shops/${encodeURIComponent(shopId)}/players?offset=0&limit=100`, - { cache: "no-store" }, - ) - return res.items + const players = await listPlayers() + return players.filter((player) => player.shopId === shopId) }