oficina / estilo Public

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

Plain git — no account needed to clone.

Download

Download this file

Google Drive import, first slice

2026-11-01. Requested by Paul: connect Google Drive, choose Docs and Sheets, import useful editable copies, and improve formatting fidelity incrementally. Status: reviewed by Claude Fable 5.1 (claude-fable-5-1), 2026-11-01; implementation permitted with B1–B5/R1–R5 corrections, incorporated below. Corrected spec APPROVED by the same reviewer on 2026-11-01, separately from the initial changes-required verdict. Implementation is authorized by the conversation.

Outcome

Each app has an Import from Google Drive action on its import page. A person connects their Google account, chooses one file, and imports a new Oficina copy. The original stays in Google Drive. This is a one-time copy, with no sync, automatic sharing migration, or background access to Google.

Google integration is optional, configured per deployment with a public OAuth web client ID, Picker API key and Google Cloud project number. All three must be set together; unset leaves normal app use and file imports available. The setup guide records API enablement, exact authorized JavaScript origins, API key restrictions, consent-screen/test-user setup and production publishing. The project number must belong to the OAuth client's project and is passed to Picker.setAppId; a mismatch can cause export to answer 404. drive.file is a non-sensitive scope; follow the console's publishing and branding requirements, and explicitly list test users while the OAuth app is in Testing. No client secret or refresh token is required. The API key is public browser configuration, restricted in Google Cloud, never described as a secret.

Transport and ownership

Use Google's supported GIS browser token model and Google Picker with only drive.file scope and a view filtered to the app's Google-native file MIME type. Google authorization is separate from Oficina sign-in and grants no Oficina membership. Require the existing signed-in create permission on every import endpoint and recheck membership at the write. Never derive membership from the Google account address.

The short-lived access token lives only in the import page's memory. Use it to export the selected native Google file through Google's fixed Drive API origin (Docs as DOCX, Sheets as XLSX). Validate selected IDs and MIME types; never fetch a URL supplied by Picker, a document, or a request parameter. Fetch with Authorization header, never a query token. Reject shortcut selections even if the view was MIME-filtered. Bound exported response bytes at 10 MiB and use AbortController timeouts. Google's own export-size refusal has a distinct actionable message. Name the File from the selected name with path separators removed and always append .docx/.xlsx. Transfer the resulting File through the normal same-origin multipart upload form; server limits and validation remain authoritative. No Google tokens go to Oficina, storage, logs or error text. Cancellation, blocked popups, denied scopes, expired credentials, export refusals/limits, networking failures and picker-load failures leave a usable retry action and no new document. Do not expose Google's raw errors.

Shared browser behavior and public configuration validation live in Estilo's googleimport package, built for the Docs integration and then adopted by Sheets. Render strings come from a twelve-locale catalog; app-specific copy describes the import fidelity. JavaScript is required for Google Picker; ordinary file upload remains the scriptless path.

Load Google scripts only on the opted-in import page. Extend CSP only on that page for the specific Google script, frame and connection origins needed; retain form-action self, frame-ancestors none and base-uri self. Derive it from the app's existing policy, set one CSP header, and extend the policy drift tests. Preserve the existing app policy elsewhere. No wildcard origins or unsafe-eval. The apps set no COOP header; do not add one, and test that it remains absent. Document the disclosed Google connection on the page and in operator documentation.

Docs conversion

Add GET /import and POST /import to Docs' signed-in group, guarded by requireMemberRequest. Add a dedicated import template, ordinary scriptless multipart form, 10 MiB file cap plus multipart framing slack, .docx extension check and ZIP validation. Use MultipartReader without disk spill. Docs' app-specific copy uses its existing English catalog; the shared chooser has twelve locales.

Replace the existing paragraph/font reader with a bounded token walk that preserves nested text in hyperlink, table/row/cell, insertion, sdt and smartTag containers. Omit deletion text and report it; honour w:val on bold/italic toggles. Map tabs and line breaks to spaces or paragraph breaks and report normalization. Count XML depth explicitly; encoding/xml does not enforce it on our behalf. Preserve paragraph text, headings, bold and italic, and supported fonts/sizes. Unsupported links retain their visible text; the first slice does not invent a clickable-link feature missing from the editor. Lists and table cells retain their text in reading order as paragraphs. Report lost structure/formatting and omitted non-text content, headers/footers, comments and tracked changes. Reject malformed/empty-only unsupported documents with an actionable error. Bound ZIP entries, total uncompressed data, XML depth and text/output size; never extract to disk, fetch external relationships, or log source content.

