MCPcopy Create free account
hub / github.com/dropbox/dbxcli / findExistingSharedLink

Function findExistingSharedLink

cmd/share_link_create.go:330–371  ·  view source on GitHub ↗
(dbx sharedLinkClient, requestedPath string)

Source from the content-addressed store, hash-verified

328}
329
330func 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
373func sharedLinkURL(link sharing.IsSharedLinkMetadata) (string, bool) {
374 switch link := link.(type) {

Callers 1

existingSharedLinkFunction · 0.85

Calls 7

currentContextFunction · 0.85
withJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
pathErrorDetailsFunction · 0.85
sharedLinkPathLowerFunction · 0.85
sameDropboxPathFunction · 0.85

Tested by

no test coverage detected