( ctx context.Context, svc *docs.Service, docID string, target docsReplaceImageTarget, imageURL string, )
| 198 | } |
| 199 | |
| 200 | func (c *DocsReplaceImageCmd) replaceImageURL( |
| 201 | ctx context.Context, |
| 202 | svc *docs.Service, |
| 203 | docID string, |
| 204 | target docsReplaceImageTarget, |
| 205 | imageURL string, |
| 206 | ) (docsReplaceImageResult, error) { |
| 207 | request := &docs.BatchUpdateDocumentRequest{ |
| 208 | Requests: []*docs.Request{{ReplaceImage: &docs.ReplaceImageRequest{ |
| 209 | ImageObjectId: target.image.ObjectID, |
| 210 | Uri: imageURL, |
| 211 | ImageReplaceMethod: docsImageReplaceMethodCenterCrop, |
| 212 | TabId: target.tabID, |
| 213 | }}}, |
| 214 | WriteControl: docsRequiredRevisionWriteControl(target.revisionID), |
| 215 | } |
| 216 | if _, err := svc.Documents.BatchUpdate(docID, request).Context(ctx).Do(); err != nil { |
| 217 | if isDocsNotFound(err) { |
| 218 | return docsReplaceImageResult{}, fmt.Errorf("doc not found or not a Google Doc (id=%s)", docID) |
| 219 | } |
| 220 | return docsReplaceImageResult{}, fmt.Errorf("replace image: %w", err) |
| 221 | } |
| 222 | return docsReplaceImageResult{ |
| 223 | documentID: docID, |
| 224 | image: target.image, |
| 225 | tabID: target.tabID, |
| 226 | sourceURL: imageURL, |
| 227 | }, nil |
| 228 | } |
| 229 | |
| 230 | func writeDocsReplaceImageResult(ctx context.Context, result docsReplaceImageResult) error { |
| 231 | if outfmt.IsJSON(ctx) { |
no test coverage detected