(ctx context.Context, account string, source slidesImageSource)
| 64 | } |
| 65 | |
| 66 | func 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 | |
| 105 | func resolveSlidesNotesInput(notes *string, notesFile string) (string, bool, error) { |
| 106 | if notesFile != "" { |
no test coverage detected