过渡版:本地验发token
This commit is contained in:
1 parent
fb71def840
commit
a5f0ec645d
14 files changed
+313
-220
No files matched your search
@@ -6,6 +6,7 @@
|
||||
* 逻辑关系:封装 Fetch API 处理流式响应,供 ChatView 组件使用
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
interface RetrieverResource {
|
||||
// 知识库/检索来源的基础字段,具体键可能因后端返回而扩展
|
||||
@@ -119,32 +120,6 @@ export function useChat() {
|
||||
*/
|
||||
const conversationId = ref<string | null>(null);
|
||||
|
||||
const getAuthHeaders = () => {
|
||||
const candidates = [
|
||||
sessionStorage.getItem('hxops_user'),
|
||||
localStorage.getItem('hxops_user'),
|
||||
];
|
||||
for (const stored of candidates) {
|
||||
if (!stored) continue;
|
||||
try {
|
||||
const data = JSON.parse(stored) as any;
|
||||
const user = data.user || data;
|
||||
if (!user?.username || !user?.role) continue;
|
||||
const headers: Record<string, string> = {
|
||||
'X-Username': user.username,
|
||||
'X-Role': user.role,
|
||||
};
|
||||
if (user.id) {
|
||||
headers['X-User-Id'] = String(user.id);
|
||||
}
|
||||
return headers;
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
/**
|
||||
* sendMessage
|
||||
* 用途:发送消息并处理 SSE 流式响应
|
||||
|
||||
Reference in new issue
Block a user