(ctx context.Context, docsSvc *docs.Service, driveSvc *drive.Service, docID, localPath, name, mimeType string, target docsImageTarget)
| 247 | } |
| 248 | |
| 249 | func (c *DocsInsertImageCmd) runFile(ctx context.Context, docsSvc *docs.Service, driveSvc *drive.Service, docID, localPath, name, mimeType string, target docsImageTarget) (result docsInsertImageResult, err error) { |
| 250 | uploaded, err := uploadDocsInlineImage(ctx, driveSvc, localPath, name, mimeType, strings.TrimSpace(c.Parent)) |
| 251 | if err != nil { |
| 252 | return result, err |
| 253 | } |
| 254 | result.uploadedFileID = uploaded.Id |
| 255 | result.uploadedFileName = uploaded.Name |
| 256 | |
| 257 | perm, err := shareDocsImagePublicly(ctx, driveSvc, uploaded.Id) |
| 258 | if err != nil { |
| 259 | if strings.EqualFold(c.OnRestricted, "link") && isDrivePublicSharingRestricted(err) { |
| 260 | return c.insertRestrictedImageFallback(ctx, docsSvc, docID, uploaded, target, result) |
| 261 | } |
| 262 | return result, fmt.Errorf("share uploaded image publicly: %w", err) |
| 263 | } |
| 264 | result.permissionID = perm.Id |
| 265 | |
| 266 | defer func() { |
| 267 | if perm.Id == "" { |
| 268 | return |
| 269 | } |
| 270 | result.revoked, err = finishDocsImagePublicShare(ctx, driveSvc, uploaded.Id, perm.Id, err) |
| 271 | }() |
| 272 | |
| 273 | imageURL := driveImageDownloadURL(uploaded.Id) |
| 274 | return c.insertImageURL(ctx, docsSvc, docID, imageURL, target, result) |
| 275 | } |
| 276 | |
| 277 | func (c *DocsInsertImageCmd) insertImageURL(ctx context.Context, docsSvc *docs.Service, docID, imageURL string, target docsImageTarget, result docsInsertImageResult) (docsInsertImageResult, error) { |
| 278 | reqs, index, tabID, err := c.buildInsertRequests(ctx, docsSvc, docID, target, imageURL) |
no test coverage detected