fix: comprehensive Sora & GDrive code review fixes

P0 fixes:
- StorageType: UploadFromURL now returns actual storageType, fixing
  GDrive tasks being incorrectly recorded as "s3"
- Concurrency: selectAccount returns ReleaseFunc to caller, fixing
  premature slot release before task creation
- Race condition: applyRecoveredToken uses copy-on-write for
  account.Credentials map to prevent concurrent write panic
- GetCameoStatus: use direct HTTP call to populate missing fields
  (StatusMessage, InstructionSetHint, InstructionSet)
- Frontend: progress bar uses reactive now.value instead of
  non-reactive Date.now()

P1 fixes:
- EditImage: pass req.Image through to CreateImageRequest
- ListPending: add LIMIT 200 to prevent unbounded queries
- Worker encapsulation: add ListPendingTasks/UpdateTask proxy methods
  to SoraTaskService, worker no longer accesses repo directly
- Frontend polling: add retry counter (3 attempts) before giving up

P2-P3 fixes:
- QuotaBar: handle both quota_source and source field names
- i18n: replace hardcoded Chinese labels in SoraPromptBar and
  example prompts in SoraGeneratePage with i18n keys
- Fix regenrate → regenerate i18n typo
- SoraMediaPreview: skip Escape handler when not visible
- SoraGeneratePage: void handleGenerate promise in handleRetry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erioandClaude Opus 4.6 committed 2026-03-08 01:02:55 +08:00
1 parent f9695ca83f
commit 597c19e80b
18 files changed
+168 -81

No files matched your search

@@ -43,10 +43,11 @@ func NewSoraVideosHandler(
}
func (h *SoraVideosHandler) CreateVideo(c *gin.Context) {
apiKey, account, ok := h.selectAccount(c, "")
apiKey, account, release, ok := h.selectAccount(c, "")
if !ok {
return
}
defer release()
body, err := readBody(c)
if err != nil {
@@ -224,10 +225,11 @@ func (h *SoraVideosHandler) resolveContentURL(c *gin.Context, task *service.Sora
}
func (h *SoraVideosHandler) CreateImage(c *gin.Context) {
apiKey, account, ok := h.selectAccount(c, "")
apiKey, account, release, ok := h.selectAccount(c, "")
if !ok {
return
}
defer release()
body, err := readBody(c)
if err != nil {
@@ -257,10 +259,11 @@ func (h *SoraVideosHandler) CreateImage(c *gin.Context) {
}
func (h *SoraVideosHandler) EditImage(c *gin.Context) {
apiKey, account, ok := h.selectAccount(c, "")
apiKey, account, release, ok := h.selectAccount(c, "")
if !ok {
return
}
defer release()
body, err := readBody(c)
if err != nil {
@@ -287,6 +290,7 @@ func (h *SoraVideosHandler) EditImage(c *gin.Context) {
imageReq := &service.CreateImageRequest{
Model: req.Model,
Prompt: req.Prompt,
Image: req.Image,
Size: req.Size,
ResponseFormat: req.ResponseFormat,
N: 1,
@@ -312,10 +316,10 @@ func (h *SoraVideosHandler) getAPIKey(c *gin.Context) (*service.APIKey, bool) {
return apiKey, true
}
func (h *SoraVideosHandler) selectAccount(c *gin.Context, model string) (*service.APIKey, *service.Account, bool) {
func (h *SoraVideosHandler) selectAccount(c *gin.Context, model string) (*service.APIKey, *service.Account, func(), bool) {
apiKey, ok := h.getAPIKey(c)
if !ok {
return nil, nil, false
return nil, nil, nil, false
}
selection, err := h.gatewayService.SelectAccountWithLoadAwareness(
@@ -323,12 +327,14 @@ func (h *SoraVideosHandler) selectAccount(c *gin.Context, model string) (*servic
)
if err != nil {
soraErrorResponse(c, http.StatusServiceUnavailable, "server_error", "No available accounts")
return nil, nil, false
return nil, nil, nil, false
}
releaseFunc := func() {}
if selection.ReleaseFunc != nil {
defer selection.ReleaseFunc()
releaseFunc = selection.ReleaseFunc
}
return apiKey, selection.Account, true
return apiKey, selection.Account, releaseFunc, true
}
func (h *SoraVideosHandler) selectAccountByID(c *gin.Context, accountID int64) (*service.Account, error) {