(dbx sharedLinkClient, link sharing.IsSharedLinkMetadata, opts shareLinkCreateOptions)
| 214 | } |
| 215 | |
| 216 | func 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 | |
| 253 | func (opts shareLinkCreateOptions) hasCreateSettings() bool { |
| 254 | return opts.expires != nil || opts.allowDownload || opts.access != nil || opts.audience != nil || opts.password.set |
no test coverage detected