use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class StoregateShareFeature method toDownloadUrl.
@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void options, final PasswordCallback callback) throws BackgroundException {
try {
final Host bookmark = session.getHost();
final CreateFileShareRequest request = new CreateFileShareRequest().fileId(fileid.getFileId(file, new DisabledListProgressListener()));
try {
request.setPassword(callback.prompt(bookmark, LocaleFactory.localizedString("Passphrase", "Cryptomator"), MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()), new LoginOptions().keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
} catch (LoginCanceledException e) {
// Ignore no password set
}
return new DescriptiveUrl(URI.create(new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
} catch (ApiException e) {
throw new StoregateExceptionMappingService(fileid).map(e);
}
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class StoregateShareFeature method toUploadUrl.
@Override
public DescriptiveUrl toUploadUrl(final Path file, final Void options, final PasswordCallback callback) throws BackgroundException {
try {
final Host bookmark = session.getHost();
final CreateFileShareRequest request = new CreateFileShareRequest().fileId(fileid.getFileId(file, new DisabledListProgressListener())).allowUpload(true);
try {
request.setPassword(callback.prompt(bookmark, LocaleFactory.localizedString("Passphrase", "Cryptomator"), MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()), new LoginOptions().keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
} catch (LoginCanceledException e) {
// Ignore no password set
}
return new DescriptiveUrl(URI.create(new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
} catch (ApiException e) {
throw new StoregateExceptionMappingService(fileid).map(e);
}
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class B2AuthorizedUrlProvider method toDownloadUrl.
@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file)));
try {
if (log.isDebugEnabled()) {
log.debug(String.format("Create download authorization for %s", file));
}
final int seconds = 604800;
// Determine expiry time for URL
final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
expiry.add(Calendar.SECOND, seconds);
final String token = session.getClient().getDownloadAuthorization(fileid.getVersionId(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds);
return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())));
} catch (B2ApiException e) {
throw new B2ExceptionMappingService(fileid).map(e);
} catch (IOException e) {
throw new DefaultIOExceptionMappingService().map(e);
}
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class B2UrlProvider method toUrl.
@Override
public DescriptiveUrlBag toUrl(final Path file) {
if (file.isVolume()) {
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(URI.create(download), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT))));
}
return list;
}
use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.
the class B2AuthorizedUrlProviderTest method testToUrl.
@Test
public void testToUrl() throws Exception {
final Path bucket = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path test = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
new B2TouchFeature(session, fileid).touch(test, new TransferStatus());
final B2AuthorizedUrlProvider provider = new B2AuthorizedUrlProvider(session, fileid);
assertFalse(provider.isSupported(bucket, PromptUrlProvider.Type.download));
final DescriptiveUrl url = provider.toDownloadUrl(test, null, new DisabledPasswordCallback());
assertNotEquals(DescriptiveUrl.EMPTY, url);
assertNotNull(url.getUrl());
new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations