Bihar Police Notebook can optionally copy your letters and FIR case diaries to a folder in your personal Google Drive. This feature is entirely opt-in and manual — nothing leaves your device until you explicitly connect a Google account and trigger a sync from the History sidebar. Once enabled, each document is stored as a single JSON file in a dedicated Drive folder that only this app can access.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/arverma/Bihar-Police-Notebook/llms.txt
Use this file to discover all available pages before exploring further.
Module overview
The backup feature is split across three JavaScript modules ineditor/js/:
| Module | Responsibility |
|---|---|
drive-config.js | OAuth client ID, Drive API scope (drive.file), folder name, API base URLs |
drive-auth.js | Google Identity Services token client; caches short-lived access tokens in IndexedDB for up to 24 hours |
drive-sync.js | Folder management, per-document upload/download logic, push/pull/merge orchestration |
Connecting Google Drive
To enable backup, open the History sidebar and click the backup icon. The app launches a Google OAuth flow via Google Identity Services (GIS). You will be asked to grant the following scope:The
drive.file scope limits the app to files and folders it creates. It cannot read your existing Drive files, photos, or any documents created by other apps.bp-writing-tool-auth for up to 24 hours so you are not prompted to log in again on every page refresh. The browser key bpnt.drive.connected in localStorage tracks whether an account is currently linked.
Backup menu actions
Three actions are available in the History sidebar backup menu:Sync All
Pull every file from the Drive folder into local IndexedDB (newer remote content wins), then push all dirty or new local documents to Drive. Use this when you want a full two-way merge, for example after using the app on another device.
Sync New
Push only dirty or new local documents to Drive. No pull phase. Use this for a quick upload of recent work without downloading any changes from Drive.
Disconnect
Revokes the access token in this browser and clears all cached auth data. Does not delete the Drive folder or any files already uploaded. You can reconnect later and sync again.
Drive folder and file layout
When a sync runs for the first time, the app creates a folder in your My Drive root:uuid:
appProperties.uuid — a metadata field embedded in the Drive file, not the filename — so renaming documents locally does not create duplicates on Drive.
Full sync sequence
The following steps describe what happens during a Sync All operation, from user click to updated UI badges:ensureAccessToken
drive-auth.js checks the in-memory token. If valid, it is reused. If expired or absent, the module attempts a silent refresh via GIS. Only if the silent refresh fails will an interactive Google login popup appear.ensureFolder
drive-sync.js reads the cached folder ID from localStorage (bpnt.drive.folderId). It verifies the folder still exists on Drive with a quick metadata fetch. If the folder is missing or was trashed, the cached ID is cleared, all local driveFileId references are nulled out (so every document will be treated as new for the next push), and a new folder is created with the canonical name.pullAndMerge (Sync All only)
The app lists every
.json file inside the Drive folder. For each file, it downloads the JSON payload and compares updated_at timestamps against the local copy. If the remote version is newer — or no local copy exists — the document is upserted into IndexedDB via upsertFromRemote. Documents that carry "deleted": true in their payload are soft-deleted locally.pushPending
The app collects every local document where
needsBackup() returns true: documents that have never been synced, documents whose updated_at is later than syncedAt, and soft-deleted tombstones that haven’t been pushed yet. Each is uploaded as a JSON file using the Drive multipart upload API. On success, markSynced stamps driveFileId and syncedAt on the local row. Tombstones are hard-deleted from IndexedDB after a successful push.Handling a deleted Drive folder
If the folder is found to be missing at the start of a sync, the app automatically:- Clears all
driveFileIdvalues on every local document. - Creates a fresh folder with the same canonical name.
- Uploads all local documents as if they were new (no data is lost from the local side).
Token lifetime and re-authentication
Access tokens issued by Google expire after approximately one hour. The cached session inbp-writing-tool-auth is retained for up to 24 hours so the app can silently request a fresh token using the stored session metadata without opening a popup. After 24 hours the session record is discarded and the next sync will prompt for Google login again.
Disconnecting
Clicking Disconnect in the backup menu callsdisconnectDrive() in drive-auth.js, which:
- Calls
google.accounts.oauth2.revoke()to invalidate the token on Google’s servers. - Clears the in-memory token, the
bp-writing-tool-authIndexedDB session, and thebpnt.drive.connected/bpnt.drive.emailpreferences.