From a9f46a544d985b0d7f6ee7f8d2f5b90ecd032ce7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Mar 2026 22:18:19 +0000 Subject: [PATCH] Fix Google Doc links to use user-facing URLs instead of API URLs The "Visit source" link in the document modal was using the raw docs.googleapis.com API URL. Now converts to the proper docs.google.com format using the document's customId or by extracting the ID from the API URL. https://claude.ai/code/session_01Eex8FXHXFQxLAF9jW2Bjve --- apps/web/components/document-modal/index.tsx | 26 +++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/web/components/document-modal/index.tsx b/apps/web/components/document-modal/index.tsx index 6a25e194..cbe03c56 100644 --- a/apps/web/components/document-modal/index.tsx +++ b/apps/web/components/document-modal/index.tsx @@ -27,6 +27,30 @@ import { useIsMobile } from "@hooks/use-mobile" type DocumentsResponse = z.infer type DocumentWithMemories = DocumentsResponse["documents"][0] +function getDocumentSourceUrl(document: DocumentWithMemories): string { + const url = document.url ?? "" + const googleDocTypes: Record = { + google_doc: "https://docs.google.com/document/d/", + google_sheet: "https://docs.google.com/spreadsheets/d/", + google_slide: "https://docs.google.com/presentation/d/", + } + + const prefix = document.type ? googleDocTypes[document.type] : null + if (!prefix) return url + + if (document.customId) { + return `${prefix}${document.customId}/edit` + } + + // Extract ID from API URL like docs.googleapis.com/v1/documents/{id} + const apiMatch = url.match(/docs\.googleapis\.com\/v1\/documents\/([a-zA-Z0-9_-]+)/) + if (apiMatch?.[1]) { + return `${prefix}${apiMatch[1]}/edit` + } + + return url +} + interface DocumentModalProps { document: DocumentWithMemories | null isOpen: boolean @@ -237,7 +261,7 @@ export function DocumentModal({ /> {_document?.url && (