feat(reset): 以构造器模式重构

- 加了大文件传输自定义分片协议

BREAKING CHANGES: 0.1.0(latest)
This commit is contained in:
tobegold574
2025-11-30 20:27:53 +08:00
parent c5853847ae
commit 382e3aff21
82 changed files with 1421 additions and 7010 deletions

View File

@@ -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;

View File

@@ -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; // 作者信息
}

View File

@@ -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'
}

View File

@@ -1,4 +1,4 @@
// 导出帖子系统所有类型定义
export * from './base';
export * from './enum';
export * from './types';
export * from './api';

2
types/post/types.ts Normal file
View File

@@ -0,0 +1,2 @@
// 只有排序用到type
// 排序暂时不支持,先全部删了