- 修复 folder-aciton.ts 文件名拼写错误为 folder-action.ts - 修复所有导入路径中的拼写错误 - 添加 repoGetPublicFolderById 和 actionGetPublicFolderById - 创建 ExploreDetailClient 详情页组件 - /explore/[id] 现在显示文件夹详情和链接到 /folders/[id] - 添加 exploreDetail 中英文翻译
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import { LENGTH_MAX_FOLDER_NAME, LENGTH_MAX_IPA, LENGTH_MAX_LANGUAGE, LENGTH_MAX_PAIR_TEXT, LENGTH_MIN_FOLDER_NAME, LENGTH_MIN_IPA, LENGTH_MIN_LANGUAGE, LENGTH_MIN_PAIR_TEXT } from "@/shared/constant";
|
|
import { TSharedFolderWithTotalPairs } from "@/shared/folder-type";
|
|
import { generateValidator } from "@/utils/validate";
|
|
import z from "zod";
|
|
|
|
export const schemaActionInputCreatePair = z.object({
|
|
text1: z.string().min(LENGTH_MIN_PAIR_TEXT).max(LENGTH_MAX_PAIR_TEXT),
|
|
text2: z.string().min(LENGTH_MIN_PAIR_TEXT).max(LENGTH_MAX_PAIR_TEXT),
|
|
language1: z.string().min(LENGTH_MIN_LANGUAGE).max(LENGTH_MAX_LANGUAGE),
|
|
language2: z.string().min(LENGTH_MIN_LANGUAGE).max(LENGTH_MAX_LANGUAGE),
|
|
ipa1: z.string().min(LENGTH_MIN_IPA).max(LENGTH_MAX_IPA).optional(),
|
|
ipa2: z.string().min(LENGTH_MIN_IPA).max(LENGTH_MAX_IPA).optional(),
|
|
folderId: z.int()
|
|
});
|
|
export type ActionInputCreatePair = z.infer<typeof schemaActionInputCreatePair>;
|
|
export const validateActionInputCreatePair = generateValidator(schemaActionInputCreatePair);
|
|
|
|
export const schemaActionInputUpdatePairById = z.object({
|
|
text1: z.string().min(LENGTH_MIN_PAIR_TEXT).max(LENGTH_MAX_PAIR_TEXT).optional(),
|
|
text2: z.string().min(LENGTH_MIN_PAIR_TEXT).max(LENGTH_MAX_PAIR_TEXT).optional(),
|
|
language1: z.string().min(LENGTH_MIN_LANGUAGE).max(LENGTH_MAX_LANGUAGE).optional(),
|
|
language2: z.string().min(LENGTH_MIN_LANGUAGE).max(LENGTH_MAX_LANGUAGE).optional(),
|
|
ipa1: z.string().min(LENGTH_MIN_IPA).max(LENGTH_MAX_IPA).optional(),
|
|
ipa2: z.string().min(LENGTH_MIN_IPA).max(LENGTH_MAX_IPA).optional(),
|
|
folderId: z.int().optional()
|
|
});
|
|
export type ActionInputUpdatePairById = z.infer<typeof schemaActionInputUpdatePairById>;
|
|
export const validateActionInputUpdatePairById = generateValidator(schemaActionInputUpdatePairById);
|
|
|
|
export type ActionOutputGetFoldersWithTotalPairsByUserId = {
|
|
message: string,
|
|
success: boolean,
|
|
data?: TSharedFolderWithTotalPairs[];
|
|
};
|
|
|
|
export const schemaActionInputSetFolderVisibility = z.object({
|
|
folderId: z.number().int().positive(),
|
|
visibility: z.enum(["PRIVATE", "PUBLIC"]),
|
|
});
|
|
export type ActionInputSetFolderVisibility = z.infer<typeof schemaActionInputSetFolderVisibility>;
|
|
|
|
export const schemaActionInputSearchPublicFolders = z.object({
|
|
query: z.string().min(1).max(100),
|
|
});
|
|
export type ActionInputSearchPublicFolders = z.infer<typeof schemaActionInputSearchPublicFolders>;
|
|
|
|
export type ActionOutputPublicFolder = {
|
|
id: number;
|
|
name: string;
|
|
visibility: "PRIVATE" | "PUBLIC";
|
|
createdAt: Date;
|
|
userId: string;
|
|
userName: string | null;
|
|
userUsername: string | null;
|
|
totalPairs: number;
|
|
favoriteCount: number;
|
|
};
|
|
|
|
export type ActionOutputGetPublicFolders = {
|
|
message: string;
|
|
success: boolean;
|
|
data?: ActionOutputPublicFolder[];
|
|
};
|
|
|
|
export type ActionOutputGetPublicFolderById = {
|
|
message: string;
|
|
success: boolean;
|
|
data?: ActionOutputPublicFolder;
|
|
};
|
|
|
|
export type ActionOutputSetFolderVisibility = {
|
|
message: string;
|
|
success: boolean;
|
|
};
|
|
|
|
export type ActionOutputToggleFavorite = {
|
|
message: string;
|
|
success: boolean;
|
|
data?: {
|
|
isFavorited: boolean;
|
|
favoriteCount: number;
|
|
};
|
|
};
|
|
|
|
export type ActionOutputCheckFavorite = {
|
|
message: string;
|
|
success: boolean;
|
|
data?: {
|
|
isFavorited: boolean;
|
|
favoriteCount: number;
|
|
};
|
|
};
|
|
|
|
export type ActionOutputUserFavorite = {
|
|
id: number;
|
|
folderId: number;
|
|
folderName: string;
|
|
folderCreatedAt: Date;
|
|
folderTotalPairs: number;
|
|
folderOwnerId: string;
|
|
folderOwnerName: string | null;
|
|
folderOwnerUsername: string | null;
|
|
favoritedAt: Date;
|
|
};
|
|
|
|
export type ActionOutputGetUserFavorites = {
|
|
message: string;
|
|
success: boolean;
|
|
data?: ActionOutputUserFavorite[];
|
|
};
|