chore: update api endpoints and lock tenant role

This commit is contained in:
xiaohei
2025-12-29 05:26:29 +00:00
parent 8372183d01
commit 884e2a4cfc
2 changed files with 49 additions and 22 deletions
+9 -16
View File
@@ -927,22 +927,15 @@ export default function ChannelDashboard() {
</div>
<div className="space-y-2">
<Label htmlFor="plan">{language === "zh" ? "系统权限" : "System Role"}</Label>
<Select
value={createTenantForm.systemRole}
onValueChange={(value: "tenant" | "admin" | "billing-admin" | "operations-admin") =>
setCreateTenantForm({ ...createTenantForm, systemRole: value })
}
>
<SelectTrigger className="bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="tenant">{language === "zh" ? "租户" : "Tenant"}</SelectItem>
<SelectItem value="admin">{language === "zh" ? "管理员" : "Admin"}</SelectItem>
<SelectItem value="billing-admin">{language === "zh" ? "计费管理员" : "Billing Admin"}</SelectItem>
<SelectItem value="operations-admin">{language === "zh" ? "运营管理员" : "Operations Admin"}</SelectItem>
</SelectContent>
</Select>
<Input
id="plan"
value={language === "zh" ? "租户(默认)" : "Tenant (default)"}
readOnly
disabled
className="bg-muted text-muted-foreground"
/>
{/* 锁定为租户角色,避免渠道端自行调整权限 */}
<input type="hidden" value={createTenantForm.systemRole} readOnly />
</div>
</div>
<DialogFooter>
+40 -6
View File
@@ -3,9 +3,9 @@
import { getAuthToken, clearAllTokens } from "@/lib/auth"
export const API_BASE_URLS = {
dataIngestion: process.env.NEXT_PUBLIC_DATA_INGESTION_URL || "http://localhost:8001",
mcpServer: process.env.NEXT_PUBLIC_MCP_SERVER_URL || "http://localhost:8002", // MCP Server 映射到主机端口 8002
gateway: process.env.NEXT_PUBLIC_API_GATEWAY_URL || "http://localhost:80",
dataIngestion: process.env.NEXT_PUBLIC_DATA_INGESTION_URL || "http://135.171.216.9/api/data-ingestion",
mcpServer: process.env.NEXT_PUBLIC_MCP_SERVER_URL || "http://135.171.216.9/api/mcp",
gateway: process.env.NEXT_PUBLIC_API_GATEWAY_URL || "http://135.171.216.9/api",
}
// Helper function to get API key
@@ -70,11 +70,45 @@ export interface APIResponse<T = any> {
// Helper function to handle API responses
async function handleResponse<T = any>(response: Response): Promise<T> {
const contentType = response.headers.get("content-type")
// 先读取响应文本
const text = await response.text()
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: response.statusText }))
throw new Error((error as any).detail || `HTTP error! status: ${response.status}`)
let errorMessage = `HTTP ${response.status}: ${response.statusText}`
// 尝试解析错误响应
if (contentType?.includes("application/json") && text) {
try {
const error = JSON.parse(text)
errorMessage = error.detail || error.message || errorMessage
} catch (e) {
console.error("Failed to parse error response as JSON:", e)
console.error("Response text:", text.substring(0, 200))
}
} else {
console.error("Non-JSON error response:", text.substring(0, 200))
}
throw new Error(errorMessage)
}
// 检查响应是否为JSON
if (!contentType?.includes("application/json")) {
console.error("Expected JSON but got:", contentType)
console.error("Response preview:", text.substring(0, 200))
throw new Error(`Server returned non-JSON response. Content-Type: ${contentType || 'unknown'}`)
}
// 解析JSON
try {
return JSON.parse(text) as T
} catch (e) {
console.error("Failed to parse JSON response:", e)
console.error("Response text:", text.substring(0, 300))
throw new Error("Invalid JSON response from server")
}
return response.json() as Promise<T>
}
// Helper function to check if backend is reachable