-
-
Notifications
You must be signed in to change notification settings - Fork 305
feat: Copy B2 CLI URL #17108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: Copy B2 CLI URL #17108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,20 +23,20 @@ | |
import ch.cyberduck.core.Scheme; | ||
import ch.cyberduck.core.URIEncoder; | ||
import ch.cyberduck.core.UrlProvider; | ||
import ch.cyberduck.core.PathRelativizer; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.EnumSet; | ||
import java.util.Locale; | ||
|
||
public class B2UrlProvider implements UrlProvider { | ||
|
||
private final PathContainerService containerService | ||
= new B2PathContainerService(); | ||
|
||
private final PathContainerService containerService; | ||
private final B2Session session; | ||
|
||
public B2UrlProvider(final B2Session session) { | ||
this.session = session; | ||
this.containerService = session.getFeature(PathContainerService.class); | ||
} | ||
|
||
@Override | ||
|
@@ -45,12 +45,38 @@ public DescriptiveUrlBag toUrl(final Path file, final EnumSet<DescriptiveUrl.Typ | |
return DescriptiveUrlBag.empty(); | ||
} | ||
final DescriptiveUrlBag list = new DescriptiveUrlBag(); | ||
if(file.isFile()) { | ||
final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), | ||
URIEncoder.encode(containerService.getContainer(file).getName()), | ||
URIEncoder.encode(containerService.getKey(file))); | ||
list.add(new DescriptiveUrl(download, DescriptiveUrl.Type.http, | ||
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT)))); | ||
if(file.isFile() || file.isDirectory()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move check for file type inside scope of handled types. |
||
if(types.contains(DescriptiveUrl.Type.http) && file.isFile()) { | ||
final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), | ||
URIEncoder.encode(containerService.getContainer(file).getName()), | ||
URIEncoder.encode(containerService.getKey(file))); | ||
list.add(new DescriptiveUrl(download, DescriptiveUrl.Type.http, | ||
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT)))); | ||
} | ||
if(types.contains(DescriptiveUrl.Type.provider)) { | ||
final Path container = containerService.getContainer(file); | ||
if(!file.isRoot()) { | ||
String cliUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assign |
||
if(container.equals(file)) { | ||
cliUrl = String.format("b2://%s/", container.getName()); | ||
} | ||
else { | ||
String key; | ||
if(file.isDirectory()) { | ||
key = PathRelativizer.relativize(container.getAbsolute(), file.getAbsolute()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
} | ||
else { | ||
key = containerService.getKey(file); | ||
} | ||
if(file.isDirectory() && !key.endsWith("/")) { | ||
key = key + "/"; | ||
} | ||
cliUrl = String.format("b2://%s/%s", container.getName(), key); | ||
} | ||
list.add(new DescriptiveUrl(cliUrl, DescriptiveUrl.Type.provider, | ||
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "B2 CLI"))); | ||
} | ||
} | ||
} | ||
return list; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change as the pattern instantiating
B2PathContainerService
is present in all other features.