feat: Refactor template handling and brand management

- Removed schema_json from article templates and related queries.
- Updated brand service to include website field in requests and responses.
- Simplified template wizard view by eliminating unused schema fields and related logic.
- Added tests for ark text format handling.
- Created migrations for dropping schema_json and adding website to brands.
This commit is contained in:
2026-04-02 11:38:08 +08:00
parent 7fa1809682
commit 111498a65f
25 changed files with 298 additions and 379 deletions
+7 -12
View File
@@ -140,12 +140,11 @@ func main() {
// Platform templates
templates := []struct {
key, name, schema, prompt, cardConfig string
key, name, prompt, cardConfig string
}{
{
"top_x_article",
"Top X 文章",
`{"fields":[{"name":"topic","type":"text","label":"话题","required":true},{"name":"count","type":"number","label":"数量","required":true,"default":10}]}`,
`你是一名经验丰富的内容编辑,请围绕「{{topic}}」撰写一篇完整的 Markdown 推荐类文章。
文章目标:
1. 帮读者快速理解这个主题下值得关注的 {{count}} 个方向、产品或对象。
@@ -245,7 +244,6 @@ func main() {
{
"product_review",
"产品评测文章",
`{"fields":[{"name":"product_name","type":"text","label":"产品名称","required":true},{"name":"category","type":"text","label":"品类","required":true}]}`,
`你是一名资深产品评测编辑,请围绕「{{product_name}}」这款{{category}}产品撰写一篇完整的 Markdown 评测文章。
文章目标:
1. 帮读者判断这款产品是否值得关注或购买。
@@ -346,7 +344,6 @@ func main() {
{
"research_report",
"研究报告文章",
`{"fields":[{"name":"subject","type":"text","label":"研究主题","required":true},{"name":"depth","type":"select","label":"深度","options":["overview","detailed"],"default":"overview"}]}`,
`你是一名研究分析师,请围绕「{{subject}}」撰写一篇完整的 Markdown 研究报告。
文章目标:
1. 提炼关键事实、趋势与结构化发现。
@@ -439,7 +436,6 @@ func main() {
{
"brand_search_expansion",
"品牌词搜索扩写",
`{"fields":[{"name":"brand","type":"text","label":"品牌名","required":true},{"name":"keyword","type":"text","label":"关键词","required":true}]}`,
`你是一名擅长搜索意图写作的内容编辑,请围绕「{{brand}} {{keyword}}」撰写一篇完整的 Markdown 品牌词搜索扩写文章。
文章目标:
1. 直接回答搜索用户最关心的问题。
@@ -536,10 +532,10 @@ func main() {
for _, t := range templates {
_, err = tx.Exec(ctx, `
INSERT INTO article_templates (scope, origin_type, template_key, template_name, schema_json, prompt_template, prompt_visibility, card_config_json, status)
VALUES ('platform', 'platform', $1, $2, $3::jsonb, $4, 'visible', $5::jsonb, 'active')
INSERT INTO article_templates (scope, origin_type, template_key, template_name, prompt_template, prompt_visibility, card_config_json, status)
VALUES ('platform', 'platform', $1, $2, $3, 'visible', $4::jsonb, 'active')
ON CONFLICT DO NOTHING
`, t.key, t.name, t.schema, t.prompt, t.cardConfig)
`, t.key, t.name, t.prompt, t.cardConfig)
if err != nil {
log.Fatalf("insert template %s: %v", t.key, err)
}
@@ -547,16 +543,15 @@ func main() {
_, err = tx.Exec(ctx, `
UPDATE article_templates
SET template_name = $2,
schema_json = $3::jsonb,
prompt_template = $4,
card_config_json = $5::jsonb,
prompt_template = $3,
card_config_json = $4::jsonb,
prompt_visibility = 'visible',
status = 'active',
updated_at = NOW()
WHERE scope = 'platform'
AND template_key = $1
AND deleted_at IS NULL
`, t.key, t.name, t.schema, t.prompt, t.cardConfig)
`, t.key, t.name, t.prompt, t.cardConfig)
if err != nil {
log.Fatalf("update template %s: %v", t.key, err)
}