(dbx sharedLinkClient, requestedPath string)
| 328 | } |
| 329 | |
| 330 | func findExistingSharedLink(dbx sharedLinkClient, requestedPath string) (sharing.IsSharedLinkMetadata, error) { |
| 331 | arg := sharing.NewListSharedLinksArg() |
| 332 | arg.Path = requestedPath |
| 333 | arg.DirectOnly = true |
| 334 | |
| 335 | var firstDirect sharing.IsSharedLinkMetadata |
| 336 | |
| 337 | for { |
| 338 | res, err := dbx.ListSharedLinksContext(currentContext(), arg) |
| 339 | if err != nil { |
| 340 | return nil, withJSONErrorDetails(err, operationErrorDetails("share_link_create"), pathErrorDetails(requestedPath)) |
| 341 | } |
| 342 | |
| 343 | for _, link := range res.Links { |
| 344 | linkPath, ok := sharedLinkPathLower(link) |
| 345 | if ok { |
| 346 | if sameDropboxPath(linkPath, requestedPath) { |
| 347 | return link, nil |
| 348 | } |
| 349 | continue |
| 350 | } |
| 351 | |
| 352 | if firstDirect == nil { |
| 353 | firstDirect = link |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | if !res.HasMore { |
| 358 | break |
| 359 | } |
| 360 | if res.Cursor == "" { |
| 361 | return nil, errors.New("shared link lookup has more results but no cursor") |
| 362 | } |
| 363 | arg.Cursor = res.Cursor |
| 364 | } |
| 365 | |
| 366 | if firstDirect != nil { |
| 367 | return firstDirect, nil |
| 368 | } |
| 369 | |
| 370 | return nil, fmt.Errorf("shared link already exists but no direct link was found for %q", requestedPath) |
| 371 | } |
| 372 | |
| 373 | func sharedLinkURL(link sharing.IsSharedLinkMetadata) (string, bool) { |
| 374 | switch link := link.(type) { |
no test coverage detected