* Build a multipart/related body for Drive's files.create upload endpoint. * Used when converting Markdown to a Google Doc in a single round-trip. * See: https://developers.google.com/workspace/drive/api/guides/manage-uploads
( metadata: Record<string, unknown>, markdownContent: string, boundary: string )
| 13 | * See: https://developers.google.com/workspace/drive/api/guides/manage-uploads |
| 14 | */ |
| 15 | function buildMarkdownMultipartBody( |
| 16 | metadata: Record<string, unknown>, |
| 17 | markdownContent: string, |
| 18 | boundary: string |
| 19 | ): string { |
| 20 | return ( |
| 21 | `--${boundary}\r\n` + |
| 22 | `Content-Type: application/json; charset=UTF-8\r\n\r\n` + |
| 23 | `${JSON.stringify(metadata)}\r\n` + |
| 24 | `--${boundary}\r\n` + |
| 25 | `Content-Type: text/markdown\r\n\r\n` + |
| 26 | `${markdownContent}\r\n` + |
| 27 | `--${boundary}--` |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | function shouldUseMarkdownUpload(params: GoogleDocsToolParams): boolean { |
| 32 | return Boolean(params.markdown && params.content) |