Skip to content

Commit

Permalink
Add sharee definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jul 5, 2023
1 parent 80f66fc commit ccfaade
Show file tree
Hide file tree
Showing 29 changed files with 231 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, 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)));
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));
Expand All @@ -91,7 +91,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final Pass
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Void none, final PasswordCallback callback) throws BackgroundException {
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testToUrl() throws Exception {
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());
final DescriptiveUrl url = provider.toDownloadUrl(test, PromptUrlProvider.Sharee.world, null, new DisabledPasswordCallback());
assertNotEquals(DescriptiveUrl.EMPTY, url);
assertNotNull(url.getUrl());
new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
Expand Down
4 changes: 2 additions & 2 deletions box/src/main/java/ch/cyberduck/core/box/BoxShareFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
if(file.isDirectory()) {
return this.createFolderSharedLink(file, callback);
}
return this.createFileSharedLink(file, callback);
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
throw new UnsupportedException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testFolder() throws Exception {
final BoxShareFeature feature = new BoxShareFeature(session, fileid);
assertTrue(feature.isSupported(directory, PromptUrlProvider.Type.download));
assertFalse(feature.isSupported(directory, PromptUrlProvider.Type.upload));
assertNotNull(feature.toDownloadUrl(directory, null, new DisabledPasswordCallback()).getUrl());
assertNotNull(feature.toDownloadUrl(directory, PromptUrlProvider.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(directory), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}

Expand All @@ -55,7 +55,7 @@ public void testFile() throws Exception {
final BoxShareFeature feature = new BoxShareFeature(session, fileid);
assertTrue(feature.isSupported(test, PromptUrlProvider.Type.download));
assertFalse(feature.isSupported(test, PromptUrlProvider.Type.upload));
assertNotNull(feature.toDownloadUrl(test, null, new DisabledPasswordCallback()).getUrl());
assertNotNull(feature.toDownloadUrl(test, PromptUrlProvider.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
try {
final Credentials password = callback.prompt(session.getHost(),
LocaleFactory.localizedString("Passphrase", "Cryptomator"),
Expand All @@ -63,7 +63,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.cyberduck.core.DisabledPasswordCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

Expand All @@ -39,7 +40,7 @@ public void toDownloadUrl() throws Exception {
EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
final Path test = new BrickTouchFeature(session).touch(
new Path(directory, String.format("%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
assertNotNull(new BrickShareFeature(session).toDownloadUrl(test, null, new DisabledPasswordCallback()).getUrl());
assertNotNull(new BrickShareFeature(session).toDownloadUrl(test, PromptUrlProvider.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BrickDeleteFeature(session).delete(Collections.singletonList(directory), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) {
return proxy.toUrl(file).find(DescriptiveUrl.Type.signed);
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,53 @@
*/

import ch.cyberduck.core.DescriptiveUrl;
import ch.cyberduck.core.LocaleFactory;
import ch.cyberduck.core.PasswordCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.exception.BackgroundException;

import java.util.Collections;
import java.util.List;

@Optional
public interface PromptUrlProvider<Download, Upload> {
boolean isSupported(Path file, Type type);

DescriptiveUrl toDownloadUrl(Path file, Download options, PasswordCallback callback) throws BackgroundException;
/**
* Retrieve list of users from server
*
* @return List of possible users to select from
*/
default List<Sharee> getSharees() throws BackgroundException {
return Collections.singletonList(Sharee.world);
}

DescriptiveUrl toDownloadUrl(Path file, Sharee sharee, Download options, PasswordCallback callback) throws BackgroundException;

DescriptiveUrl toUploadUrl(Path file, Upload options, PasswordCallback callback) throws BackgroundException;
DescriptiveUrl toUploadUrl(Path file, Sharee sharee, Upload options, PasswordCallback callback) throws BackgroundException;

enum Type {
download,
upload
}

class Sharee {
private final String identifier;
private final String description;

public Sharee(final String identifier, final String description) {
this.identifier = identifier;
this.description = description;
}

public String getIdentifier() {
return identifier;
}

public String getDescription() {
return description;
}

public static final Sharee world = new Sharee(null, LocaleFactory.localizedString("Public"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DescriptiveUrl run(final Session<?> session) throws BackgroundException {
if(log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", provider));
}
return provider.toDownloadUrl(file, options, callback);
return provider.toDownloadUrl(file, PromptUrlProvider.Sharee.world, options, callback);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DescriptiveUrl run(final Session<?> session) throws BackgroundException {
if(log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", provider));
}
return provider.toUploadUrl(file, options, callback);
return provider.toUploadUrl(file, PromptUrlProvider.Sharee.world, options, callback);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, CreateDownloadShareRequest options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, CreateDownloadShareRequest options, final PasswordCallback callback) throws BackgroundException {
try {
if(log.isDebugEnabled()) {
log.debug(String.format("Create download share for %s", file));
Expand Down Expand Up @@ -178,7 +178,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, CreateDownloadShareRequest
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, CreateUploadShareRequest options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, CreateUploadShareRequest options, final PasswordCallback callback) throws BackgroundException {
try {
if(log.isDebugEnabled()) {
log.debug(String.format("Create upload share for %s", file));
Expand Down
Loading

0 comments on commit ccfaade

Please sign in to comment.