Files
google-drive-content-adapter/src
Peter.Morton 81dd86c09b Simplify proxy.js: Moderate cleanup for better maintainability
Section 1: Authentication (135 → 62 lines, 54% reduction)
- Inlined createServiceAccountJWT into initializeServiceAccount
- Inlined getAccessToken axios call (simple wrapper removed)
- Removed clearAuthCache (3-line test helper)
- Added constants: TOKEN_EXPIRY_MS, TOKEN_BUFFER_MS (no magic numbers)
- Simplified error handling (removed redundant try-catch)
- Condensed JWT signing to single jwt.sign() call
- Optional chaining: settings?.serviceAccount?.client_email

Section 2: Request Queue (85 → 39 lines, 54% reduction)
- Removed verbose debug logging (enqueue, _processNext)
- Simplified enqueue: inline if statement
- Simplified _processNext: direct await in try block
- Removed redundant JSDoc comments
- Kept essential structure and error handling

Section 3: Drive API Client (109 → 52 lines, 52% reduction)
- Removed debug logging (query start, each page)
- Removed verbose error logging (already bubbles with stack)
- Removed unnecessary try-catch (let errors bubble naturally)
- Moved accessToken outside loop for clarity
- Removed DocumentCountExceededError re-throw check (unnecessary)
- Inline params.append when pageToken exists

Section 4: Request Handling (124 → 88 lines, 29% reduction)
- Removed redundant JSDoc @param tags
- Simplified handleSitemapRequest comments
- Removed 'successfully' from log messages (redundant)
- Removed duplicate comment about empty body
- Inline async wrapper in requestQueue.enqueue
- Condensed route not found logic

Benefits:
 40% fewer lines to read and maintain
 Named constants instead of magic numbers
 Cleaner error handling (natural bubbling)
 Less noise from debug logging (info/error only)
 Same functionality, clearer code
 Easier to understand core business logic

Testing:
✓ Syntax validated
✓ Server starts successfully
✓ Request handling works
✓ Route parsing functional
✓ All core logic preserved

Philosophy:
- Remove verbosity that obscures intent
- Inline simple wrappers (1-2 line functions)
- Let errors bubble naturally (fewer try-catch)
- Use constants for magic numbers
- Keep essential structure and logic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-07 11:35:23 -06:00
..
2026-03-06 23:34:00 -06:00