Files
creator-hub/internal/controlplane/api/creator_collector.go
T
rogee 3f1e2d39f4 feat(creator): 自有账号监控后端——播放量入库、账号粉丝时序快照、监控 API
- migration 040/041:creator_work 与 creator_work_metric 加 play_count;新建 creator_account_metric 时序快照表
- douyin:详情接口解析 play_count;self profile 扩展解析粉丝/关注/获赞/作品数(flexibleInt 兼容字符串)
- creator store:PlayCount 全链路(UpsertWork COALESCE/RecordMetric/ListMetrics);RecordAccountMetric/ListAccountMetrics/ListAccountMonitorViews/GetAccountCollectionStatus
- controlplane:syncCreatorOwned 成功路径末尾记账号画像快照(失败 errors.Join 不吞错);新增 monitor-views/collection-status/metrics/sync 四个路由;creatorError 补 account.ErrNotFound→404
- 测试:integration/douyin/api 断言播放量落库与 COALESCE 语义、快照覆盖语义、路由 happy path 与 409/503/404 语义
2026-09-27 22:05:01 +08:00

69 lines
2.7 KiB
Go

package api
// 平台收敛为抖音:collector 装配与平台身份核验 helper。
// 原小红书平台分支已随平台下线整体移除。
import (
"context"
"encoding/base64"
"errors"
"fmt"
"strings"
"git.ipao.vip/rogee/creator-hub/internal/creator"
hub "git.ipao.vip/rogee/creator-hub/internal/environment"
douyin "git.ipao.vip/rogee/creator-hub/internal/platform/douyin"
)
func newCreatorCollector(ctx context.Context, platform string, gateway hub.Gateway, environment hub.EnvironmentContext, viewerAccountKey, targetAccountKey, _, sourceType, sourceID string) (creator.PlatformCollector, string, error) {
if strings.TrimSpace(viewerAccountKey) == "" || strings.TrimSpace(targetAccountKey) == "" {
return nil, "", fmt.Errorf("%w: creator collector account key is missing", creator.ErrInvalid)
}
if platform != creator.PlatformDouyin {
return nil, "", fmt.Errorf("%w: unsupported creator platform %s", creator.ErrUnavailable, platform)
}
browser := creatorGatewayBrowser{gateway: gateway, environment: environment}
if _, err := browser.Identity(ctx, viewerAccountKey); err != nil {
return nil, "", err
}
collector := douyinCollector(browser, targetAccountKey, sourceType, sourceID)
canonicalKey, err := collector.CanonicalTargetSecUID(ctx, targetAccountKey)
if err != nil {
return nil, "", err
}
return &collector, canonicalKey, nil
}
func douyinCollector(browser creatorGatewayBrowser, accountKey, sourceType, sourceID string) douyin.CreatorCollector {
return douyin.CreatorCollector{Browser: browser, AccountKey: accountKey, SourceType: sourceType, SourceID: sourceID}
}
// validateDouyinCompetitor 监控账号入队前的平台一致性校验(平台收敛后仅抖音)。
func validateDouyinCompetitor(input creator.CompetitorInput) error {
if input.Platform != creator.PlatformDouyin {
return creator.ErrInvalid
}
return nil
}
func verifyCreatorPlatformIdentity(ctx context.Context, platform string, gateway hub.Gateway, environment hub.EnvironmentContext, expectedKey string) (string, error) {
if platform != creator.PlatformDouyin {
return "", fmt.Errorf("%w: unsupported creator platform %s", creator.ErrUnavailable, platform)
}
return (creatorGatewayBrowser{gateway: gateway, environment: environment}).Identity(ctx, expectedKey)
}
func decodeBase64(value string) ([]byte, error) {
const maxEncoded = 96 << 20
if len(value) > maxEncoded {
return nil, errors.New("media response is too large")
}
data, err := base64.StdEncoding.DecodeString(value)
if err != nil {
return nil, fmt.Errorf("decode media response: %w", err)
}
if len(data) > maxCreatorMediaBytes {
return nil, errors.New("media response is too large")
}
return data, nil
}