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

Function prepareSlidesImageURL

internal/cmd/slides_shared.go:66–103  ·  view source on GitHub ↗
(ctx context.Context, account string, source slidesImageSource)

Source from the content-addressed store, hash-verified

64}
65
66func prepareSlidesImageURL(ctx context.Context, account string, source slidesImageSource) (string, func(), error) {
67 if source.imageURL != "" {
68 return source.imageURL, func() {}, nil
69 }
70
71 driveSvc, err := driveService(ctx, account)
72 if err != nil {
73 return "", nil, err
74 }
75 imgFile, err := os.Open(source.localPath)
76 if err != nil {
77 return "", nil, fmt.Errorf("open image: %w", err)
78 }
79 defer imgFile.Close()
80
81 driveFile, err := driveSvc.Files.Create(&drive.File{
82 Name: filepath.Base(source.localPath),
83 MimeType: source.mimeType,
84 }).Media(imgFile).Fields("id, webContentLink").Context(ctx).Do()
85 if err != nil {
86 return "", nil, fmt.Errorf("upload image to Drive: %w", err)
87 }
88
89 cleanup := func() {
90 if err := driveSvc.Files.Delete(driveFile.Id).Context(context.WithoutCancel(ctx)).Do(); err != nil {
91 ui.FromContext(ctx).Err().Linef("Warning: failed to delete temporary Drive image %s; it may remain publicly readable until removed: %v", driveFile.Id, err)
92 }
93 }
94 if _, err := driveSvc.Permissions.Create(driveFile.Id, &drive.Permission{
95 Type: "anyone",
96 Role: "reader",
97 }).Context(ctx).Do(); err != nil {
98 cleanup()
99 return "", nil, fmt.Errorf("set image permissions: %w", err)
100 }
101
102 return driveImageDownloadURL(driveFile.Id), cleanup, nil
103}
104
105func resolveSlidesNotesInput(notes *string, notesFile string) (string, bool, error) {
106 if notesFile != "" {

Callers 2

RunMethod · 0.85
RunMethod · 0.85

Calls 10

FromContextFunction · 0.92
driveServiceFunction · 0.85
driveImageDownloadURLFunction · 0.85
ErrorfMethod · 0.80
CreateMethod · 0.80
LinefMethod · 0.80
ErrMethod · 0.80
CloseMethod · 0.65
DoMethod · 0.65
DeleteMethod · 0.45

Tested by

no test coverage detected