mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 23:07:18 +00:00
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:
1 parent
f9695ca83f
commit
597c19e80b
18 files changed
+168
-81
No files matched your search
@@ -212,29 +212,29 @@ func (s *SoraS3Storage) GenerateObjectKey(prefix string, userID int64, ext strin
|
||||
}
|
||||
|
||||
// UploadFromURL 从上游 URL 下载并流式上传到 S3。
|
||||
// 返回 S3 object key。
|
||||
func (s *SoraS3Storage) UploadFromURL(ctx context.Context, userID int64, sourceURL string) (string, int64, error) {
|
||||
// 返回 S3 object key、文件大小、存储类型。
|
||||
func (s *SoraS3Storage) UploadFromURL(ctx context.Context, userID int64, sourceURL string) (string, int64, string, error) {
|
||||
client, cfg, err := s.getClient(ctx)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
return "", 0, "", err
|
||||
}
|
||||
|
||||
// 下载源文件
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, sourceURL, nil)
|
||||
if err != nil {
|
||||
return "", 0, fmt.Errorf("create download request: %w", err)
|
||||
return "", 0, "", fmt.Errorf("create download request: %w", err)
|
||||
}
|
||||
httpClient := &http.Client{Timeout: 5 * time.Minute}
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
return "", 0, fmt.Errorf("download from upstream: %w", err)
|
||||
return "", 0, "", fmt.Errorf("download from upstream: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", 0, &UpstreamDownloadError{StatusCode: resp.StatusCode}
|
||||
return "", 0, "", &UpstreamDownloadError{StatusCode: resp.StatusCode}
|
||||
}
|
||||
|
||||
// 推断文件扩展名
|
||||
@@ -275,14 +275,14 @@ func (s *SoraS3Storage) UploadFromURL(ctx context.Context, userID int64, sourceU
|
||||
_ = writer.CloseWithError(copyErr)
|
||||
uploadErr := <-uploadErrCh
|
||||
if copyErr != nil {
|
||||
return "", 0, fmt.Errorf("stream upload copy failed: %w", copyErr)
|
||||
return "", 0, "", fmt.Errorf("stream upload copy failed: %w", copyErr)
|
||||
}
|
||||
if uploadErr != nil {
|
||||
return "", 0, fmt.Errorf("s3 upload: %w", uploadErr)
|
||||
return "", 0, "", fmt.Errorf("s3 upload: %w", uploadErr)
|
||||
}
|
||||
|
||||
logger.LegacyPrintf("service.sora_s3", "[SoraS3] 上传完成 key=%s size=%d", objectKey, written)
|
||||
return objectKey, written, nil
|
||||
return objectKey, written, SoraStorageTypeS3, nil
|
||||
}
|
||||
|
||||
func buildSoraS3Client(ctx context.Context, cfg *SoraS3Settings) (*s3.Client, string, error) {
|
||||
|
||||
Reference in new issue
Block a user