HH-912: simplify social account creation (#36)

This commit is contained in:
2026-09-02 02:03:36 +08:00
parent 3729ce910f
commit f054d04321
23 changed files with 885 additions and 215 deletions
+24 -17
View File
@@ -6,6 +6,7 @@ import (
"errors"
"io"
"strconv"
"strings"
"time"
"git.ipao.vip/rogee/creator-hub/internal/hub"
@@ -14,15 +15,11 @@ import (
)
type accountRequest struct {
ID string `json:"id"`
Platform string `json:"platform"`
PlatformAccountKey string `json:"platform_account_key"`
AuthorizationKind string `json:"authorization_kind"`
CredentialReference struct {
ID string `json:"id"`
Provider string `json:"provider"`
Key string `json:"key"`
} `json:"credential_reference"`
Name string `json:"name"`
Platform string `json:"platform"`
PlatformAccountKey string `json:"platform_account_key"`
Tags []string `json:"tags"`
Cookies string `json:"cookies"`
}
type draftRequest struct {
@@ -44,23 +41,33 @@ type taskVerificationRequest struct {
Result string `json:"result"`
}
func registerPhaseA(app *fiber.App, store *phasea.Store, runtimeStore runtimeStopStore) {
func registerPhaseA(app *fiber.App, store *phasea.Store, runtimeStore runtimeStopStore, credentials phasea.CredentialBridge) {
app.Post("/api/phase-a/accounts", func(c fiber.Ctx) error {
var input accountRequest
if err := decodePhaseA(c, &input); err != nil {
return phaseAError(c, err)
}
accountID := input.ID
if accountID == "" {
accountID = phasea.NewAccountID()
tags := input.Tags
if tags == nil {
tags = []string{}
}
for index := range tags {
tags[index] = strings.TrimSpace(tags[index])
}
accountID := phasea.NewAccountID()
account := phasea.Account{
ID: accountID, Platform: input.Platform, PlatformAccountKey: input.PlatformAccountKey,
AuthorizationKind: input.AuthorizationKind, CredentialKey: input.CredentialReference.Key,
CredentialReference: phasea.CredentialReference{ID: input.CredentialReference.ID, Provider: input.CredentialReference.Provider},
ID: accountID, Name: strings.TrimSpace(input.Name), Platform: strings.TrimSpace(input.Platform),
PlatformAccountKey: strings.TrimSpace(input.PlatformAccountKey), Tags: tags, Cookies: strings.TrimSpace(input.Cookies),
CredentialReference: phasea.CredentialReference{ID: accountID + "-cookies", Provider: "os_keyring"},
CredentialKey: "creatorhub/" + accountID + "/cookies",
AuthorizationStatus: "authorized", RuntimeStatus: "paused", Version: 1,
}
if err := store.CreateAccount(c.Context(), account); err != nil {
if err := store.CreateAccount(c.Context(), account, credentials); err != nil {
if errors.Is(err, phasea.ErrAccountCreationUnknown) {
return c.Status(fiber.StatusServiceUnavailable).JSON(map[string]string{
"error": "account creation result is unknown", "reason_code": "account_creation_result_unknown", "account_id": accountID,
})
}
return phaseAError(c, err)
}
return c.Status(fiber.StatusCreated).JSON(account)