公众号助手bug修复

This commit is contained in:
Jackzhou
2026-08-27 18:00:58 +08:00
parent f864cc2c87
commit 8dfcb6547c
5 changed files with 573 additions and 40 deletions
@@ -35,6 +35,7 @@ func ensureOfficialAccountArticle(task model.WorkerTask, workflow officialAccoun
OutlineStyle: normalizeOfficialAccountOutlineStyle(workflow.Form.OutlineStyle),
OutlineWords: normalizeOfficialAccountOutlineWords(workflow.Form.OutlineWords),
ContentTargetWords: normalizeOfficialAccountContentTargetWords(workflow.Form.ContentTargetWords),
MaxContentImages: normalizeOfficialAccountMaxContentImages(workflow.Form.MaxContentImages),
Status: "draft",
}
if err := store.DB.Create(row).Error; err != nil {
@@ -56,6 +57,7 @@ func syncWorkflowFromOfficialAccountArticle(workflow *officialAccountWorkflowSta
workflow.Form.OutlineStyle = normalizeOfficialAccountOutlineStyle(article.OutlineStyle)
workflow.Form.OutlineWords = normalizeOfficialAccountOutlineWords(article.OutlineWords)
workflow.Form.ContentTargetWords = normalizeOfficialAccountContentTargetWords(article.ContentTargetWords)
workflow.Form.MaxContentImages = normalizeOfficialAccountMaxContentImages(article.MaxContentImages)
if strings.TrimSpace(article.TopicCandidatesJSON) != "" {
var items []officialAccountTopicCandidate
@@ -110,6 +112,7 @@ func syncOfficialAccountArticleFromWorkflow(article *model.OfficialAccountArticl
article.OutlineStyle = normalizeOfficialAccountOutlineStyle(workflow.Form.OutlineStyle)
article.OutlineWords = normalizeOfficialAccountOutlineWords(workflow.Form.OutlineWords)
article.ContentTargetWords = normalizeOfficialAccountContentTargetWords(workflow.Form.ContentTargetWords)
article.MaxContentImages = normalizeOfficialAccountMaxContentImages(workflow.Form.MaxContentImages)
article.SelectedTopic = workflow.Shared.SelectedTopic
article.SelectedTitle = workflow.Shared.SelectedTitle
article.Outline = workflow.Shared.Outline
@@ -174,6 +177,7 @@ func resetOfficialAccountArticle(article *model.OfficialAccountArticle, req offi
article.OutlineWords = normalizeOfficialAccountOutlineWords(req.OutlineWords)
article.Outline = ""
article.ContentTargetWords = normalizeOfficialAccountContentTargetWords(req.ContentTargetWords)
article.MaxContentImages = normalizeOfficialAccountMaxContentImages(req.MaxContentImages)
article.Content = ""
article.ContentWithPrompts = ""
article.ImagePromptsJSON = "[]"
@@ -147,6 +147,7 @@ func executeOfficialAccountPageMarkdownStep(workflow *officialAccountWorkflowSta
func buildOfficialAccountImagePrompts(workflow *officialAccountWorkflowState) []officialAccountImagePrompt {
title := firstNonEmpty(workflow.Shared.SelectedTitle, workflow.Form.Keyword, "公众号文章")
sections := extractOfficialAccountSections(workflow.Shared.Content)
maxContentImages := normalizeOfficialAccountMaxContentImages(workflow.Form.MaxContentImages)
prompts := []officialAccountImagePrompt{
{
Key: "cover",
@@ -155,7 +156,7 @@ func buildOfficialAccountImagePrompts(workflow *officialAccountWorkflowState) []
},
}
for idx, item := range sections {
if idx >= 3 {
if maxContentImages > 0 && idx >= maxContentImages {
break
}
prompts = append(prompts, officialAccountImagePrompt{
@@ -46,6 +46,7 @@ type officialAccountTaskCreateReq struct {
OutlineStyle string `json:"outline_style"`
OutlineWords int `json:"outline_words"`
ContentTargetWords int `json:"content_target_words"`
MaxContentImages int `json:"max_content_images"`
}
type officialAccountStepReq struct {
@@ -67,6 +68,7 @@ type officialAccountTaskUpdateReq struct {
OutlineStyle string `json:"outline_style"`
OutlineWords int `json:"outline_words"`
ContentTargetWords int `json:"content_target_words"`
MaxContentImages int `json:"max_content_images"`
}
type officialAccountWorkflowState struct {
@@ -87,6 +89,7 @@ type officialAccountForm struct {
OutlineStyle string `json:"outline_style"`
OutlineWords int `json:"outline_words"`
ContentTargetWords int `json:"content_target_words"`
MaxContentImages int `json:"max_content_images"`
}
type officialAccountSharedState struct {
@@ -275,7 +278,8 @@ func UpdateOfficialAccountTask(c *gin.Context) {
oldWorkflow.Form.Requirements != req.Requirements ||
oldWorkflow.Form.OutlineStyle != normalizeOfficialAccountOutlineStyle(req.OutlineStyle) ||
oldWorkflow.Form.OutlineWords != normalizeOfficialAccountOutlineWords(req.OutlineWords) ||
oldWorkflow.Form.ContentTargetWords != normalizeOfficialAccountContentTargetWords(req.ContentTargetWords)
oldWorkflow.Form.ContentTargetWords != normalizeOfficialAccountContentTargetWords(req.ContentTargetWords) ||
oldWorkflow.Form.MaxContentImages != normalizeOfficialAccountMaxContentImages(req.MaxContentImages)
workflow := oldWorkflow
if changed {
@@ -289,6 +293,7 @@ func UpdateOfficialAccountTask(c *gin.Context) {
OutlineStyle: req.OutlineStyle,
OutlineWords: req.OutlineWords,
ContentTargetWords: req.ContentTargetWords,
MaxContentImages: req.MaxContentImages,
})
} else {
workflow.Form.BusinessDomain = resolveOfficialAccountBusinessDomain(req.BusinessDomain, req.Keyword)
@@ -300,6 +305,7 @@ func UpdateOfficialAccountTask(c *gin.Context) {
workflow.Form.OutlineStyle = normalizeOfficialAccountOutlineStyle(req.OutlineStyle)
workflow.Form.OutlineWords = normalizeOfficialAccountOutlineWords(req.OutlineWords)
workflow.Form.ContentTargetWords = normalizeOfficialAccountContentTargetWords(req.ContentTargetWords)
workflow.Form.MaxContentImages = normalizeOfficialAccountMaxContentImages(req.MaxContentImages)
}
if changed {
@@ -352,6 +358,7 @@ func UpdateOfficialAccountTask(c *gin.Context) {
"outline_style": normalizeOfficialAccountOutlineStyle(req.OutlineStyle),
"outline_words": normalizeOfficialAccountOutlineWords(req.OutlineWords),
"content_target_words": normalizeOfficialAccountContentTargetWords(req.ContentTargetWords),
"max_content_images": normalizeOfficialAccountMaxContentImages(req.MaxContentImages),
})
logsJSON, _ := json.Marshal([]string{
fmt.Sprintf("%s 已切换主题并重置流程", now.Format("15:04:05")),
@@ -556,6 +563,7 @@ func newOfficialAccountWorkflow(req officialAccountTaskCreateReq) officialAccoun
OutlineStyle: normalizeOfficialAccountOutlineStyle(req.OutlineStyle),
OutlineWords: normalizeOfficialAccountOutlineWords(req.OutlineWords),
ContentTargetWords: normalizeOfficialAccountContentTargetWords(req.ContentTargetWords),
MaxContentImages: normalizeOfficialAccountMaxContentImages(req.MaxContentImages),
},
Steps: map[string]*officialAccountStepState{},
Shared: officialAccountSharedState{
@@ -611,6 +619,16 @@ func normalizeOfficialAccountContentTargetWords(value int) int {
return value
}
func normalizeOfficialAccountMaxContentImages(value int) int {
if value <= 0 {
return 0
}
if value > 20 {
return 20
}
return value
}
func parseOfficialAccountWorkflow(value string) officialAccountWorkflowState {
if strings.TrimSpace(value) == "" {
return newOfficialAccountWorkflow(officialAccountTaskCreateReq{})
@@ -634,6 +652,7 @@ func parseOfficialAccountWorkflow(value string) officialAccountWorkflowState {
if workflow.Form.Tone == "" {
workflow.Form.Tone = "专业但好懂"
}
workflow.Form.MaxContentImages = normalizeOfficialAccountMaxContentImages(workflow.Form.MaxContentImages)
if workflow.Steps == nil {
workflow.Steps = map[string]*officialAccountStepState{}
}