oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

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