temp:临时备份,测试合并兼容性

This commit is contained in:
PingChuan
2025-11-20 20:36:42 +08:00
parent 2e604e8ede
commit b9fe57c5fa
12 changed files with 1310 additions and 36 deletions
+63
View File
@@ -0,0 +1,63 @@
/**
* Collabora 配置生成 API 路由
*
* 功能:
* - 生成 Collabora iframe URL
* - 生成 WOPI access token
* - 返回完整的 Collabora 配置
*
* @encoding UTF-8
*/
import { type LoaderFunctionArgs, json } from '@remix-run/node';
import { getUserSession } from '~/api/login/auth.server';
import { generateCollaboraConfig } from '~/lib/collabora/config.server';
/**
* GET /api/collabora/config
*
* 查询参数:
* - fileId: 文件路径(例如:contracts/test.docx
* - mode: 模式(view 或 edit),默认 view
* - userId: 用户 ID(可选,从 session 获取)
* - userName: 用户名(可选,从 session 获取)
*/
export async function loader({ request }: LoaderFunctionArgs) {
try {
// 获取用户会话信息
const { userInfo } = await getUserSession(request);
// 解析查询参数
const url = new URL(request.url);
const fileId = url.searchParams.get('fileId');
const mode = (url.searchParams.get('mode') || 'view') as 'view' | 'edit';
const userId = url.searchParams.get('userId') || userInfo?.sub || 'guest';
const userName = url.searchParams.get('userName') || userInfo?.nick_name || '访客';
// 验证必需参数
if (!fileId) {
return json(
{ error: '文件路径不能为空' },
{ status: 400 }
);
}
// 生成 Collabora 配置
const config = await generateCollaboraConfig({
fileId,
mode,
userId,
userName,
});
return json(config);
} catch (error) {
console.error('生成 Collabora 配置失败:', error);
return json(
{
error: error instanceof Error ? error.message : '生成配置失败',
},
{ status: 500 }
);
}
}