diff --git a/server/api/share_routes.py b/server/api/share_routes.py index 8fa2453..38a3ec7 100644 --- a/server/api/share_routes.py +++ b/server/api/share_routes.py @@ -94,7 +94,7 @@ async def create_share_handler(data: dict): return { "id": share["id"], - "shareUrl": f"/#/share/{share['id']}", + "shareUrl": f"/chat-ui/share/{share['id']}", "expiresAt": share["expiresAt"], } @@ -114,7 +114,7 @@ async def create_share_handler(data: dict): conv_snapshot = { "id": conv["id"], "title": conv["title"], - "messages": conv.get("messages", [])[:100], # 限制消息数量 + "messages": conv.get("messages", []), "createdAt": conv["createdAt"], "updatedAt": conv["updatedAt"], } @@ -139,7 +139,7 @@ async def create_share_handler(data: dict): # 返回分享信息 return { "id": share["id"], - "shareUrl": f"/#/share/{share['id']}", + "shareUrl": f"/chat-ui/share/{share['id']}", "expiresAt": share["expiresAt"], } @@ -227,4 +227,4 @@ async def verify_share_handler(share_id: str, data: dict): "viewCount": view_count, "hasPassword": bool(share["passwordHash"]), }, - } \ No newline at end of file + } diff --git a/src/__tests__/shareApi.test.ts b/src/__tests__/shareApi.test.ts index ab693f4..154f01e 100644 --- a/src/__tests__/shareApi.test.ts +++ b/src/__tests__/shareApi.test.ts @@ -24,7 +24,7 @@ describe('分享 API 测试', () => { it('应该成功创建分享', async () => { const mockResponse: ShareCreateResponse = { id: 'share-123', - shareUrl: 'https://example.com/#/share/share-123', + shareUrl: 'https://example.com/chat-ui/share/share-123', expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000, } @@ -147,4 +147,4 @@ describe('分享 API 测试', () => { expect(result.share).toBeUndefined() }) }) -}) \ No newline at end of file +}) diff --git a/src/components/modals/ShareModal.vue b/src/components/modals/ShareModal.vue index f004bf9..0af6fbc 100644 --- a/src/components/modals/ShareModal.vue +++ b/src/components/modals/ShareModal.vue @@ -191,8 +191,8 @@ async function handleCreateShare() { // 关闭当前模态框,打开结果模态框 handleClose() - // 前端生成分享 URL - const shareUrl = `${window.location.origin}/chat-ui/share/${result.id}` + // 优先使用后端返回的路径,避免前后端各自拼接导致不一致 + const shareUrl = new URL(result.shareUrl, window.location.origin).toString() // 存储分享信息并打开结果模态框 settingsStore.setShareResult({ @@ -576,4 +576,4 @@ watch(show, (newVal: boolean) => { transform: scale(0.95); } } - \ No newline at end of file +