Skip to content

Commit 665af28

Browse files
committed
feat: 按 Dify 官方 API 文档重写,API Key 留空则回退 iframe;填入密钥后可自动发送
1 parent 038a3ac commit 665af28

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/App.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React, { useState, useEffect, useMemo, useRef, useCallback } from 'react';
22
import { Clock, CheckCircle, XCircle, ChevronRight, ChevronLeft, RotateCcw, Cpu, Zap, Layers, BarChart3, AlertTriangle, CalendarClock, Github, Flag, Mail, X, Sparkles, Shuffle, User, BookOpen, Send } from 'lucide-react';
33
import { QUESTION_BANK } from './questionBank.js';
4+
5+
// Dify API 配置 - 请在 Dify 后台 "API 访问" 中生成密钥后替换
6+
const DIFY_API_KEY = ''; // 留空则使用 iframe 回退,填入形如 app-xxxx 的密钥启用自动发送
7+
const DIFY_API_BASE = 'https://udify.app/v1';
48
// 移除登录系统:不再需要LoginView和ProfileView
59
import { ExportMenu } from './MenuComponents.jsx';
610
import { NotificationMenu } from './NotificationComponent.jsx';
@@ -860,10 +864,12 @@ export default function App() {
860864

861865
// --- AI 解析功能 ---
862866
const callDifyApi = useCallback(async (queryText, signal) => {
863-
const resp = await fetch('https://udify.app/v1/chat-messages', {
867+
if (!DIFY_API_KEY) throw new Error('NO_API_KEY');
868+
869+
const resp = await fetch(`${DIFY_API_BASE}/chat-messages`, {
864870
method: 'POST',
865871
headers: {
866-
'Authorization': 'Bearer xg0maoDg7kzrcGT0',
872+
'Authorization': `Bearer ${DIFY_API_KEY}`,
867873
'Content-Type': 'application/json',
868874
},
869875
body: JSON.stringify({
@@ -876,7 +882,8 @@ export default function App() {
876882
});
877883

878884
if (!resp.ok) {
879-
console.warn(`[AI] API返回非200状态: ${resp.status}, 将使用iframe回退`);
885+
const errText = await resp.text().catch(() => '');
886+
console.warn(`[AI] API ${resp.status}: ${errText}`);
880887
throw new Error(`API_${resp.status}`);
881888
}
882889
return resp;

0 commit comments

Comments
 (0)