feat(reset): 以构造器模式重构
- 加了大文件传输自定义分片协议 BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { PaginationRequest, PaginationResponse } from '../common';
|
||||
import type { ChatSession, ChatMessage } from './base';
|
||||
import type { ChatMessageType } from './enum';
|
||||
import type { ChatMessageType } from './types';
|
||||
|
||||
// 创建聊天会话请求接口
|
||||
export interface CreateChatSessionRequest {
|
||||
@@ -7,92 +8,55 @@ export interface CreateChatSessionRequest {
|
||||
participantId: string;
|
||||
}
|
||||
|
||||
// 更新聊天会话请求接口(占位)
|
||||
export interface UpdateChatSessionRequest {
|
||||
// 只能用于处理后台逻辑
|
||||
sessionId: string;
|
||||
// 创建聊天会话响应接口
|
||||
export interface CreateChatSessionResponse {
|
||||
success: boolean;
|
||||
chatSessionId: string; // 成功时返回会话ID,应该是点击私信就跳转到私信
|
||||
}
|
||||
|
||||
|
||||
// 发送消息请求接口
|
||||
export interface SendMessageRequest {
|
||||
sessionId: string;
|
||||
chatSessionId: string; // cookie存不了这个,所以得在请求体里
|
||||
content: string;
|
||||
type: ChatMessageType;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface SendMessageResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 获取聊天会话列表请求接口
|
||||
export interface GetChatSessionsRequest {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export interface GetChatSessionsRequest extends PaginationRequest {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 获取聊天会话列表响应接口
|
||||
export interface GetChatSessionsResponse {
|
||||
sessions: ChatSession[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
export interface GetChatSessionsResponse extends PaginationResponse<ChatSession> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
|
||||
// 获取聊天消息请求接口
|
||||
export interface GetChatMessagesRequest {
|
||||
sessionId: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
export interface GetChatMessagesRequest extends PaginationRequest {
|
||||
chatSessionId: string;
|
||||
before?: string; // 消息ID,获取该消息之前的消息
|
||||
after?: string; // 消息ID,获取该消息之后的消息
|
||||
}
|
||||
|
||||
// 获取聊天消息响应接口
|
||||
export interface GetChatMessagesResponse {
|
||||
messages: ChatMessage[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
hasMore: boolean;
|
||||
export interface GetChatMessagesResponse extends PaginationResponse<ChatMessage> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 标记消息已读请求接口
|
||||
export interface MarkMessagesAsReadRequest {
|
||||
sessionId: string;
|
||||
messageIds: string[];
|
||||
}
|
||||
|
||||
// 标记消息已读响应接口(已读状态只面向接收方)
|
||||
export interface MarkMessagesAsReadResponse {
|
||||
success: boolean;
|
||||
markedMessageIds: string[]; // 成功标记的消息ID
|
||||
failedMessageIds?: string[]; // 失败的消息ID
|
||||
}
|
||||
|
||||
// 搜索聊天消息请求接口
|
||||
export interface SearchChatMessagesRequest {
|
||||
sessionId?: string;
|
||||
// 搜索聊天消息/会话请求接口
|
||||
export interface SearchChatMessagesRequest extends PaginationRequest {
|
||||
query: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// 搜索聊天消息响应接口
|
||||
export interface SearchChatMessagesResponse {
|
||||
messages: ChatMessage[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
export interface SearchChatMessagesResponse extends PaginationResponse<ChatSession> {
|
||||
// 足矣
|
||||
}
|
||||
|
||||
// 搜索聊天会话请求接口
|
||||
export interface SearchChatSessionsRequest {
|
||||
query: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// 搜索聊天会话响应接口
|
||||
export interface SearchChatSessionsResponse {
|
||||
sessions: ChatSession[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,25 @@
|
||||
import type { User } from '../index';
|
||||
import type { ChatMessageType, ChatMessageStatus } from './enum';
|
||||
import type { UserProfile } from '../user';
|
||||
import type { ChatMessageType } from './types';
|
||||
import type { BaseEntity } from '../common';
|
||||
|
||||
// 聊天消息接口
|
||||
export interface ChatMessage {
|
||||
id: string;
|
||||
export interface ChatMessage extends BaseEntity {
|
||||
// 聊天会话id,下面那个接口的id
|
||||
sessionId: string;
|
||||
sender: User;
|
||||
receiver: User;
|
||||
content: string;
|
||||
type: ChatMessageType;
|
||||
status: ChatMessageStatus;
|
||||
chatSessionId: string;
|
||||
sender: UserProfile;
|
||||
receiver: UserProfile;
|
||||
content: string; // 只支持文本信息
|
||||
type: ChatMessageType; // 实际无用
|
||||
createdAt: Date;
|
||||
// 非文本消息类型的元数据
|
||||
metadata?: {
|
||||
fileName?: string;
|
||||
fileSize?: number;
|
||||
duration?: number;
|
||||
// 小图预览
|
||||
thumbnail?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
// 无元数据,因为只有文本消息
|
||||
}
|
||||
|
||||
// 聊天会话接口
|
||||
export interface ChatSession {
|
||||
export interface ChatSession extends BaseEntity {
|
||||
id: string;
|
||||
participant1Id: string;
|
||||
participant2Id: string;
|
||||
participant1: User;
|
||||
participant2: User;
|
||||
lastMessage?: {
|
||||
id: string;
|
||||
content: string;
|
||||
senderId: string;
|
||||
createdAt: Date;
|
||||
};
|
||||
unreadCount1: number; // 参与者1的未读消息数
|
||||
unreadCount2: number; // 参与者2的未读消息数
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
// 会话元数据(特殊标记、背景设置、自定义属性等等)
|
||||
metadata?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
participant1: UserProfile;
|
||||
participant2: UserProfile;
|
||||
// 用于在聊天列表显示最后一句话
|
||||
lastMessage?: ChatMessage;
|
||||
// 没有已读和未读
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// 聊天消息类型枚举(暂时用不到的)
|
||||
export enum ChatMessageType {
|
||||
TEXT = 'text',
|
||||
IMAGE = 'image',
|
||||
FILE = 'file',
|
||||
VOICE = 'voice',
|
||||
VIDEO = 'video',
|
||||
SYSTEM = 'system'
|
||||
}
|
||||
|
||||
// 聊天消息状态枚举(暂时用不到的)
|
||||
export enum ChatMessageStatus {
|
||||
SENDING = 'sending',
|
||||
SENT = 'sent',
|
||||
DELIVERED = 'delivered',
|
||||
READ = 'read',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './enum';
|
||||
export * from './base';
|
||||
export * from './api';
|
||||
export * from './types';
|
||||
|
||||
4
types/chat/types.ts
Normal file
4
types/chat/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// 聊天消息类型枚举(暂时只支持文本)
|
||||
export type ChatMessageType =
|
||||
| 'text';
|
||||
|
||||
26
types/common.ts
Normal file
26
types/common.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export interface PaginationRequest {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export interface PaginationResponse<T> {
|
||||
data: T[]; // 数据列表
|
||||
total: number; // 总数
|
||||
page: number; // 当前页码
|
||||
limit: number; // 每页数量
|
||||
hasMore?: boolean; // 是否有更多数据
|
||||
}
|
||||
|
||||
// 基础实体接口
|
||||
export interface BaseEntity {
|
||||
id: string; // 唯一标识符
|
||||
createdAt: Date; // 创建时间
|
||||
// 没有更新时间(不支持更新)
|
||||
}
|
||||
|
||||
// 基础数据统计接口
|
||||
export interface BaseStats {
|
||||
stars?: number; // 收藏数
|
||||
likes?: number; // 点赞数
|
||||
comments?: number; // 评论数
|
||||
}
|
||||
@@ -3,3 +3,5 @@ export * from './chat';
|
||||
export * from './model';
|
||||
export * from './post';
|
||||
export * from './user';
|
||||
export * from './upload';
|
||||
export * from './common';
|
||||
|
||||
@@ -1,57 +1,26 @@
|
||||
import type { PaginationRequest, PaginationResponse } from 'types/common';
|
||||
import type { ModelComment, AIModel } from './base';
|
||||
import type { CommentSortType } from './enum';
|
||||
|
||||
// AI模型榜单项接口
|
||||
export interface AIModelRankingItem {
|
||||
model: AIModel;
|
||||
rank: number;
|
||||
change?: 'up' | 'down' | 'same'; // 排名变化,未来扩展
|
||||
}
|
||||
|
||||
// 获取AI模型广场数据请求接口
|
||||
export interface GetAIPlazaRequest {
|
||||
// 模型卡片数据是静态配置(手动维护)的,不需要分页参数
|
||||
}
|
||||
|
||||
// 获取AI模型广场数据响应接口
|
||||
export interface GetAIPlazaResponse {
|
||||
models: AIModel[]; // 模型卡片列表,由管理员预定义
|
||||
hotRankings: AIModelRankingItem[]; // 热评模型榜单
|
||||
clickRankings: AIModelRankingItem[]; // 点击排行榜
|
||||
}
|
||||
|
||||
// 获取模型详情请求接口
|
||||
export interface GetModelDetailRequest {
|
||||
modelId: string;
|
||||
page?: number; // 评论页码
|
||||
limit?: number; // 每页评论数量
|
||||
sortBy?: CommentSortType; // 评论排序方式,未来扩展功能
|
||||
export interface GetModelsRequest extends PaginationRequest {
|
||||
// 够了
|
||||
}
|
||||
|
||||
// 获取模型详情响应接口
|
||||
export interface GetModelDetailResponse {
|
||||
model: AIModel;
|
||||
comments: ModelComment[]; // 使用新的ModelComment类型,已经是数组
|
||||
totalComments: number;
|
||||
hasMoreComments: boolean; // 是否还有更多评论,支持无限滚动加载
|
||||
export interface GetModelsResponse extends PaginationResponse<AIModel> {
|
||||
// 够了
|
||||
}
|
||||
|
||||
// 批量获取模型评论请求接口
|
||||
export interface GetModelCommentsRequest {
|
||||
export interface GetModelCommentsRequest extends PaginationRequest {
|
||||
modelId: string;
|
||||
page?: number; // 页码
|
||||
limit?: number; // 每页评论数量
|
||||
sortBy?: CommentSortType; // 评论排序方式
|
||||
parentId?: string; // 父评论ID,用于获取回复
|
||||
parentId?: string; // 父评论ID
|
||||
}
|
||||
|
||||
// 批量获取模型评论响应接口
|
||||
export interface GetModelCommentsResponse {
|
||||
comments: ModelComment[]; // 评论列表
|
||||
total: number; // 总数
|
||||
page: number; // 当前页码
|
||||
limit: number; // 每页数量
|
||||
hasMore: boolean; // 是否有更多数据
|
||||
export interface GetModelCommentsResponse extends PaginationResponse<ModelComment> {
|
||||
// 够了
|
||||
}
|
||||
|
||||
// 发表模型评论请求接口
|
||||
@@ -63,98 +32,19 @@ export interface CreateModelCommentRequest {
|
||||
|
||||
// 发表模型评论响应接口
|
||||
export interface CreateModelCommentResponse {
|
||||
comment: ModelComment; // 使用新的ModelComment类型
|
||||
}
|
||||
|
||||
// 点赞模型评论请求接口
|
||||
export interface LikeModelCommentRequest {
|
||||
commentId: string;
|
||||
}
|
||||
|
||||
// 点赞模型评论响应接口
|
||||
export interface LikeModelCommentResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 记录模型点击请求接口
|
||||
export interface RecordModelClickRequest {
|
||||
// 点赞模型请求接口
|
||||
export interface LikeModelRequest {
|
||||
modelId: string;
|
||||
}
|
||||
|
||||
// 记录模型点击响应接口
|
||||
export interface RecordModelClickResponse {
|
||||
success: boolean;
|
||||
clickCount: number; // 更新后的总点击数
|
||||
}
|
||||
|
||||
// 后面的都暂时不考虑
|
||||
// 删除模型评论请求接口
|
||||
export interface DeleteModelCommentRequest {
|
||||
commentId: string;
|
||||
}
|
||||
|
||||
// 删除模型评论响应接口
|
||||
export interface DeleteModelCommentResponse {
|
||||
// 点赞模型响应接口
|
||||
export interface LikeModelResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 更新模型评论请求接口
|
||||
export interface UpdateModelCommentRequest {
|
||||
commentId: string;
|
||||
content?: string; // 更新内容
|
||||
}
|
||||
|
||||
// 更新模型评论响应接口
|
||||
export interface UpdateModelCommentResponse {
|
||||
success: boolean;
|
||||
comment: ModelComment; // 返回更新后的评论
|
||||
}
|
||||
|
||||
// 批量点赞模型评论请求接口
|
||||
export interface BatchLikeModelCommentsRequest {
|
||||
commentIds: string[]; // 评论ID列表
|
||||
}
|
||||
|
||||
// 批量点赞模型评论响应接口
|
||||
export interface BatchLikeModelCommentsResponse {
|
||||
results: Array<{
|
||||
commentId: string;
|
||||
success: boolean;
|
||||
comment?: ModelComment; // 成功时返回更新后的评论
|
||||
error?: string; // 失败时的错误信息
|
||||
}>;
|
||||
}
|
||||
|
||||
// 批量删除模型评论请求接口
|
||||
export interface BatchDeleteModelCommentsRequest {
|
||||
commentIds: string[]; // 评论ID列表
|
||||
}
|
||||
|
||||
// 批量删除模型评论响应接口
|
||||
export interface BatchDeleteModelCommentsResponse {
|
||||
results: Array<{
|
||||
commentId: string;
|
||||
success: boolean;
|
||||
error?: string; // 失败时的错误信息
|
||||
}>;
|
||||
}
|
||||
|
||||
// 批量更新模型评论请求接口
|
||||
export interface BatchUpdateModelCommentsRequest {
|
||||
updates: Array<{
|
||||
commentId: string;
|
||||
content?: string; // 更新内容
|
||||
rating?: number; // 更新评分
|
||||
}>;
|
||||
}
|
||||
|
||||
// 批量更新模型评论响应接口
|
||||
export interface BatchUpdateModelCommentsResponse {
|
||||
results: Array<{
|
||||
commentId: string;
|
||||
success: boolean;
|
||||
comment?: ModelComment; // 成功时返回更新后的评论
|
||||
error?: string; // 失败时的错误信息
|
||||
}>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
import type { BaseEntity, BaseUser } from '../post/base';
|
||||
|
||||
// AI模型评论统计信息接口
|
||||
export interface ModelCommentStats {
|
||||
stars: number; // 收藏数
|
||||
likes: number; // 点赞数
|
||||
comments: number; // 评论数
|
||||
replies: number; // 回复数
|
||||
}
|
||||
import type { BaseEntity, BaseStats } from '../common';
|
||||
|
||||
// AI模型评论接口
|
||||
export interface ModelComment extends BaseEntity {
|
||||
modelId: string; // 模型ID
|
||||
authorId: string; // 作者ID
|
||||
author: BaseUser; // 作者信息
|
||||
content: string; // 评论内容
|
||||
parentId?: string; // 父评论ID,用于嵌套评论
|
||||
// 其实没必要
|
||||
stats: ModelCommentStats; // 统计信息
|
||||
}
|
||||
|
||||
// AI模型接口
|
||||
export interface AIModel {
|
||||
id: string;
|
||||
export interface AIModel extends BaseEntity, BaseStats {
|
||||
name: string;
|
||||
description: string;
|
||||
avatar?: string; // 模型头像
|
||||
tags?: string[]; // 模型标签
|
||||
website?: string; // 官方网站
|
||||
clickCount?: number; // 点击次数
|
||||
likeCount?: number; // 点赞次数
|
||||
tags: string[]; // 模型标签(这个反正是静态的,必须有)
|
||||
website: string; // 官方网站(必须有)
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// AI模型评论排序枚举
|
||||
// 和post的重复了,而且字段还不一样
|
||||
export enum CommentSortType {
|
||||
LATEST = 'latest', // 最新
|
||||
HOTTEST = 'hottest', // 最热
|
||||
HIGHEST_RATING = 'highest_rating' // 评分最高
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// 导出所有模型相关的类型定义
|
||||
export * from './base';
|
||||
export * from './api';
|
||||
export * from './enum';
|
||||
export * from './types';
|
||||
|
||||
2
types/model/types.ts
Normal file
2
types/model/types.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// 只有排序
|
||||
// 暂时不排序
|
||||
@@ -1,52 +1,26 @@
|
||||
import type { BaseEntityContent, Post, PostComment } from './base';
|
||||
import type {
|
||||
PostType,
|
||||
PostSortBy,
|
||||
CommentSortBy,
|
||||
SortOrder
|
||||
} from './enum';
|
||||
import type { Post, PostComment, PostType, PostContent } from './base';
|
||||
import type { PaginationRequest, PaginationResponse } from '../common';
|
||||
|
||||
// 创建帖子请求接口
|
||||
export interface CreatePostRequest extends BaseEntityContent {
|
||||
type: PostType; // 帖子类型:提问或文章
|
||||
images?: string[]; // 图片
|
||||
publishedAt?: Date; // 发布时间
|
||||
export interface CreatePostRequest {
|
||||
title: string;
|
||||
content: PostContent;
|
||||
type: PostType;
|
||||
}
|
||||
|
||||
// 创建帖子响应接口
|
||||
// 创建帖子响应接口(整体替换资源,直接返回结果就够了)
|
||||
export interface CreatePostResponse {
|
||||
post: Post;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 获取帖子列表请求接口
|
||||
export interface GetPostsRequest {
|
||||
page?: number; // 页码
|
||||
limit?: number; // 每页数量
|
||||
sortBy?: PostSortBy; // 帖子排序方式
|
||||
type?: PostType; // 帖子类型:提问或文章
|
||||
sortOrder?: SortOrder; // 排序方向
|
||||
authorId?: string;
|
||||
search?: string;
|
||||
// 获取帖子列表请求接口(简单,但是为了之后的扩展性保持独立)
|
||||
export interface GetPostsRequest extends PaginationRequest {
|
||||
// 已继承page和limit字段
|
||||
}
|
||||
|
||||
// 获取帖子列表响应接口
|
||||
export interface GetPostsResponse {
|
||||
data: Post[]; // 数据列表
|
||||
total: number; // 总数
|
||||
page: number; // 当前页码
|
||||
limit: number; // 每页数量
|
||||
hasMore: boolean; // 是否有更多数据
|
||||
sortBy?: PostSortBy; // 帖子排序方式
|
||||
}
|
||||
|
||||
// 获取帖子详情请求接口
|
||||
export interface GetPostRequest {
|
||||
postId: string;
|
||||
}
|
||||
|
||||
// 获取帖子详情响应接口
|
||||
export interface GetPostResponse {
|
||||
post: Post;
|
||||
export interface GetPostsResponse extends PaginationResponse<Post> {
|
||||
// 已继承所有分页相关字段
|
||||
}
|
||||
|
||||
// 点赞帖子请求接口
|
||||
@@ -71,6 +45,7 @@ export interface BookmarkPostResponse {
|
||||
|
||||
// 创建评论请求接口
|
||||
export interface CreateCommentRequest {
|
||||
// 作者信息让后端去计算,保持纯粹性
|
||||
postId: string;
|
||||
content: string;
|
||||
parentId?: string;
|
||||
@@ -78,43 +53,25 @@ export interface CreateCommentRequest {
|
||||
|
||||
// 创建评论响应接口
|
||||
export interface CreateCommentResponse {
|
||||
comment: PostComment;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
|
||||
// 获取评论列表请求接口
|
||||
export interface GetCommentsRequest {
|
||||
page?: number; // 页码
|
||||
limit?: number; // 每页数量
|
||||
sortOrder?: SortOrder; // 排序方向
|
||||
export interface GetCommentsRequest extends PaginationRequest {
|
||||
postId: string;
|
||||
parentId?: string;
|
||||
sortBy?: CommentSortBy;
|
||||
}
|
||||
|
||||
// 获取评论列表响应接口
|
||||
export interface GetCommentsResponse {
|
||||
data: PostComment[]; // 数据列表
|
||||
total: number; // 总数
|
||||
page: number; // 当前页码
|
||||
limit: number; // 每页数量
|
||||
hasMore: boolean; // 是否有更多数据
|
||||
export interface GetCommentsResponse extends PaginationResponse<PostComment> {
|
||||
// 已继承所有分页相关字段
|
||||
}
|
||||
|
||||
// 点赞评论请求接口
|
||||
export interface LikeCommentRequest {
|
||||
commentId: string;
|
||||
}
|
||||
|
||||
// 点赞评论响应接口
|
||||
export interface LikeCommentResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// 获取热门帖子请求接口
|
||||
export interface GetHotPostsRequest {
|
||||
limit?: number; // 每页数量
|
||||
days?: number; // 统计天数,默认7天
|
||||
// 获取热门帖子请求接口(简单,独立,扩展性)
|
||||
export interface GetHotPostsRequest extends PaginationRequest {
|
||||
// 已继承limit字段
|
||||
// 用不着统计天数
|
||||
}
|
||||
|
||||
// 获取热门帖子响应接口
|
||||
@@ -123,22 +80,18 @@ export interface GetHotPostsResponse {
|
||||
total: number; // 总数
|
||||
}
|
||||
|
||||
// 获取帖子榜单请求接口
|
||||
export interface GetPostRankingRequest {
|
||||
limit?: number; // 每页数量
|
||||
period?: 'day' | 'week' | 'month'; // 统计周期
|
||||
type?: 'views' | 'likes' | 'comments'; // 排序类型
|
||||
// 获取帖子榜单请求接口(简单,独立,扩展性)
|
||||
export interface GetPostRankingRequest extends PaginationRequest {
|
||||
// 已继承limit字段
|
||||
}
|
||||
|
||||
// 获取帖子榜单响应接口
|
||||
// 获取帖子榜单响应接口(不存在无限滚动的可能)
|
||||
export interface GetPostRankingResponse {
|
||||
data: Post[]; // 数据列表
|
||||
total: number; // 总数
|
||||
period: 'day' | 'week' | 'month'; // 统计周期
|
||||
type: 'views' | 'likes' | 'comments'; // 排序类型
|
||||
}
|
||||
|
||||
// 后面全部暂时不考虑
|
||||
// 后面全部暂时不会实现
|
||||
// 删除帖子请求接口
|
||||
export interface DeletePostRequest {
|
||||
postId: string;
|
||||
|
||||
@@ -1,44 +1,26 @@
|
||||
import type {User} from '../user/base';
|
||||
import type {PostType} from './enum';
|
||||
import type { UserProfile } from '../user';
|
||||
import type { BaseEntity, BaseStats } from '../common';
|
||||
|
||||
// 基础实体接口
|
||||
export interface BaseEntity {
|
||||
id: string; // 唯一标识符
|
||||
createdAt: Date; // 创建时间
|
||||
updatedAt: Date; // 更新时间
|
||||
}
|
||||
export type PostType = 'question' | 'article';
|
||||
|
||||
// 不搞fallback,统一用原子组件作为fallback
|
||||
export type PostContent =
|
||||
| { type: 'text'; value: string }
|
||||
| { type: 'image'; src: string }
|
||||
| { type: 'video'; src: string};
|
||||
|
||||
// 用户基础信息接口
|
||||
export interface BaseUser {
|
||||
// 其实应该用profile的
|
||||
user: User;
|
||||
}
|
||||
|
||||
export interface PostComment extends BaseEntity {
|
||||
// 这里没带postId,如果后台管理需要,就要带
|
||||
// 重复了,而且评论没有数据(点赞、收藏等等)
|
||||
authorId: string; // 作者ID
|
||||
author: BaseUser; // 作者信息
|
||||
content: string; // 评论内容
|
||||
author: UserProfile; // 作者信息
|
||||
content: string; // 评论内容(暂时只支持文字评论)
|
||||
parentId?: string; // 父评论ID,用于嵌套评论
|
||||
}
|
||||
|
||||
// 实体内容和统计信息基础接口
|
||||
export interface BaseEntityContent {
|
||||
title?: string; // 标题
|
||||
excerpt: string; // 摘要
|
||||
tags?: string[]; // 标签数组
|
||||
metadata?: Record<string, unknown>; // 元数据
|
||||
stars: number; // 收藏数
|
||||
likes: number; // 点赞数
|
||||
comments: number; // 评论数
|
||||
}
|
||||
|
||||
// 帖子接口
|
||||
export interface Post extends BaseEntity, BaseEntityContent {
|
||||
export interface Post extends BaseEntity, BaseStats{
|
||||
title: string; // 标题
|
||||
// 没有标签数组
|
||||
content: PostContent[]; // 内容(文字、图片等)
|
||||
type: PostType; // 帖子类型:提问或文章
|
||||
authorId: string; // 作者ID
|
||||
author: BaseUser; // 作者信息
|
||||
images?: string[]; // 图片数组
|
||||
publishedAt?: Date; // 发布时间
|
||||
author: UserProfile; // 作者信息
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// 这里应该用type联合的,现在有冗余和风格不统一的问题
|
||||
// 排序方式枚举
|
||||
export enum SortOrder {
|
||||
ASC = 'asc',
|
||||
DESC = 'desc'
|
||||
}
|
||||
|
||||
// 排序字段枚举
|
||||
export enum PostSortBy {
|
||||
CREATED_AT = 'createdAt',
|
||||
UPDATED_AT = 'updatedAt',
|
||||
PUBLISHED_AT = 'publishedAt',
|
||||
VIEWS = 'views',
|
||||
LIKES = 'likes',
|
||||
COMMENTS = 'comments'
|
||||
}
|
||||
|
||||
// 评论排序字段枚举
|
||||
export enum CommentSortBy {
|
||||
CREATED_AT = 'createdAt',
|
||||
LIKES = 'likes',
|
||||
REPLIES = 'replies'
|
||||
}
|
||||
|
||||
// 帖子类型枚举
|
||||
export enum PostType {
|
||||
QUESTION = 'question',
|
||||
ARTICLE = 'article'
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// 导出帖子系统所有类型定义
|
||||
export * from './base';
|
||||
export * from './enum';
|
||||
export * from './types';
|
||||
export * from './api';
|
||||
|
||||
2
types/post/types.ts
Normal file
2
types/post/types.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// 只有排序用到type
|
||||
// 排序暂时不支持,先全部删了
|
||||
77
types/upload/api.ts
Normal file
77
types/upload/api.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
// 分片上传相关的API接口定义
|
||||
|
||||
/**
|
||||
* 文件分片请求接口
|
||||
*/
|
||||
export interface UploadChunkRequest {
|
||||
/** 文件唯一标识 */
|
||||
fileId: string;
|
||||
/** 分片索引,从0开始 */
|
||||
chunkIndex: number;
|
||||
/** 总分片数量 */
|
||||
totalChunks: number;
|
||||
/** 分片大小 */
|
||||
chunkSize: number;
|
||||
/** 文件总大小 */
|
||||
totalSize: number;
|
||||
/** 文件名称 */
|
||||
fileName: string;
|
||||
/** 文件类型 */
|
||||
fileType: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件分片响应接口
|
||||
*/
|
||||
export interface UploadChunkResponse {
|
||||
success: boolean;
|
||||
message: string;
|
||||
chunkIndex: number;
|
||||
uploadedSize: number;
|
||||
isLastChunk?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并分片请求接口
|
||||
*/
|
||||
export interface MergeChunksRequest {
|
||||
/** 文件唯一标识 */
|
||||
fileId: string;
|
||||
/** 总分片数量 */
|
||||
totalChunks: number;
|
||||
/** 文件名称 */
|
||||
fileName: string;
|
||||
/** 文件类型 */
|
||||
fileType: string;
|
||||
/** 文件总大小 */
|
||||
totalSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并分片响应接口
|
||||
*/
|
||||
export interface MergeChunksResponse {
|
||||
success: boolean;
|
||||
message: string;
|
||||
fileUrl?: string;
|
||||
fileId: string;
|
||||
fileSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件上传状态请求接口
|
||||
*/
|
||||
export interface CheckUploadStatusRequest {
|
||||
/** 文件唯一标识 */
|
||||
fileId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查文件上传状态响应接口
|
||||
*/
|
||||
export interface CheckUploadStatusResponse {
|
||||
success: boolean;
|
||||
isUploaded: boolean;
|
||||
uploadedChunks: number[];
|
||||
totalChunks?: number;
|
||||
}
|
||||
63
types/upload/base.ts
Normal file
63
types/upload/base.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
// 上传相关的基础类型定义
|
||||
|
||||
/**
|
||||
* 上传状态枚举
|
||||
*/
|
||||
export enum UploadStatus {
|
||||
/** 初始状态 */
|
||||
INITIAL = 'INITIAL',
|
||||
/** 上传中 */
|
||||
UPLOADING = 'UPLOADING',
|
||||
/** 暂停 */
|
||||
PAUSED = 'PAUSED',
|
||||
/** 已完成 */
|
||||
COMPLETED = 'COMPLETED',
|
||||
/** 失败 */
|
||||
FAILED = 'FAILED'
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件分片信息
|
||||
*/
|
||||
export interface FileChunk {
|
||||
/** 分片索引 */
|
||||
index: number;
|
||||
/** 分片大小 */
|
||||
size: number;
|
||||
/** 分片起始位置 */
|
||||
start: number;
|
||||
/** 分片结束位置 */
|
||||
end: number;
|
||||
/** 是否已上传 */
|
||||
uploaded?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传任务信息
|
||||
*/
|
||||
export interface UploadTask {
|
||||
/** 任务ID */
|
||||
taskId: string;
|
||||
/** 文件ID */
|
||||
fileId: string;
|
||||
/** 文件信息 */
|
||||
file: File;
|
||||
/** 上传状态 */
|
||||
status: UploadStatus;
|
||||
/** 已上传大小 */
|
||||
uploadedSize: number;
|
||||
/** 总大小 */
|
||||
totalSize: number;
|
||||
/** 上传进度百分比 */
|
||||
progress: number;
|
||||
/** 分片大小 */
|
||||
chunkSize: number;
|
||||
/** 总分片数 */
|
||||
totalChunks: number;
|
||||
/** 已上传分片索引列表 */
|
||||
uploadedChunks: number[];
|
||||
/** 创建时间 */
|
||||
createdAt: number;
|
||||
/** 更新时间 */
|
||||
updatedAt: number;
|
||||
}
|
||||
3
types/upload/index.ts
Normal file
3
types/upload/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// 导出上传相关的类型定义
|
||||
export * from './api';
|
||||
export * from './base';
|
||||
@@ -1,30 +1,99 @@
|
||||
import type { User } from './base';
|
||||
import type { UserProfile } from './base';
|
||||
import type { PaginationRequest } from '../common';
|
||||
|
||||
// 获取热门作者请求接口
|
||||
export interface GetHotAuthorsRequest {
|
||||
limit?: number; // 每页数量
|
||||
days?: number; // 统计天数,默认30天
|
||||
// 获取当前用户个人资料相关接口(不需要参数,所以没有request)
|
||||
export interface GetMyProfileResponse {
|
||||
profile: UserProfile;
|
||||
}
|
||||
|
||||
// 获取他人档案相关接口
|
||||
export interface GetUserProfileRequest {
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export interface GetUserProfileResponse {
|
||||
profile: UserProfile;
|
||||
}
|
||||
|
||||
// 热门作者相关接口
|
||||
export interface GetHotAuthorsRequest extends PaginationRequest {
|
||||
// 已继承limit字段(page字段默认不用了)
|
||||
}
|
||||
|
||||
// 获取热门作者响应接口
|
||||
export interface GetHotAuthorsResponse {
|
||||
// 其实应该用profile返回的
|
||||
data: User[]; // 数据列表
|
||||
data: UserProfile[]; // 数据列表
|
||||
total: number; // 总数
|
||||
}
|
||||
|
||||
// 获取作者榜单请求接口
|
||||
export interface GetAuthorRankingRequest {
|
||||
limit?: number; // 每页数量
|
||||
period?: 'day' | 'week' | 'month'; // 统计周期
|
||||
type?: 'posts' | 'views' | 'likes'; // 排序类型
|
||||
// 登录注册相关接口
|
||||
export interface LoginRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
user: UserProfile;
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface RegisterResponse {
|
||||
user: UserProfile;
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
export interface ChangePasswordRequest {
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
export interface ChangePasswordResponse {
|
||||
user: UserProfile;
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
// 通知相关接口
|
||||
export type NotificationType = 'like' | 'comment' | 'follow' | 'mention';
|
||||
|
||||
export interface UserNotification {
|
||||
id: string;
|
||||
type: NotificationType;
|
||||
content: string;
|
||||
isRead: boolean;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
// 个人资料更新相关接口
|
||||
export interface UserProfileUpdateRequest {
|
||||
avatar?: string;
|
||||
introduction?: string;
|
||||
level?: string;
|
||||
}
|
||||
|
||||
export interface UserProfileUpdateResponse {
|
||||
profile: UserProfile;
|
||||
}
|
||||
|
||||
// 作者榜单相关接口
|
||||
export interface GetAuthorRankingRequest extends PaginationRequest {
|
||||
// 已继承limit字段(page字段默认不用了)
|
||||
}
|
||||
|
||||
// 获取作者榜单响应接口
|
||||
export interface GetAuthorRankingResponse {
|
||||
data: User[]; // 数据列表
|
||||
data: UserProfile[]; // 数据列表
|
||||
total: number; // 总数
|
||||
// 其实冗余了
|
||||
period: 'day' | 'week' | 'month'; // 统计周期
|
||||
type: 'posts' | 'views' | 'likes'; // 排序类型
|
||||
}
|
||||
|
||||
// 用户搜索相关接口
|
||||
export interface UserSearchRequest {
|
||||
keyword: string;
|
||||
}
|
||||
|
||||
export interface UserSearchResponse {
|
||||
users: Array<UserProfile>;
|
||||
total: number;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,14 @@
|
||||
import { NotificationType } from './enum';
|
||||
|
||||
// 最小用户信息
|
||||
export interface User{
|
||||
id: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
// 认证
|
||||
export interface LoginRequest{
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface LoginResponse{
|
||||
export interface UserProfile{
|
||||
user: User;
|
||||
sessionId: string;
|
||||
avatar: string;
|
||||
introduction: string;
|
||||
level: string;
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface RegisterResponse {
|
||||
user: User;
|
||||
sessionId: string;
|
||||
}
|
||||
|
||||
export interface ChangePasswordRequest { // 暂时用不到
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
// 目前只用得到session
|
||||
// export interface RefreshTokenRequest {
|
||||
// sessionId: string;
|
||||
// }
|
||||
|
||||
// export interface RefreshTokenResponse {
|
||||
// sessionId: string;
|
||||
// }
|
||||
|
||||
// 用户通知(暂时用不到)
|
||||
export interface UserNotification {
|
||||
id: string;
|
||||
userId: string;
|
||||
type: NotificationType;
|
||||
content: string;
|
||||
isRead: boolean;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// 通知类型枚举
|
||||
export enum NotificationType {
|
||||
LIKE = 'like',
|
||||
COMMENT = 'comment',
|
||||
FOLLOW = 'follow',
|
||||
MENTION = 'mention'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,2 @@
|
||||
export * from './base';
|
||||
export * from './profile';
|
||||
export * from './search';
|
||||
export * from './enum';
|
||||
export * from './api';
|
||||
export * from './api';
|
||||
@@ -1,38 +0,0 @@
|
||||
import type { User } from './base';
|
||||
|
||||
// 用户档案以及更新
|
||||
export interface UserProfile{
|
||||
user: User;
|
||||
avatar: string;
|
||||
introduction: string;
|
||||
level: string;
|
||||
}
|
||||
|
||||
export interface UserProfileUpdateRequest {
|
||||
avatar?: string;
|
||||
introduction?: string;
|
||||
level?: string;
|
||||
}
|
||||
|
||||
export interface UserProfileUpdateResponse {
|
||||
profile: UserProfile;
|
||||
}
|
||||
|
||||
// 用户关系
|
||||
export interface UserRelation {
|
||||
// 当前用户的id
|
||||
id: string;
|
||||
followerId: string[];
|
||||
followingId: string[];
|
||||
}
|
||||
|
||||
// 当前用户的id由cookie带上
|
||||
export interface UserFollowRequest {
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export interface UserFollowResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { UserProfile } from './profile';
|
||||
|
||||
// 用户搜索结果
|
||||
export interface UserSearchRequest {
|
||||
keyword: string;
|
||||
}
|
||||
|
||||
export interface UserSearchResponse {
|
||||
// 这里逻辑是对的(可惜暂时不打算做)
|
||||
users: Array<UserProfile>
|
||||
total: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user