fix: resolve auth cascade errors and optimize sync performance - #2
Open
zwolenik wants to merge 4 commits into
Open
fix: resolve auth cascade errors and optimize sync performance#2zwolenik wants to merge 4 commits into
zwolenik wants to merge 4 commits into
Conversation
- Make ensureValidToken() public with auto-login fallback Previously, if isAuthenticated was false (e.g. after restart), every API call would fail with 'Authentication required', generating a cascade of errors - one per file in the vault. - Add auth check at start of performSync() Ensures authentication is valid before beginning any sync operations. If auth fails, shows a notice and aborts cleanly instead of generating N errors. - Batch needsSync() checks into single API call (N+1 fix) Previously, getFileStatsV2() was called individually for each file, generating hundreds of API requests. Now all file paths are sent in a single batch request, with results mapped locally. - Add proactive token refresh timer in main plugin Checks token expiry every 5 minutes and refreshes proactively when token expires within 10 minutes, preventing auth failures during auto-sync cycles. Fixes LinkLeong#1 (indirectly - improves sync reliability)
- Simplify getFilesToSync() to exclusion-only filter (no API calls) The mediainfo API does not return modification timestamps, making per-file needsSync() checks wasteful. Time comparison is done properly in compareFiles() using the file listing API. - Fix needsSync() to handle mediainfo response format correctly Updated to match actual API response structure and provide clear documentation of its limitations. - Add finally blocks to performAutoSync and performManualSync Guarantees syncInProgress is always reset, preventing the flag from getting stuck after errors in Notice/logError. - Sync syncInProgress via notifyStatusUpdate callback Ensures main.ts and sync-manager.ts stay in sync on the flag. - Skip directories in remote-only download operations getAllFilesRecursive returns both files and directories. The compareFiles method was creating download operations for remote directories that don't exist locally, causing 400 errors on the download API endpoint.
Security: - Remove plaintext password from login request logs - Gate window.ozsyncPlugin behind debugMode setting - Remove duplicate Notice popup from log() method (showErrorNotice is the single source for user-facing error popups) Binary file handling: - Change downloadFile to use responseType arraybuffer instead of text This prevents silent corruption of images, PDFs, and other binary files that were previously decoded as UTF-8 text. - Expand text extension detection: md, txt, csv, json, yaml, html, css, js, canvas, xml, ts, tsx, jsx, py, and more are now read as text on both upload and download. All other extensions use binary read/write paths. - Fix cloud-browser download and preview to handle ArrayBuffer data
Text files decode correctly after parsing JSON envelope. Binary files have documented limitation due to JSON UTF-8 serialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After Obsidian restart or token expiry, every sync operation generates a cascade of "Authentication required" errors — one per file in the vault. With hundreds of files, this produces dozens of red error notices.
Root cause:
performSync()doesn't verify authentication before starting, andensureValidToken()returnsfalse(instead of attempting login) whenisAuthenticatedis false.Additionally,
needsSync()callsgetFileStatsV2()individually for each file (N+1 problem), generating hundreds of API requests per sync.Changes
1.
ensureValidToken()— public with auto-login fallbackprivatetopublicsoSyncManagercan call itfalsewhen not authenticated, attempts auto-login2. Auth check at start of
performSync()ensureValidToken()before any sync operations3. Batch
needsSync()(N+1 fix)getFileStatsV2()batch request4. Proactive token refresh timer
Testing
Verified locally:
Related
Partially addresses sync reliability concerns mentioned in issue discussions.