Search in sources :

Example 1 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class BoxShareFeature method createFileSharedLink.

private DescriptiveUrl createFileSharedLink(final Path file, final PasswordCallback callback) throws BackgroundException {
    try {
        final String password = this.prompt(file, callback);
        final File link = new SharedLinksFilesApi(new BoxApiClient(session.getClient())).putFilesIdAddSharedLink("shared_link", fileid.getFileId(file, new DisabledListProgressListener()), new FilesFileIdaddSharedLinkBody().sharedLink(new FilesfileIdaddSharedLinkSharedLink().password(password)));
        return new DescriptiveUrl(URI.create(link.getSharedLink().getDownloadUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FilesFileIdaddSharedLinkBody(ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdaddSharedLinkBody) SharedLinksFilesApi(ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFilesApi) FilesfileIdaddSharedLinkSharedLink(ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdaddSharedLinkSharedLink) File(ch.cyberduck.core.box.io.swagger.client.model.File) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 2 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class PathAttributesDictionary method deserialize.

public <T> PathAttributes deserialize(T serialized) {
    final Deserializer dict = factory.create(serialized);
    final PathAttributes attributes = new PathAttributes();
    final String sizeObj = dict.stringForKey("Size");
    if (sizeObj != null) {
        attributes.setSize(Long.parseLong(sizeObj));
    }
    final String quotaObj = dict.stringForKey("Quota");
    if (quotaObj != null) {
        attributes.setQuota(Long.parseLong(quotaObj));
    }
    final String modifiedObj = dict.stringForKey("Modified");
    if (modifiedObj != null) {
        attributes.setModificationDate(Long.parseLong(modifiedObj));
    }
    final String createdObj = dict.stringForKey("Created");
    if (createdObj != null) {
        attributes.setCreationDate(Long.parseLong(createdObj));
    }
    final String revisionObj = dict.stringForKey("Revision");
    if (revisionObj != null) {
        attributes.setRevision(Long.parseLong(revisionObj));
    }
    final List<T> versionsObj = dict.listForKey("Versions");
    if (versionsObj != null) {
        final AttributedList<Path> versions = new AttributedList<>();
        for (T versionDict : versionsObj) {
            versions.add(new PathDictionary(factory).deserialize(versionDict));
        }
        attributes.setVersions(versions);
    }
    final String etagObj = dict.stringForKey("ETag");
    if (etagObj != null) {
        attributes.setETag(etagObj);
    }
    final Object permissionObj = dict.objectForKey("Permission");
    if (permissionObj != null) {
        attributes.setPermission(new PermissionDictionary().deserialize(permissionObj));
    }
    final Object aclObj = dict.objectForKey("Acl");
    if (aclObj != null) {
        attributes.setAcl(new AclDictionary().deserialize(aclObj));
    }
    if (dict.mapForKey("Link") != null) {
        final Map<String, String> link = dict.mapForKey("Link");
        attributes.setLink(new DescriptiveUrl(URI.create(link.get("Url")), DescriptiveUrl.Type.valueOf(link.get("Type"))));
    } else {
        final String linkObj = dict.stringForKey("Link");
        if (linkObj != null) {
            attributes.setLink(new DescriptiveUrl(URI.create(linkObj), DescriptiveUrl.Type.http));
        }
    }
    if (dict.mapForKey("Checksum") != null) {
        final Map<String, String> checksum = dict.mapForKey("Checksum");
        attributes.setChecksum(new Checksum(HashAlgorithm.valueOf(checksum.get("Algorithm")), checksum.get("Hash")));
    } else {
        attributes.setChecksum(Checksum.parse(dict.stringForKey("Checksum")));
    }
    attributes.setVersionId(dict.stringForKey("Version"));
    attributes.setFileId(dict.stringForKey("File Id"));
    attributes.setLockId(dict.stringForKey("Lock Id"));
    final String duplicateObj = dict.stringForKey("Duplicate");
    if (duplicateObj != null) {
        attributes.setDuplicate(Boolean.parseBoolean(duplicateObj));
    }
    final String hiddenObj = dict.stringForKey("Hidden");
    if (hiddenObj != null) {
        attributes.setHidden(Boolean.parseBoolean(hiddenObj));
    }
    attributes.setMetadata(Collections.emptyMap());
    attributes.setRegion(dict.stringForKey("Region"));
    attributes.setStorageClass(dict.stringForKey("Storage Class"));
    final Object vaultObj = dict.objectForKey("Vault");
    if (vaultObj != null) {
        attributes.setVault(new PathDictionary(factory).deserialize(vaultObj));
    }
    final Map<String, String> customObj = dict.mapForKey("Custom");
    if (customObj != null) {
        attributes.setCustom(customObj);
    }
    return attributes;
}
Also used : Path(ch.cyberduck.core.Path) PathAttributes(ch.cyberduck.core.PathAttributes) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) AttributedList(ch.cyberduck.core.AttributedList) Checksum(ch.cyberduck.core.io.Checksum)

Example 3 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class DefaultUrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.attributes().getLink() != DescriptiveUrl.EMPTY) {
        list.add(file.attributes().getLink());
    }
    list.add(new DescriptiveUrl(URI.create(String.format("%s%s", new HostUrlProvider().withUsername(false).get(host), URIEncoder.encode(file.getAbsolute()))), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), host.getProtocol().getScheme().toString().toUpperCase(Locale.ROOT))));
    list.addAll(new HostWebUrlProvider(host).toUrl(file));
    return list;
}
Also used : HostWebUrlProvider(ch.cyberduck.core.HostWebUrlProvider) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) HostUrlProvider(ch.cyberduck.core.HostUrlProvider) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Example 4 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class DistributionUrlProviderTest method testStreaming.