Produce a genuine Yjs document using a bounded builder in the existing Rust yrs core (ABI version 5), not a second handwritten Yjs wire encoder. Go passes only the closed set of supported paragraph/heading/text/mark operations; validate the entire input before writing to a fresh handle. Replay the generated update in a second handle and compare its rendered structure with the converter's intended structure before saving. Test compatibility with the editor's own y-prosemirror bridge; opening the import must not cause schema-cleanup edits. This keeps ordinary file upload usable with JavaScript disabled. Creation and content publication use one CreateImported transaction: document row, sealed initial update and sealed report, with membership checked inside it, creation-token idempotence and a distinct report contentAAD kind byte. Cancellation or conversion/write failure must not publish an empty or partial document. Persist import report codes and coordinates with the created document under existing encryption rules; show the report on arrival, with a way to reopen it. No report may imply full fidelity. Preserve the existing sharing default for new documents.

Sheets conversion

Reuse the existing XLSX job lifecycle and hidden-until-success sheet creation. For this slice explicitly import only the first worksheet, because the current UI has no tab switching (Sheets spec deferral). State this before import and report how many worksheets were omitted. Preserve existing supported values and formatting. Unsupported formulas must fall back to an available cached value and be reported by coordinate; never silently turn a value into a broken formula. Google's __xludf.DUMMYFUNCTION wrappers (even within IFERROR), array formulas, qualified sheet references and external references are unsupported. A bounded ZIP/XML scan of the first worksheet verifies actual cached <v> presence, agreeing with excelize's formula cells: finite numeric n, boolean exactly 0/1, or string str (empty allowed). Missing caches, cached errors and unexpected cached types refuse the import. Known formulas remain formulas; report differences from saved values, using a relative numeric tolerance.

Preserve typed text, including strings beginning with '=' or looking like numbers. Ambiguous strings, including empty strings and TRUE/FALSE/NaN/Inf, become constant string expressions ="..." with doubled quotes through the existing parser, reported by coordinate; refuse wrapped input over 8 KiB. No new apostrophe semantics or input codec; existing records keep their meaning. If no trustworthy cached value exists, flag the affected coordinate and refuse that import rather than manufacture a value. Cross-sheet references are unsupported in a single-worksheet import, even if the evaluator parses them. Any additional supported-formula fidelity cannot be claimed without fixtures.

Persist a report attached to the sheet using the sealed-content conventions; show it at completion and allow reopening. Report unsupported charts, images, merges, comments, validation and layout where detectable, with an always-visible statement of the supported subset. Data and filenames never enter logs.

Proof and release

Tests cover actual converted text/marks/cell values and omission reports, ZIP/resource limits, malicious link targets, unknown formulas and missing caches, permission/CSRF refusal, failed imports not appearing, and sealed-at-rest storage including SQLite WAL. Browser tests exercise picker/token/export success and failure with controlled Google responses; run through production headers. Check keyboard use, cancellation, retry, 320px reflow and scriptless upload.

Repository review rules apply to this spec and to each final branch. Work in isolated worktrees and push reviewable commits. Complete local/CI checks before shipping; real Google OAuth verification additionally needs configured Google Cloud credentials and a person exercising consent on an authorized origin. Never call a mocked Google test proof of live consent. Until real verification, keep Google configuration off on production and report the remaining setup.

Later fidelity, with triggers

  • More Docx structure and clickable links: editor support and a representative failing fixture exist; promote each fixture into the regression corpus.
  • Additional worksheets: the Sheets UI can create, name and switch tabs.
  • Multiple selected files: single-file imports are reliable and batch progress, cancellation and per-file retry have a defined lifecycle.
  • Google comments, permissions, history and ongoing sync: separately requested product work with explicit ownership semantics.

References

  • https://developers.google.com/identity/oauth2/web/guides/use-token-model
  • https://developers.google.com/workspace/drive/picker/guides/overview
  • https://developers.google.com/workspace/drive/api/guides/ref-export-formats
  • https://developers.google.com/workspace/drive/api/reference/rest/v3/files/export
  • Docs design section 11.2; Sheets design sections 11 and 14.