feat(image): 新建 knowai-core:1.0.0 镜像并完成推送
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
- 搭建 api、auth、utils 等逻辑模块 - 通过 tsc、eslint、vitest 测试验证 BREAKING CHANGE: 新镜像分支
This commit is contained in:
48
api/modules/chat.ts
Normal file
48
api/modules/chat.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import type { ApiClient } from '../types';
|
||||
import type {
|
||||
CreateChatSessionRequest,
|
||||
UpdateChatSessionRequest,
|
||||
SendMessageRequest,
|
||||
GetChatSessionsRequest,
|
||||
GetChatSessionsResponse,
|
||||
GetChatMessagesRequest,
|
||||
GetChatMessagesResponse,
|
||||
MarkMessagesAsReadRequest,
|
||||
MarkMessagesAsReadResponse
|
||||
} from '@/types/chat/api';
|
||||
import type { ChatSession, ChatMessage } from '@/types/chat/base';
|
||||
|
||||
// 聊天API服务工厂函数
|
||||
export const chatApi = (client: ApiClient) => ({
|
||||
// 创建聊天会话
|
||||
createSession: (data: CreateChatSessionRequest): Promise<{ session: ChatSession }> => {
|
||||
return client.post('/chat/sessions', data);
|
||||
},
|
||||
|
||||
// 更新聊天会话
|
||||
updateSession: ({ sessionId, ...data }: UpdateChatSessionRequest): Promise<{ session: ChatSession }> => {
|
||||
return client.put(`/chat/sessions/${sessionId}`, data);
|
||||
},
|
||||
|
||||
// 发送消息
|
||||
sendMessage: (data: SendMessageRequest): Promise<{ message: ChatMessage }> => {
|
||||
return client.post(`/chat/sessions/${data.sessionId}/messages`, data);
|
||||
},
|
||||
|
||||
// 获取聊天会话列表
|
||||
getSessions: (params?: GetChatSessionsRequest): Promise<GetChatSessionsResponse> => {
|
||||
const config: AxiosRequestConfig = params ? { params } : {};
|
||||
return client.get('/chat/sessions', config);
|
||||
},
|
||||
|
||||
// 获取聊天消息
|
||||
getMessages: ({ sessionId, ...params }: GetChatMessagesRequest): Promise<GetChatMessagesResponse> => {
|
||||
return client.get(`/chat/sessions/${sessionId}/messages`, { params });
|
||||
},
|
||||
|
||||
// 标记消息已读
|
||||
markMessagesAsRead: ({ sessionId, messageIds }: MarkMessagesAsReadRequest): Promise<MarkMessagesAsReadResponse> => {
|
||||
return client.post(`/chat/sessions/${sessionId}/read`, { messageIds });
|
||||
}
|
||||
});
|
||||
14
api/modules/index.ts
Normal file
14
api/modules/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { apiClient } from '../client';
|
||||
import { postApi as createPostApi } from './post';
|
||||
import { userApi as createUserApi } from './user';
|
||||
import { chatApi as createChatApi } from './chat';
|
||||
import { modelApi as createModelApi } from './model';
|
||||
|
||||
// 导出工厂函数
|
||||
export { postApi as createPostApi, userApi as createUserApi, chatApi as createChatApi, modelApi as createModelApi };
|
||||
|
||||
// 向后兼容的默认实例
|
||||
export const postApi = createPostApi(apiClient);
|
||||
export const userApi = createUserApi(apiClient);
|
||||
export const chatApi = createChatApi(apiClient);
|
||||
export const modelApi = createModelApi(apiClient);
|
||||
29
api/modules/model.ts
Normal file
29
api/modules/model.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import type { ApiClient } from '../types';
|
||||
import type {
|
||||
GetAIPlazaRequest,
|
||||
GetAIPlazaResponse,
|
||||
GetModelDetailRequest,
|
||||
GetModelDetailResponse,
|
||||
GetModelCommentsRequest,
|
||||
GetModelCommentsResponse
|
||||
} from '@/types/model/api';
|
||||
|
||||
// AI模型API服务工厂函数
|
||||
export const modelApi = (client: ApiClient) => ({
|
||||
// 获取AI模型广场数据
|
||||
getAIPlaza: (params?: GetAIPlazaRequest): Promise<GetAIPlazaResponse> => {
|
||||
const config: AxiosRequestConfig = params ? { params } : {};
|
||||
return client.get('/models/plaza', config);
|
||||
},
|
||||
|
||||
// 获取模型详情
|
||||
getModelDetail: ({ modelId, ...params }: GetModelDetailRequest): Promise<GetModelDetailResponse> => {
|
||||
return client.get(`/models/${modelId}`, { params });
|
||||
},
|
||||
|
||||
// 获取模型评论
|
||||
getModelComments: ({ modelId, ...params }: GetModelCommentsRequest): Promise<GetModelCommentsResponse> => {
|
||||
return client.get(`/models/${modelId}/comments`, { params });
|
||||
}
|
||||
});
|
||||
65
api/modules/post.ts
Normal file
65
api/modules/post.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import type { ApiClient } from '../types';
|
||||
import type {
|
||||
CreatePostRequest,
|
||||
CreatePostResponse,
|
||||
GetPostsRequest,
|
||||
GetPostsResponse,
|
||||
GetPostRequest,
|
||||
GetPostResponse,
|
||||
LikePostRequest,
|
||||
LikePostResponse,
|
||||
BookmarkPostRequest,
|
||||
BookmarkPostResponse,
|
||||
CreateCommentRequest,
|
||||
CreateCommentResponse,
|
||||
GetCommentsRequest,
|
||||
GetCommentsResponse,
|
||||
LikeCommentRequest,
|
||||
LikeCommentResponse
|
||||
} from '@/types/post/api';
|
||||
|
||||
// 帖子API服务工厂函数
|
||||
export const postApi = (client: ApiClient) => ({
|
||||
// 创建帖子
|
||||
createPost: (data: CreatePostRequest): Promise<CreatePostResponse> => {
|
||||
return client.post('/posts', data);
|
||||
},
|
||||
|
||||
// 获取帖子列表
|
||||
getPosts: (params: GetPostsRequest): Promise<GetPostsResponse> => {
|
||||
const config: AxiosRequestConfig = { params };
|
||||
return client.get('/posts', config);
|
||||
},
|
||||
|
||||
// 获取帖子详情
|
||||
getPost: ({ postId }: GetPostRequest): Promise<GetPostResponse> => {
|
||||
return client.get(`/posts/${postId}`);
|
||||
},
|
||||
|
||||
// 点赞帖子
|
||||
likePost: ({ postId }: LikePostRequest): Promise<LikePostResponse> => {
|
||||
return client.put(`/posts/${postId}/like`);
|
||||
},
|
||||
|
||||
// 收藏帖子
|
||||
bookmarkPost: ({ postId }: BookmarkPostRequest): Promise<BookmarkPostResponse> => {
|
||||
return client.put(`/posts/${postId}/bookmark`);
|
||||
},
|
||||
|
||||
// 创建评论
|
||||
createComment: (data: CreateCommentRequest): Promise<CreateCommentResponse> => {
|
||||
return client.post(`/posts/${data.postId}/comments`, data);
|
||||
},
|
||||
|
||||
// 获取评论列表
|
||||
getComments: (params: GetCommentsRequest): Promise<GetCommentsResponse> => {
|
||||
const { postId, ...queryParams } = params;
|
||||
return client.get(`/posts/${postId}/comments`, { params: queryParams });
|
||||
},
|
||||
|
||||
// 点赞评论
|
||||
likeComment: ({ commentId }: LikeCommentRequest): Promise<LikeCommentResponse> => {
|
||||
return client.put(`/comments/${commentId}/like`);
|
||||
}
|
||||
});
|
||||
51
api/modules/user.ts
Normal file
51
api/modules/user.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { ApiClient } from '../types';
|
||||
import type {
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
RegisterRequest,
|
||||
RegisterResponse,
|
||||
RefreshTokenRequest,
|
||||
RefreshTokenResponse,
|
||||
UserProfileUpdateRequest,
|
||||
UserProfileUpdateResponse,
|
||||
UserFollowRequest,
|
||||
UserFollowResponse
|
||||
} from '@/types/user';
|
||||
|
||||
// 用户API服务工厂函数
|
||||
export const userApi = (client: ApiClient) => ({
|
||||
// 用户登录
|
||||
login: (data: LoginRequest): Promise<LoginResponse> => {
|
||||
return client.post('/auth/login', data);
|
||||
},
|
||||
|
||||
// 用户注册
|
||||
register: (data: RegisterRequest): Promise<RegisterResponse> => {
|
||||
return client.post('/auth/register', data);
|
||||
},
|
||||
|
||||
// 刷新令牌
|
||||
refreshToken: (data: RefreshTokenRequest): Promise<RefreshTokenResponse> => {
|
||||
return client.post('/auth/refresh', data);
|
||||
},
|
||||
|
||||
// 获取用户档案
|
||||
getProfile: (): Promise<UserProfileUpdateResponse> => {
|
||||
return client.get('/user/profile');
|
||||
},
|
||||
|
||||
// 更新用户档案
|
||||
updateProfile: (data: UserProfileUpdateRequest): Promise<UserProfileUpdateResponse> => {
|
||||
return client.put('/user/profile', data);
|
||||
},
|
||||
|
||||
// 关注用户
|
||||
followUser: ({ userId }: UserFollowRequest): Promise<UserFollowResponse> => {
|
||||
return client.put(`/user/follow/${userId}`);
|
||||
},
|
||||
|
||||
// 取消关注用户
|
||||
unfollowUser: ({ userId }: UserFollowRequest): Promise<UserFollowResponse> => {
|
||||
return client.delete(`/user/follow/${userId}`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user