feat(desktop): drop parked review flow, add publish management
SaaS 侧人工审核后才创建 publish job,desktop 不再做二次审核:移除 manual/waiting_user/parked/from_parked 状态机与 LeaseFromParked 查询, desktop client 只执行发布并新增"发布管理"页(待发布队列 / 历史 / 再次 发送)。同时抽离 @geo/publisher-platforms 共享适配器包、新增 Redis-based desktop_presence 与 publish_record_support,刷新 admin-web 发布弹窗与 媒体库;plan A / spec 文档同步口径。
This commit is contained in:
@@ -21,6 +21,8 @@ func NewDesktopAccountHandler(a *bootstrap.App) *DesktopAccountHandler {
|
||||
return &DesktopAccountHandler{
|
||||
svc: app.NewDesktopAccountService(
|
||||
repository.NewDesktopAccountRepository(a.DB),
|
||||
repository.NewDesktopClientRepository(a.DB),
|
||||
a.Redis,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -31,7 +33,16 @@ func (h *DesktopAccountHandler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.ListByClient(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
||||
data, err := h.svc.ListByUser(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopAccountHandler) TenantList(c *gin.Context) {
|
||||
data, err := h.svc.ListForActor(c.Request.Context(), auth.MustActor(c.Request.Context()))
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
|
||||
@@ -22,6 +22,10 @@ func (s *stubDesktopClientRepo) Register(ctx context.Context, params repository.
|
||||
panic("unexpected call")
|
||||
}
|
||||
|
||||
func (s *stubDesktopClientRepo) GetByID(ctx context.Context, id uuid.UUID, workspaceID int64) (*repository.DesktopClient, error) {
|
||||
panic("unexpected call")
|
||||
}
|
||||
|
||||
func (s *stubDesktopClientRepo) GetByTokenHash(ctx context.Context, tokenHash []byte) (*repository.DesktopClient, error) {
|
||||
if s.client == nil {
|
||||
return nil, context.Canceled
|
||||
|
||||
@@ -18,6 +18,7 @@ func NewDesktopClientHandler(a *bootstrap.App) *DesktopClientHandler {
|
||||
return &DesktopClientHandler{
|
||||
svc: app.NewDesktopClientService(
|
||||
repository.NewDesktopClientRepository(a.DB),
|
||||
a.Redis,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -71,3 +72,12 @@ func (h *DesktopClientHandler) Revoke(c *gin.Context) {
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopClientHandler) Offline(c *gin.Context) {
|
||||
data, err := h.svc.Offline(c.Request.Context(), MustDesktopClient(c.Request.Context()))
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package transport
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -11,20 +13,26 @@ import (
|
||||
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/app"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
||||
)
|
||||
|
||||
type DesktopTaskHandler struct {
|
||||
svc *app.DesktopTaskService
|
||||
svc *app.DesktopTaskService
|
||||
publishSvc *app.PublishJobService
|
||||
}
|
||||
|
||||
func NewDesktopTaskHandler(a *bootstrap.App) *DesktopTaskHandler {
|
||||
return &DesktopTaskHandler{
|
||||
svc: app.NewDesktopTaskService(
|
||||
repository.NewDesktopTaskRepository(a.DB),
|
||||
a.DB,
|
||||
a.RabbitMQ,
|
||||
a.Logger,
|
||||
),
|
||||
).WithCache(a.Cache),
|
||||
publishSvc: app.NewPublishJobService(
|
||||
a.DB,
|
||||
a.RabbitMQ,
|
||||
a.Redis,
|
||||
a.Logger,
|
||||
).WithCache(a.Cache),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +53,44 @@ func (h *DesktopTaskHandler) Lease(c *gin.Context) {
|
||||
routeTaskID = &parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.Lease(c.Request.Context(), MustDesktopClient(c.Request.Context()), req, routeTaskID, c.Query("from_parked") == "true")
|
||||
data, err := h.svc.Lease(c.Request.Context(), MustDesktopClient(c.Request.Context()), req, routeTaskID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopTaskHandler) ListPublish(c *gin.Context) {
|
||||
req := app.ListPublishTasksRequest{
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Title: strings.TrimSpace(c.Query("title")),
|
||||
}
|
||||
|
||||
if rawPage := c.Query("page"); rawPage != "" {
|
||||
parsed, err := strconv.Atoi(rawPage)
|
||||
if err != nil || parsed <= 0 {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page must be a positive integer"))
|
||||
return
|
||||
}
|
||||
req.Page = parsed
|
||||
}
|
||||
|
||||
rawPageSize := c.Query("page_size")
|
||||
if rawPageSize == "" {
|
||||
rawPageSize = c.Query("limit")
|
||||
}
|
||||
if rawPageSize != "" {
|
||||
parsed, err := strconv.Atoi(rawPageSize)
|
||||
if err != nil || parsed <= 0 {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page_size must be a positive integer"))
|
||||
return
|
||||
}
|
||||
req.PageSize = parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.ListPublishTasks(c.Request.Context(), MustDesktopClient(c.Request.Context()), req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
@@ -74,27 +119,6 @@ func (h *DesktopTaskHandler) Extend(c *gin.Context) {
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopTaskHandler) Park(c *gin.Context) {
|
||||
desktopID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40084, "invalid_desktop_task_id", "task id must be a uuid"))
|
||||
return
|
||||
}
|
||||
|
||||
var req app.ParkDesktopTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.Park(c.Request.Context(), MustDesktopClient(c.Request.Context()), desktopID, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopTaskHandler) Result(c *gin.Context) {
|
||||
desktopID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
@@ -116,6 +140,21 @@ func (h *DesktopTaskHandler) Result(c *gin.Context) {
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopTaskHandler) RetryPublish(c *gin.Context) {
|
||||
desktopID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40084, "invalid_desktop_task_id", "task id must be a uuid"))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.publishSvc.RetryByDesktopTask(c.Request.Context(), MustDesktopClient(c.Request.Context()), desktopID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *DesktopTaskHandler) Cancel(c *gin.Context) {
|
||||
desktopID, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
|
||||
@@ -15,7 +15,7 @@ type PublishJobHandler struct {
|
||||
|
||||
func NewPublishJobHandler(a *bootstrap.App) *PublishJobHandler {
|
||||
return &PublishJobHandler{
|
||||
svc: app.NewPublishJobService(a.DB, a.RabbitMQ, a.Logger),
|
||||
svc: app.NewPublishJobService(a.DB, a.RabbitMQ, a.Redis, a.Logger).WithCache(a.Cache),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,27 +40,33 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
desktopAuth.Use(DesktopClientMiddleware(repository.NewDesktopClientRepository(app.DB)))
|
||||
desktopAuth.POST("/clients/rotate", desktopClientHandler.Rotate)
|
||||
desktopAuth.POST("/clients/heartbeat", desktopClientHandler.Heartbeat)
|
||||
desktopAuth.POST("/clients/offline", desktopClientHandler.Offline)
|
||||
desktopAuth.POST("/clients/revoke", desktopClientHandler.Revoke)
|
||||
desktopAuth.GET("/events", desktopEventsHandler.Stream)
|
||||
desktopAuth.GET("/accounts", desktopAccountHandler.List)
|
||||
desktopAuth.GET("/content/articles/:id", desktopContentHandler.Article)
|
||||
desktopAuth.GET("/publish-tasks", desktopTaskHandler.ListPublish)
|
||||
desktopAuth.POST("/accounts", desktopAccountHandler.Upsert)
|
||||
desktopAuth.PATCH("/accounts/:id", desktopAccountHandler.Patch)
|
||||
desktopAuth.DELETE("/accounts/:id", desktopAccountHandler.Delete)
|
||||
desktopAuth.POST("/tasks/lease", desktopTaskHandler.Lease)
|
||||
desktopAuth.POST("/tasks/:id/lease", desktopTaskHandler.Lease)
|
||||
desktopAuth.POST("/tasks/:id/extend", desktopTaskHandler.Extend)
|
||||
desktopAuth.POST("/tasks/:id/park", desktopTaskHandler.Park)
|
||||
desktopAuth.POST("/tasks/:id/cancel", desktopTaskHandler.Cancel)
|
||||
desktopAuth.POST("/tasks/:id/result", desktopTaskHandler.Result)
|
||||
desktopAuth.POST("/publish-tasks/:id/retry", desktopTaskHandler.RetryPublish)
|
||||
|
||||
tenantProtected := protected.Group("/tenant")
|
||||
tenantProtected.Use(RequireActiveTenantSubscription(repository.NewTenantPlanRepository(app.DB)))
|
||||
tenantProtected.GET("/accounts", desktopAccountHandler.TenantList)
|
||||
tenantProtected.POST("/accounts/:id/request-delete", desktopAccountHandler.RequestDelete)
|
||||
tenantProtected.POST("/tasks/:id/reconcile", desktopTaskHandler.Reconcile)
|
||||
tenantProtected.POST("/tasks/:id/cancel", desktopTaskHandler.TenantCancel)
|
||||
tenantProtected.POST("/publish-jobs", publishJobHandler.Create)
|
||||
|
||||
media := tenantProtected.Group("/media")
|
||||
media.GET("/platforms", pluginHandler.ListPlatforms)
|
||||
|
||||
workspace := tenantProtected.Group("/workspace")
|
||||
wsHandler := NewWorkspaceHandler(app)
|
||||
workspace.GET("/overview", wsHandler.Overview)
|
||||
|
||||
@@ -26,10 +26,12 @@ func TestProtectedRoutes_RequireAuth(t *testing.T) {
|
||||
{http.MethodGet, "/api/auth/me"},
|
||||
{http.MethodPost, "/api/auth/logout"},
|
||||
{http.MethodPost, "/api/desktop/clients/register"},
|
||||
{http.MethodGet, "/api/tenant/accounts"},
|
||||
{http.MethodPost, "/api/tenant/accounts/:id/request-delete"},
|
||||
{http.MethodPost, "/api/tenant/tasks/:id/reconcile"},
|
||||
{http.MethodPost, "/api/tenant/tasks/:id/cancel"},
|
||||
{http.MethodPost, "/api/tenant/publish-jobs"},
|
||||
{http.MethodGet, "/api/tenant/media/platforms"},
|
||||
{http.MethodGet, "/api/tenant/workspace/overview"},
|
||||
{http.MethodGet, "/api/tenant/templates"},
|
||||
{http.MethodGet, "/api/tenant/articles"},
|
||||
@@ -75,6 +77,7 @@ func TestDesktopClientRoutes_ClientTokenAuth(t *testing.T) {
|
||||
}{
|
||||
{http.MethodGet, "/api/desktop/events"},
|
||||
{http.MethodGet, "/api/desktop/accounts"},
|
||||
{http.MethodPost, "/api/desktop/clients/offline"},
|
||||
{http.MethodPost, "/api/desktop/tasks/lease"},
|
||||
{http.MethodPost, "/api/desktop/tasks/:id/result"},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user