refactor(data): consolidate data layer under services namespace
- Move src/data/{api,dto,schemas} directories to src/data/services/*
- Update all relative imports across the codebase to reference new paths
- Use CSS color tokens for splash button gradient in splash-button.module.css
- Add responsive sizes attribute to splash background image
- Add JSDoc documentation to splash-background component referencing original Dart implementation
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Chat API
|
||||
*
|
||||
* 聊天相关接口
|
||||
* 原始 Dart: lib/data/services/api/chat_api_client.dart
|
||||
*/
|
||||
import { httpClient } from "./http_client";
|
||||
import { ApiPath } from "./api_path";
|
||||
import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
import { ChatHistoryResponse } from "@/data/dto/chat/chat_history_response";
|
||||
import { ChatSendResponse } from "@/data/dto/chat/chat_send_response";
|
||||
import { ChatSyncData } from "@/data/dto/chat/chat_sync_data";
|
||||
import { ChatSyncRequest } from "@/data/dto/chat/chat_sync_request";
|
||||
import { ImageUploadResponse } from "@/data/dto/chat/image_upload_response";
|
||||
import { SendMessageRequest } from "@/data/dto/chat/send_message_request";
|
||||
import { SttData } from "@/data/dto/chat/stt_data";
|
||||
import { SyncMessage } from "@/data/dto/chat/sync_message";
|
||||
|
||||
export class ChatApi {
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
async sendMessage(body: SendMessageRequest): Promise<ChatSendResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatSend, {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return ChatSendResponse.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天历史
|
||||
*/
|
||||
async getHistory(limit = 50, offset = 0): Promise<ChatHistoryResponse> {
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatHistory, {
|
||||
query: { limit, offset },
|
||||
});
|
||||
return ChatHistoryResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 语音转文字(multipart 上传)
|
||||
*/
|
||||
async speechToText(audio: Blob | File): Promise<SttData> {
|
||||
const formData = new FormData();
|
||||
formData.append("audio", audio);
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatStt, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
return SttData.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步游客消息
|
||||
*/
|
||||
async syncMessages(messages: SyncMessage[]): Promise<ChatSyncData> {
|
||||
const body = ChatSyncRequest.from({ messages });
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.chatSync, {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return ChatSyncData.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
async uploadImage(image: Blob | File): Promise<ImageUploadResponse> {
|
||||
const formData = new FormData();
|
||||
formData.append("image", image);
|
||||
const env = await httpClient<ApiEnvelope<unknown>>(
|
||||
ApiPath.chatUploadImage,
|
||||
{ method: "POST", body: formData }
|
||||
);
|
||||
return ImageUploadResponse.fromJson(
|
||||
unwrap(env) as Record<string, unknown>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局单例
|
||||
*/
|
||||
export const chatApi = new ChatApi();
|
||||
Reference in New Issue
Block a user