🎉 first commit

This commit is contained in:
LIlGG
2025-09-24 13:06:25 +08:00
commit 1f4fb103e9
409 changed files with 61222 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
import { type ActionFunctionArgs, type LoaderFunctionArgs } from '@remix-run/node';
import { requireAuth } from '~/lib/.server/auth';
import { errorResponse } from '~/utils/api-response';
import { handleDeleteAction } from './delete.server';
import { handleForkAction } from './fork.server';
import { handleListLoader } from './list.server';
import { handleUpdateAction } from './update.server';
/**
* 动态路由处理聊天相关操作
* 支持的操作:
* - list: 获取聊天列表GET请求
* - delete: 删除聊天
* - update: 更新聊天
* - fork: 复制聊天
*/
/**
* 处理GET请求用于获取数据
*/
export async function loader(args: LoaderFunctionArgs) {
const authResult = await requireAuth(args.request, { isApi: true });
if (authResult instanceof Response) {
return authResult;
}
const userId = authResult.userInfo?.sub;
if (!userId) {
return errorResponse(401, '用户未登录');
}
// 获取操作类型
const { action } = args.params;
// 根据操作类型分发到不同的处理函数
switch (action) {
case 'list':
return handleListLoader({ ...args, userId });
default:
return errorResponse(400, `不支持的操作: ${action}`);
}
}
/**
* 处理非GET请求用于修改数据
*/
export async function action(args: ActionFunctionArgs) {
const authResult = await requireAuth(args.request, { isApi: true });
if (authResult instanceof Response) {
return authResult;
}
const userId = authResult.userInfo?.sub;
if (!userId) {
return errorResponse(401, '用户未登录');
}
// 获取操作类型
const { action } = args.params;
// 根据操作类型分发到不同的处理函数
switch (action) {
case 'delete':
return handleDeleteAction({ ...args, userId });
case 'update':
return handleUpdateAction({ ...args, userId });
case 'fork':
return handleForkAction({ ...args, userId });
default:
return errorResponse(400, `不支持的操作: ${action}`);
}
}