Skip to main content

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.

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.

Module overview

The backup feature is split across three JavaScript modules in editor/js/:
ModuleResponsibility
drive-config.jsOAuth client ID, Drive API scope (drive.file), folder name, API base URLs
drive-auth.jsGoogle Identity Services token client; caches short-lived access tokens in IndexedDB for up to 24 hours
drive-sync.jsFolder 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:
https://www.googleapis.com/auth/drive.file
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.
After consent, the app receives a short-lived access token. That token (and its expiry time) is cached in a second IndexedDB database named 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:
Bihar Police Notebook Backup — do not delete/
  ├── {uuid-1}.json
  ├── {uuid-2}.json
  └── {uuid-3}.json
Each document is serialised as a single JSON file named after its uuid:
{
  "uuid": "01934a2b-...",
  "type": "diary",
  "filename": "2025-06-15",
  "content": { "header": { "fir_number": "12/2025", "case_diary_no": "7" }, "pages": [] },
  "created_at": "2025-06-15T08:30:00.000Z",
  "updated_at": "2025-06-15T14:22:11.000Z",
  "deleted": false
}
Files are matched to local documents using 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:
1

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.
2

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.
3

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.
4

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.
5

Update badges and status

drive-sync.js fires statusListeners with the new sync state (idle, syncing, or error). The History sidebar refreshes its per-document badges (synced ✓, pending ↑, error ✗) and the overall backup icon.

Handling a deleted Drive folder

Do not delete or rename the “Bihar Police Notebook Backup — do not delete” folder from Drive while documents may need syncing. If you accidentally delete the folder, the next sync will recreate it and re-upload all local documents — but any documents that existed only on Drive and not locally will be lost.
If the folder is found to be missing at the start of a sync, the app automatically:
  1. Clears all driveFileId values on every local document.
  2. Creates a fresh folder with the same canonical name.
  3. 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 in bp-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.
Session lifecycle in bp-writing-tool-auth IndexedDB:
  ┌──────────────────────────────────┐
  │ accessToken  (valid ~1 hour)     │  ← refreshed silently from GIS
  │ tokenExpiresAt  (epoch ms)       │
  │ retainedUntil   (epoch ms +24h)  │  ← session discarded after this
  │ email           (display only)   │
  └──────────────────────────────────┘
If you see an “Not connected to Google Drive” error mid-sync, your 24-hour session has expired. Click Connect in the backup menu to reauthenticate and continue.

Disconnecting

Clicking Disconnect in the backup menu calls disconnectDrive() in drive-auth.js, which:
  1. Calls google.accounts.oauth2.revoke() to invalidate the token on Google’s servers.
  2. Clears the in-memory token, the bp-writing-tool-auth IndexedDB session, and the bpnt.drive.connected / bpnt.drive.email preferences.
Your Drive folder and all uploaded files remain intact. You can reconnect at any time and perform a Sync All to restore documents to a new browser or device.

Build docs developers (and LLMs) love