AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] UploadInlineMediaToLease fails request instead of falling back to inline media when GetAppFolder returns 401 unauthorized_client

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Summary

driveAuthorizationMissing explicitly matches 401 / code 16 / unauthorized_client for both GenerateAccessToken and GetAppFolder, so accounts without Google Drive authorization can still send media inline. However, UploadInlineMediaToLease only checks driveAuthorizationMissing on GenerateAccessToken's error (err), never on GetAppFolder's error (folderErr).

Trigger Path

  1. An account without Google Drive OAuth authorization receives a request with inline media.
  2. In UploadInlineMediaToLease:
    • s.client.appFolder(targetCtx, targetID) (GetAppFolder) runs in lookup.Go(...) and stores its error in folderErr.
    • s.client.GenerateAccessToken is either skipped (token != "" from uploader.beforeUpload) or succeeds (err == nil), while GetAppFolder returns HTTP 401, code 16, unauthorized_client.
  3. if err != nil { if driveAuthorizationMissing(err) { return rewritten, temporary, nil } ... } does not run because err == nil.
  4. uploadErr := folderErr falls through to if uploadErr != nil && (keepImages || !driveStorageQuotaExceeded(uploadErr)), cleaning up and failing the entire request instead of sending the inline media.

Root Cause Pointer

  • internal/aistudio/upload.go:
    • driveAuthorizationMissing(err) checks rpcError.Method == "GenerateAccessToken" || rpcError.Method == "GetAppFolder".
    • UploadInlineMediaToLease checks driveAuthorizationMissing(err) after lookup.Wait(), but ignores driveAuthorizationMissing(folderErr).

Suggested Fix

Check driveAuthorizationMissing(folderErr) right after lookup.Wait() (alongside driveAuthorizationMissing(err)), returning rewritten, temporary, nil with temporary.release = s.useInlineMedia(used) so inline media fallback behaves identically for both RPCs.

版本 / Version

v0.3.13

photobrand avatar Nov 21 '26 10:11 photobrand