MCPcopy Create free account
hub / github.com/openclaw/gogcli / replaceMarkdownWithDrive

Method replaceMarkdownWithDrive

internal/cmd/docs_edit.go:290–409  ·  view source on GitHub ↗
(
	ctx context.Context,
	flags *RootFlags,
	docID string,
	markdown preparedMarkdown,
	plan docsedit.MarkdownWritePlan,
)

Source from the content-addressed store, hash-verified

288}
289
290func (c *DocsWriteCmd) replaceMarkdownWithDrive(
291 ctx context.Context,
292 flags *RootFlags,
293 docID string,
294 markdown preparedMarkdown,
295 plan docsedit.MarkdownWritePlan,
296) error {
297 u := ui.FromContext(ctx)
298 dryRunPayload := map[string]any{
299 "document_id": docID,
300 "written": len(markdown.source),
301 "append": false,
302 "replace": true,
303 "markdown": true,
304 "pageless": c.Pageless,
305 "images": plan.ImageCount,
306 "check_orphans": plan.CheckOrphans,
307 }
308 for k, v := range c.Layout.dryRunPayload() {
309 dryRunPayload[k] = v
310 }
311 if err := dryRunExit(ctx, flags, "docs.write", dryRunPayload); err != nil {
312 return err
313 }
314
315 account, driveSvc, err := requireDriveService(ctx, flags)
316 if err != nil {
317 return err
318 }
319
320 var docsSvc *docs.Service
321 if plan.CheckOrphans {
322 docsSvc, err = docsService(ctx, account)
323 if err != nil {
324 return err
325 }
326 orphans, tabID, orphanErr := findDocsWriteMarkdownOrphans(
327 ctx,
328 driveSvc,
329 docsSvc,
330 docID,
331 markdown,
332 plan.Tab,
333 plan.OrphanScopeWholeDocument,
334 )
335 if orphanErr != nil {
336 return orphanErr
337 }
338 if resultErr := writeDocsWriteOrphanResult(ctx, docID, tabID, orphans); resultErr != nil {
339 return resultErr
340 }
341 }
342
343 updated, err := driveSvc.Files.Update(docID, &drive.File{}).
344 Media(strings.NewReader(plan.Markdown), gapi.ContentType(mimeTextMarkdown)).
345 SupportsAllDrives(true).
346 Fields("id,name,webViewLink").
347 Context(ctx).

Callers 1

writeMarkdownMethod · 0.95

Calls 15

applyDocumentStyleMethod · 0.95
FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
dryRunExitFunction · 0.85
requireDriveServiceFunction · 0.85
docsServiceFunction · 0.85
insertImagesIntoDocsFunction · 0.85

Tested by

no test coverage detected