@Test
public void testStreaming() {
    final Distribution distribution = new Distribution(Distribution.STREAMING, "n", URI.create("https://test.cyberduck.ch.s3.amazonaws.com"), true);
    distribution.setUrl(URI.create("rtmp://d1f6cbdjcbzyiu.cloudfront.net/cfx/st"));
    final DescriptiveUrl cdn = new DistributionUrlProvider(distribution).toUrl(new Path("/test.cyberduck.ch/p/f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.cdn);
    assertEquals("rtmp://d1f6cbdjcbzyiu.cloudfront.net/cfx/st/p/f", cdn.getUrl());
    assertEquals("n Streaming (RTMP) CDN URL", cdn.getHelp());
    final DescriptiveUrl origin = new DistributionUrlProvider(distribution).toUrl(new Path("/test.cyberduck.ch/p/f", EnumSet.of(Path.Type.file))).find(DescriptiveUrl.Type.origin);
    assertEquals("https://test.cyberduck.ch.s3.amazonaws.com/p/f", origin.getUrl());
    assertEquals("n Origin URL", origin.getHelp());
}
Also used : Path(ch.cyberduck.core.Path) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) Test(org.junit.Test)

Example 5 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class DistributionUrlProviderTest method testCustomOrigin.

@Test
public void testCustomOrigin() {
    final Distribution distribution = new Distribution(Distribution.CUSTOM, "n", URI.create("http://test.cyberduck.ch/"), true);
    final DescriptiveUrl url = new DistributionUrlProvider(distribution).toUrl(new Path("/p/f", EnumSet.of(Path.Type.directory))).find(DescriptiveUrl.Type.origin);
    assertEquals("http://test.cyberduck.ch/p/f", url.getUrl());
    assertEquals("n Origin URL", url.getHelp());
}
Also used : Path(ch.cyberduck.core.Path) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) Test(org.junit.Test)

Aggregations

DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)77 Path (ch.cyberduck.core.Path)42 Test (org.junit.Test)40 IntegrationTest (ch.cyberduck.test.IntegrationTest)30 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)25 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)24 Delete (ch.cyberduck.core.features.Delete)24 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)22 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)22 Host (ch.cyberduck.core.Host)19 DescriptiveUrlBag (ch.cyberduck.core.DescriptiveUrlBag)16 ObjectExpiration (ch.cyberduck.core.sds.io.swagger.client.model.ObjectExpiration)14 LoginOptions (ch.cyberduck.core.LoginOptions)13 CreateDownloadShareRequest (ch.cyberduck.core.sds.io.swagger.client.model.CreateDownloadShareRequest)12 Credentials (ch.cyberduck.core.Credentials)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 LoginCanceledException (ch.cyberduck.core.exception.LoginCanceledException)7 PathAttributes (ch.cyberduck.core.PathAttributes)6 IOException (java.io.IOException)6 HostUrlProvider (ch.cyberduck.core.HostUrlProvider)5