Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions backblaze/src/main/java/ch/cyberduck/core/b2/B2UrlProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

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.

}

@Override
Expand All @@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign final.

if(container.equals(file)) {
cliUrl = String.format("b2://%s/", container.getName());
}
else {
String key;
if(file.isDirectory()) {
key = PathRelativizer.relativize(container.getAbsolute(), file.getAbsolute());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use B2PathContainerService#getKey and strip the end .bzEmpty (B2PathContainerService.PLACEHOLDER)

}
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;
}
Expand Down