feat(publish): require cover image for WeChat Official Account
WeChat 公众号在管理员/运营者授权发布场景下需要 2.35:1 封面, 新增共享 publishPlatformRequiresCover 校验并同步前端封面要求与文案, 避免在调度与即时发布两条路径上重复维护平台名单。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -136,13 +137,22 @@ func (s *MediaService) listArticlePublishRecords(ctx context.Context, tenantID,
|
||||
|
||||
func publishBatchRequiresCover(accounts []platformAccountSeed) bool {
|
||||
for _, account := range accounts {
|
||||
if account.PlatformID == "baijiahao" || account.PlatformID == "dongchedi" {
|
||||
if publishPlatformRequiresCover(account.PlatformID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func publishPlatformRequiresCover(platformID string) bool {
|
||||
switch strings.TrimSpace(platformID) {
|
||||
case "weixin_gzh", "baijiahao", "dongchedi":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func pointerStringValue(value *string) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
|
||||
@@ -162,7 +162,7 @@ func (s *PublishJobService) Create(ctx context.Context, actor auth.Actor, req Cr
|
||||
accountSeeds = append(accountSeeds, *target.accountSeed)
|
||||
}
|
||||
if publishBatchRequiresCover(accountSeeds) && strings.TrimSpace(pointerStringValue(articleMeta.CoverAssetURL)) == "" {
|
||||
return nil, response.ErrBadRequest(40044, "publish_cover_required", "baijiahao publishing requires a cover image")
|
||||
return nil, response.ErrBadRequest(40044, "publish_cover_required", "selected publishing platform requires a cover image")
|
||||
}
|
||||
|
||||
publishBatchID, publishRecordIDs, err := createPublishBatchRecords(
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPublishPlatformRequiresCover(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, platformID := range []string{"weixin_gzh", "baijiahao", "dongchedi"} {
|
||||
if !publishPlatformRequiresCover(platformID) {
|
||||
t.Fatalf("publishPlatformRequiresCover(%q) = false, want true", platformID)
|
||||
}
|
||||
}
|
||||
|
||||
if publishPlatformRequiresCover("zhihu") {
|
||||
t.Fatal("publishPlatformRequiresCover(\"zhihu\") = true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishCoverRequirementCallersIncludeWeixinGzh(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
accounts := []platformAccountSeed{{PlatformID: "weixin_gzh"}}
|
||||
if !publishBatchRequiresCover(accounts) {
|
||||
t.Fatal("publishBatchRequiresCover() = false for weixin_gzh, want true")
|
||||
}
|
||||
|
||||
if !schedulePublishPlatformsRequireCover([]string{"weixin_gzh"}) {
|
||||
t.Fatal("schedulePublishPlatformsRequireCover() = false for weixin_gzh, want true")
|
||||
}
|
||||
}
|
||||
@@ -564,8 +564,7 @@ func (s *ScheduleTaskService) loadPublishAccountPlatformIDs(ctx context.Context,
|
||||
|
||||
func schedulePublishPlatformsRequireCover(platformIDs []string) bool {
|
||||
for _, platformID := range platformIDs {
|
||||
switch strings.TrimSpace(platformID) {
|
||||
case "baijiahao", "dongchedi":
|
||||
if publishPlatformRequiresCover(platformID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user