| 1 | # Google Drive import, first slice |
| 2 | |
| 3 | 2026-11-01. Requested by Paul: connect Google Drive, choose Docs and Sheets, |
| 4 | import useful editable copies, and improve formatting fidelity incrementally. |
| 5 | Status: reviewed by Claude Fable 5.1 (claude-fable-5-1), 2026-11-01; |
| 6 | implementation permitted with B1–B5/R1–R5 corrections, incorporated below. |
| 7 | Corrected spec APPROVED by the same reviewer on 2026-11-01, separately from |
| 8 | the initial changes-required verdict. Implementation is authorized by the conversation. |
| 9 | |
| 10 | ## Outcome |
| 11 | |
| 12 | Each app has an Import from Google Drive action on its import page. A person |
| 13 | connects their Google account, chooses one file, and imports a new Oficina copy. |
| 14 | The original stays in Google Drive. This is a one-time copy, with no sync, |
| 15 | automatic sharing migration, or background access to Google. |
| 16 | |
| 17 | Google integration is optional, configured per deployment with a public OAuth |
| 18 | web client ID, Picker API key and Google Cloud project number. All three must |
| 19 | be set together; unset leaves normal app use and file imports available. |
| 20 | The setup guide records API enablement, exact authorized JavaScript origins, |
| 21 | API key restrictions, consent-screen/test-user setup and production publishing. |
| 22 | The project number must belong to the OAuth client's project and is passed to |
| 23 | Picker.setAppId; a mismatch can cause export to answer 404. drive.file is a |
| 24 | non-sensitive scope; follow the console's publishing and branding requirements, |
| 25 | and explicitly list test users while the OAuth app is in Testing. |
| 26 | No client secret or refresh token is required. The API key is public browser |
| 27 | configuration, restricted in Google Cloud, never described as a secret. |
| 28 | |
| 29 | ## Transport and ownership |
| 30 | |
| 31 | Use Google's supported GIS browser token model and Google Picker with only |
| 32 | drive.file scope and a view filtered to the app's Google-native file MIME type. |
| 33 | Google authorization is separate from Oficina sign-in and grants no Oficina |
| 34 | membership. Require the existing signed-in create permission on every import |
| 35 | endpoint and recheck membership at the write. Never derive membership from |
| 36 | the Google account address. |
| 37 | |
| 38 | The short-lived access token lives only in the import page's memory. Use it |
| 39 | to export the selected native Google file through Google's fixed Drive API |
| 40 | origin (Docs as DOCX, Sheets as XLSX). Validate selected IDs and MIME types; |
| 41 | never fetch a URL supplied by Picker, a document, or a request parameter. |
| 42 | Fetch with Authorization header, never a query token. Reject shortcut selections |
| 43 | even if the view was MIME-filtered. Bound exported response bytes at 10 MiB and |
| 44 | use AbortController timeouts. Google's own export-size refusal has a distinct |
| 45 | actionable message. Name the File from the selected name with path separators |
| 46 | removed and always append .docx/.xlsx. Transfer the resulting File through the |
| 47 | normal same-origin multipart upload form; server limits and validation remain |
| 48 | authoritative. No Google tokens go to Oficina, storage, logs or error text. |
| 49 | Cancellation, blocked popups, denied scopes, expired credentials, export |
| 50 | refusals/limits, networking failures and picker-load failures leave a usable |
| 51 | retry action and no new document. Do not expose Google's raw errors. |
| 52 | |
| 53 | Shared browser behavior and public configuration validation live in Estilo's |
| 54 | googleimport package, built for the Docs integration and then adopted by |
| 55 | Sheets. Render strings come from a twelve-locale catalog; app-specific copy |
| 56 | describes the import fidelity. JavaScript is required for Google Picker; |
| 57 | ordinary file upload remains the scriptless path. |
| 58 | |
| 59 | Load Google scripts only on the opted-in import page. Extend CSP only on |
| 60 | that page for the specific Google script, frame and connection origins needed; |
| 61 | retain form-action self, frame-ancestors none and base-uri self. Derive it from |
| 62 | the app's existing policy, set one CSP header, and extend the policy drift tests. |
| 63 | Preserve the existing app policy elsewhere. No wildcard origins or unsafe-eval. |
| 64 | The apps set no COOP header; do not add one, and test that it remains absent. Document |
| 65 | the disclosed Google connection on the page and in operator documentation. |
| 66 | |
| 67 | ## Docs conversion |
| 68 | |
| 69 | Add GET /import and POST /import to Docs' signed-in group, guarded by |
| 70 | requireMemberRequest. Add a dedicated import template, ordinary scriptless |
| 71 | multipart form, 10 MiB file cap plus multipart framing slack, .docx extension |
| 72 | check and ZIP validation. Use MultipartReader without disk spill. Docs' |
| 73 | app-specific copy uses its existing English catalog; the shared chooser has |
| 74 | twelve locales. |
| 75 | |
| 76 | Replace the existing paragraph/font reader with a bounded token walk that |
| 77 | preserves nested text in hyperlink, table/row/cell, insertion, sdt and smartTag |
| 78 | containers. Omit deletion text and report it; honour w:val on bold/italic toggles. |
| 79 | Map tabs and line breaks to spaces or paragraph breaks and report normalization. |
| 80 | Count XML depth explicitly; encoding/xml does not enforce it on our behalf. |
| 81 | Preserve paragraph text, headings, bold and italic, and supported fonts/sizes. |
| 82 | Unsupported links retain their visible text; the first slice does not invent |
| 83 | a clickable-link feature missing from the editor. Lists and table cells retain |
| 84 | their text in reading order as paragraphs. Report lost structure/formatting |
| 85 | and omitted non-text content, headers/footers, comments and tracked changes. |
| 86 | Reject malformed/empty-only unsupported documents with an actionable error. |
| 87 | Bound ZIP entries, total uncompressed data, XML depth and text/output size; |
| 88 | never extract to disk, fetch external relationships, or log source content. |
| 89 | |
| 90 | Produce a genuine Yjs document using a bounded builder in the existing Rust |
| 91 | yrs core (ABI version 5), not a second handwritten Yjs wire encoder. Go passes |
| 92 | only the closed set of supported paragraph/heading/text/mark operations; validate |
| 93 | the entire input before writing to a fresh handle. Replay the generated update |
| 94 | in a second handle and compare its rendered structure with the converter's |
| 95 | intended structure before saving. Test compatibility with the editor's own |
| 96 | y-prosemirror bridge; opening the import must not cause schema-cleanup edits. |
| 97 | This keeps ordinary file upload usable with JavaScript disabled. Creation |
| 98 | and content publication use one CreateImported transaction: document row, |
| 99 | sealed initial update and sealed report, with membership checked inside it, |
| 100 | creation-token idempotence and a distinct report contentAAD kind byte. Cancellation or conversion/write failure |
| 101 | must not publish an empty or partial document. Persist import report codes |
| 102 | and coordinates with the created document under existing encryption rules; |
| 103 | show the report on arrival, with a way to reopen it. No report may imply full |
| 104 | fidelity. Preserve the existing sharing default for new documents. |
| 105 | |
| 106 | ## Sheets conversion |
| 107 | |
| 108 | Reuse the existing XLSX job lifecycle and hidden-until-success sheet creation. |
| 109 | For this slice explicitly import only the first worksheet, because the current |
| 110 | UI has no tab switching (Sheets spec deferral). State this before import and |
| 111 | report how many worksheets were omitted. Preserve existing supported values |
| 112 | and formatting. Unsupported formulas must fall back to an available cached |
| 113 | value and be reported by coordinate; never silently turn a value into a broken |
| 114 | formula. Google's __xludf.DUMMYFUNCTION wrappers (even within IFERROR), array |
| 115 | formulas, qualified sheet references and external references are unsupported. |
| 116 | A bounded ZIP/XML scan of the first worksheet verifies actual cached <v> |
| 117 | presence, agreeing with excelize's formula cells: finite numeric n, boolean |
| 118 | exactly 0/1, or string str (empty allowed). Missing caches, cached errors and |
| 119 | unexpected cached types refuse the import. Known formulas remain formulas; |
| 120 | report differences from saved values, using a relative numeric tolerance. |
| 121 | |
| 122 | Preserve typed text, including strings beginning with '=' or looking like |
| 123 | numbers. Ambiguous strings, including empty strings and TRUE/FALSE/NaN/Inf, |
| 124 | become constant string expressions ="..." with doubled quotes through the |
| 125 | existing parser, reported by coordinate; refuse wrapped input over 8 KiB. |
| 126 | No new apostrophe semantics or input codec; existing records keep their meaning. |
| 127 | If no trustworthy cached value exists, flag the affected coordinate |
| 128 | and refuse that import rather than manufacture a value. Cross-sheet references |
| 129 | are unsupported in a single-worksheet import, even if the evaluator parses them. |
| 130 | Any additional supported-formula fidelity cannot be claimed without fixtures. |
| 131 | |
| 132 | Persist a report attached to the sheet using the sealed-content conventions; |
| 133 | show it at completion and allow reopening. Report unsupported charts, images, |
| 134 | merges, comments, validation and layout where detectable, with an always-visible |
| 135 | statement of the supported subset. Data and filenames never enter logs. |
| 136 | |
| 137 | ## Proof and release |
| 138 | |
| 139 | Tests cover actual converted text/marks/cell values and omission reports, |
| 140 | ZIP/resource limits, malicious link targets, unknown formulas and missing |
| 141 | caches, permission/CSRF refusal, failed imports not appearing, and sealed-at-rest |
| 142 | storage including SQLite WAL. Browser tests exercise picker/token/export success |
| 143 | and failure with controlled Google responses; run through production headers. |
| 144 | Check keyboard use, cancellation, retry, 320px reflow and scriptless upload. |
| 145 | |
| 146 | Repository review rules apply to this spec and to each final branch. Work in |
| 147 | isolated worktrees and push reviewable commits. Complete local/CI checks before |
| 148 | shipping; real Google OAuth verification additionally needs configured Google |
| 149 | Cloud credentials and a person exercising consent on an authorized origin. |
| 150 | Never call a mocked Google test proof of live consent. Until real verification, |
| 151 | keep Google configuration off on production and report the remaining setup. |
| 152 | |
| 153 | ## Later fidelity, with triggers |
| 154 | |
| 155 | - More Docx structure and clickable links: editor support and a representative |
| 156 | failing fixture exist; promote each fixture into the regression corpus. |
| 157 | - Additional worksheets: the Sheets UI can create, name and switch tabs. |
| 158 | - Multiple selected files: single-file imports are reliable and batch progress, |
| 159 | cancellation and per-file retry have a defined lifecycle. |
| 160 | - Google comments, permissions, history and ongoing sync: separately requested |
| 161 | product work with explicit ownership semantics. |
| 162 | |
| 163 | ## References |
| 164 | |
| 165 | - https://developers.google.com/identity/oauth2/web/guides/use-token-model |
| 166 | - https://developers.google.com/workspace/drive/picker/guides/overview |
| 167 | - https://developers.google.com/workspace/drive/api/guides/ref-export-formats |
| 168 | - https://developers.google.com/workspace/drive/api/reference/rest/v3/files/export |
| 169 | - Docs design section 11.2; Sheets design sections 11 and 14. |
| 170 | |