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

Function applyExistingSharedLinkCreateOptions

cmd/share_link_create.go:216–251  ·  view source on GitHub ↗
(dbx sharedLinkClient, link sharing.IsSharedLinkMetadata, opts shareLinkCreateOptions)

Source from the content-addressed store, hash-verified

214}
215
216func applyExistingSharedLinkCreateOptions(dbx sharedLinkClient, link sharing.IsSharedLinkMetadata, opts shareLinkCreateOptions) (sharing.IsSharedLinkMetadata, error) {
217 if opts.access != nil {
218 return nil, invalidArgumentsErrorWithDetails("cannot apply `--access` because the shared link already exists", flagErrorDetails("access"))
219 }
220 if opts.expires == nil && !opts.removeExpiration && !opts.allowDownload && !opts.disallowDownload && opts.audience == nil && !opts.password.set {
221 return link, nil
222 }
223
224 url, ok := sharedLinkURL(link)
225 if !ok {
226 return nil, errors.New("existing shared link response did not include a URL")
227 }
228
229 if opts.disallowDownload {
230 if err := dbx.ModifySharedLinkSettingsRawContext(currentContext(), url, rawSharedLinkSettingsFromCreateOptions(opts), opts.removeExpiration); err != nil {
231 return nil, withJSONErrorDetails(err, operationErrorDetails("share_link_create"), urlErrorDetails(url))
232 }
233 return link, nil
234 }
235
236 if opts.expires != nil || opts.removeExpiration || opts.allowDownload || opts.audience != nil || opts.password.set {
237 settings := sharing.NewSharedLinkSettings()
238 applySharedLinkCreateSettings(settings, opts)
239
240 arg := sharing.NewModifySharedLinkSettingsArgs(url, settings)
241 arg.RemoveExpiration = opts.removeExpiration
242
243 updated, err := dbx.ModifySharedLinkSettingsContext(currentContext(), arg)
244 if err != nil {
245 return nil, withJSONErrorDetails(err, operationErrorDetails("share_link_create"), urlErrorDetails(url))
246 }
247 link = updated
248 }
249
250 return link, nil
251}
252
253func (opts shareLinkCreateOptions) hasCreateSettings() bool {
254 return opts.expires != nil || opts.allowDownload || opts.access != nil || opts.audience != nil || opts.password.set

Callers 1

shareLinkCreateFunction · 0.85

Calls 11

flagErrorDetailsFunction · 0.85
sharedLinkURLFunction · 0.85
currentContextFunction · 0.85
withJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
urlErrorDetailsFunction · 0.85

Tested by

no test coverage detected