feat: 添加获取视觉规则 API
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getVisualStyleRules } from '@/hooks/useKeywordCloud';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
/**
|
||||
* GET /api/keyword-cloud/rules
|
||||
* 获取视觉样式规则配置
|
||||
*/
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const enabled = searchParams.get('enabled');
|
||||
|
||||
const rules = await getVisualStyleRules(
|
||||
enabled !== null ? { enabled: enabled === 'true' } : undefined
|
||||
);
|
||||
|
||||
// 转换规则格式以匹配前端期望
|
||||
const formattedRules = rules.map(rule => ({
|
||||
id: rule.id,
|
||||
name: rule.name,
|
||||
minScore: rule.minScore,
|
||||
maxScore: rule.maxScore,
|
||||
visualConfig: {
|
||||
color: rule.color,
|
||||
size: rule.size,
|
||||
border: rule.border,
|
||||
rotation: rule.rotation,
|
||||
},
|
||||
priority: rule.priority,
|
||||
enabled: rule.enabled,
|
||||
}));
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
rules: formattedRules,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching visual style rules:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Failed to fetch rules',
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user