feat: Add platform adapters for various content publishing platforms
- Implemented Dongchedi adapter for user detection and publishing. - Implemented Jianshu adapter for user detection and publishing. - Implemented Juejin adapter for user detection and publishing. - Implemented Qiehao adapter for user detection and publishing. - Implemented Smzdm adapter for user detection and publishing. - Implemented Sohuhao adapter for user detection and publishing. - Implemented Toutiaohao adapter for user detection and publishing. - Implemented Wangyihao adapter for user detection and publishing. - Implemented Weixin Gzh adapter for user detection and publishing. - Implemented Zol adapter for user detection and publishing. - Added documentation for manual testing of media publishing.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
@@ -19,11 +20,12 @@ import (
|
||||
const minBrowserExtensionVersion = "0.1.0"
|
||||
|
||||
type MediaService struct {
|
||||
pool *pgxpool.Pool
|
||||
pool *pgxpool.Pool
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewMediaService(pool *pgxpool.Pool) *MediaService {
|
||||
return &MediaService{pool: pool}
|
||||
func NewMediaService(pool *pgxpool.Pool, logger *zap.Logger) *MediaService {
|
||||
return &MediaService{pool: pool, logger: logger}
|
||||
}
|
||||
|
||||
type MediaPlatformResponse struct {
|
||||
@@ -712,6 +714,22 @@ func (s *MediaService) HandlePublishCallback(ctx context.Context, req PluginPubl
|
||||
publishedAt = &now
|
||||
}
|
||||
|
||||
if reqStatus != "success" && s.logger != nil {
|
||||
s.logger.Warn("publisher callback reported non-success status",
|
||||
zap.Int64("plugin_session_id", req.PluginSessionID),
|
||||
zap.Int64("publish_record_id", req.PublishRecordID),
|
||||
zap.Int64("platform_account_id", req.PlatformAccountID),
|
||||
zap.Int64("article_id", req.ArticleID),
|
||||
zap.String("platform_id", req.PlatformID),
|
||||
zap.String("status", reqStatus),
|
||||
zap.Stringp("error_message", req.ErrorMessage),
|
||||
zap.Stringp("external_article_id", req.ExternalArticleID),
|
||||
zap.Stringp("external_article_url", req.ExternalArticleURL),
|
||||
zap.Any("request_payload", req.RequestPayload),
|
||||
zap.Any("response_payload", req.ResponsePayload),
|
||||
)
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `
|
||||
UPDATE publish_records
|
||||
SET status = $1,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
@@ -11,11 +12,15 @@ import (
|
||||
)
|
||||
|
||||
type MediaHandler struct {
|
||||
svc *app.MediaService
|
||||
svc *app.MediaService
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewMediaHandler(a *bootstrap.App) *MediaHandler {
|
||||
return &MediaHandler{svc: app.NewMediaService(a.DB)}
|
||||
return &MediaHandler{
|
||||
svc: app.NewMediaService(a.DB, a.Logger),
|
||||
logger: a.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *MediaHandler) ListPlatforms(c *gin.Context) {
|
||||
@@ -118,6 +123,18 @@ func (h *MediaHandler) PluginBindCallback(c *gin.Context) {
|
||||
}
|
||||
data, err := h.svc.HandleBindCallback(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
if h.logger != nil {
|
||||
appErr := response.Normalize(err)
|
||||
h.logger.Warn("publisher bind callback failed",
|
||||
zap.String("request_id", c.GetString("request_id")),
|
||||
zap.Int64("plugin_session_id", req.PluginSessionID),
|
||||
zap.String("platform_id", req.PlatformID),
|
||||
zap.String("platform_uid", req.PlatformUID),
|
||||
zap.Int("code", appErr.Code),
|
||||
zap.String("message", appErr.Message),
|
||||
zap.String("detail", appErr.Detail),
|
||||
)
|
||||
}
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
@@ -132,6 +149,24 @@ func (h *MediaHandler) PluginPublishCallback(c *gin.Context) {
|
||||
}
|
||||
data, err := h.svc.HandlePublishCallback(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
if h.logger != nil {
|
||||
appErr := response.Normalize(err)
|
||||
h.logger.Warn("publisher publish callback failed",
|
||||
zap.String("request_id", c.GetString("request_id")),
|
||||
zap.Int64("plugin_session_id", req.PluginSessionID),
|
||||
zap.Int64("publish_record_id", req.PublishRecordID),
|
||||
zap.Int64("platform_account_id", req.PlatformAccountID),
|
||||
zap.Int64("article_id", req.ArticleID),
|
||||
zap.String("platform_id", req.PlatformID),
|
||||
zap.String("status", req.Status),
|
||||
zap.Stringp("error_message", req.ErrorMessage),
|
||||
zap.Int("code", appErr.Code),
|
||||
zap.String("message", appErr.Message),
|
||||
zap.String("detail", appErr.Detail),
|
||||
zap.Any("request_payload", req.RequestPayload),
|
||||
zap.Any("response_payload", req.ResponsePayload),
|
||||
)
|
||||
}
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user