Skip to content

Commit 31e99ec

Browse files
Merge pull request #6 from SendSafely/v3.1.1
v3.1.1
2 parents d3c39e4 + 7da625c commit 31e99ec

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

SendSafelyAPI/src/com/sendsafely/SendSafely.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public List<RecipientHistory> getRecipientHistory(String recipientEmail) throws
488488
public java.io.File downloadFile(String packageId, String fileId, String keyCode, ProgressInterface progress, String password) throws DownloadFileException, PasswordRequiredException
489489
{
490490
DownloadAndDecryptFileHandler handler = new DownloadAndDecryptFileHandler(uploadManager);
491-
return handler.makeRequest(packageId, null, fileId, keyCode, progress, password);
491+
return handler.makeRequestS3(packageId, null, fileId, keyCode, progress, password, ec2Proxy);
492492
}
493493

494494
/**
@@ -505,7 +505,7 @@ public java.io.File downloadFile(String packageId, String fileId, String keyCode
505505
public java.io.File downloadFile(String packageId, String fileId, String keyCode, String password) throws DownloadFileException, PasswordRequiredException
506506
{
507507
DownloadAndDecryptFileHandler handler = new DownloadAndDecryptFileHandler(uploadManager);
508-
return handler.makeRequest(packageId, null, fileId, keyCode, null, password);
508+
return handler.makeRequestS3(packageId, null, fileId, keyCode, new DefaultProgress(), password, ec2Proxy);
509509
}
510510

511511
/**

SendSafelyAPI/src/com/sendsafely/dto/request/GetDownloadUrlsRequest.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ public void setChecksum(String checksum){
3535
public void setForceProxy(boolean forceProxy){
3636
super.setPostParam("forceProxy", forceProxy);
3737
}
38+
public void setPassword(String password){
39+
super.setPostParam("password", password);
40+
}
3841
}

SendSafelyAPI/src/com/sendsafely/handlers/DownloadAndDecryptFileHandler.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ public java.io.File makeRequestS3(String packageId, String directoryId, String f
121121
// Download the file
122122
java.io.File file = null;
123123
try {
124-
file = downloadFileFromS3(systemFile, fileToDownload, forceProxy);
124+
file = downloadFileS3(systemFile, fileToDownload, password, forceProxy, 0);
125125
} catch (GetDownloadUrlsException e) {
126-
throw new DownloadFileException("Unable to get download URLs");
126+
throw new DownloadFileException(e.getMessage());
127127
} catch (LimitExceededException e){
128128
try {
129-
file = downloadFileFromS3(systemFile, fileToDownload, true, Integer.parseInt(e.getMessage().toString()));
130-
} catch (GetDownloadUrlsException | LimitExceededException e1) {
129+
file = downloadFileS3(systemFile, fileToDownload, password, true, Integer.parseInt(e.getMessage().toString()));
130+
} catch (GetDownloadUrlsException e1) {
131+
throw new DownloadFileException(e.getMessage());
132+
} catch (LimitExceededException e1) {
131133
throw new DownloadFileException("Unable to get download URLs");
132134
}
133135
}catch(Exception e){
@@ -232,11 +234,7 @@ private java.io.File downloadFile(java.io.File outFile, File ssFile) throws Down
232234
return outFile;
233235
}
234236

235-
private java.io.File downloadFileFromS3(java.io.File systemFile, File fileToDownload, boolean forceProxy) throws DownloadFileException, PasswordRequiredException, GetDownloadUrlsException, LimitExceededException {
236-
return downloadFileFromS3(systemFile, fileToDownload, forceProxy, 0);
237-
}
238-
239-
private java.io.File downloadFileFromS3(java.io.File outFile, File ssFile, boolean forceProxy, int filePart) throws DownloadFileException, PasswordRequiredException, GetDownloadUrlsException, LimitExceededException {
237+
private java.io.File downloadFileS3(java.io.File outFile, File ssFile, String password, boolean forceProxy, int filePart) throws DownloadFileException, PasswordRequiredException, GetDownloadUrlsException, LimitExceededException {
240238

241239
Progress progress = new Progress(this.progress, ssFile.getFileId());
242240
progress.setTotal(ssFile.getFileSize());
@@ -256,7 +254,7 @@ private java.io.File downloadFileFromS3(java.io.File outFile, File ssFile, boole
256254

257255
GetDownloadUrlsHandler urlHandler = new GetDownloadUrlsHandler(uploadManager,ssFile.getParts());
258256
String checksum = calculateChecksum(packageInfo.getPackageCode(), packageInfo.getKeyCode());
259-
urlHandler.fetchDownloadUrls(packageInfo.getPackageId(), ssFile.getFileId(), this.directoryId, part, forceProxy, checksum);//do we need password here?
257+
urlHandler.fetchDownloadUrls(packageInfo.getPackageId(), ssFile.getFileId(), this.directoryId, part, forceProxy, password, checksum);
260258

261259
while (!urlHandler.getCurrentDownloadUrls().isEmpty()) {
262260

@@ -309,7 +307,7 @@ private java.io.File downloadFileFromS3(java.io.File outFile, File ssFile, boole
309307
}
310308
urlHandler.removeUrl();
311309
part++;
312-
urlHandler.fetchDownloadUrls(packageInfo.getPackageId(), ssFile.getFileId(), this.directoryId, part, forceProxy, checksum);
310+
urlHandler.fetchDownloadUrls(packageInfo.getPackageId(), ssFile.getFileId(), this.directoryId, part, forceProxy, password, checksum);
313311
}
314312
}catch(LimitExceededException e){
315313
throw new LimitExceededException(e.getMessage());

SendSafelyAPI/src/com/sendsafely/handlers/GetDownloadUrlsHandler.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public GetDownloadUrlsHandler(UploadManager uploadManager, int totalFileParts) {
2929
this.downloadUrls = new ArrayList<Map<String, String>>();
3030
}
3131

32-
public void fetchDownloadUrls(String packageId, String fileId, String directoryId, int filePart, boolean forceProxy, String checksum) throws GetDownloadUrlsException {
32+
public void fetchDownloadUrls(String packageId, String fileId, String directoryId, int filePart, boolean forceProxy, String password, String checksum) throws GetDownloadUrlsException {
3333

3434
int urlBatchSize = 0;
3535

@@ -38,7 +38,7 @@ public void fetchDownloadUrls(String packageId, String fileId, String directoryI
3838
if(directoryId!=null){
3939
createRequest(packageId,fileId,directoryId,filePart,urlBatchSize, forceProxy, checksum);
4040
}else{
41-
createRequest(packageId,fileId,filePart,urlBatchSize, forceProxy, checksum);
41+
createRequest(packageId,fileId,filePart,urlBatchSize, forceProxy, checksum, password);
4242
}
4343
makeRequest();
4444
} else if (filePart == (totalDownloadUrlsFetched - URL_REFRESH_LIMIT)) {
@@ -49,7 +49,7 @@ public void fetchDownloadUrls(String packageId, String fileId, String directoryI
4949
if(directoryId!=null){
5050
createRequest(packageId,fileId,directoryId,totalDownloadUrlsFetched+1,totalDownloadUrlsFetched+urlBatchSize, forceProxy, checksum);
5151
}else{
52-
createRequest(packageId,fileId,totalDownloadUrlsFetched+1,totalDownloadUrlsFetched+urlBatchSize, forceProxy, checksum);
52+
createRequest(packageId,fileId,totalDownloadUrlsFetched+1,totalDownloadUrlsFetched+urlBatchSize, forceProxy, checksum, password);
5353
}
5454
makeRequest();
5555
}
@@ -73,7 +73,7 @@ private void makeRequest() throws GetDownloadUrlsException {
7373

7474
}
7575

76-
private void createRequest (String packageId, String fileId, int startSegment, int endSegment, boolean forceProxy, String checksum) {
76+
private void createRequest (String packageId, String fileId, int startSegment, int endSegment, boolean forceProxy, String checksum, String password) {
7777

7878
this.request = new GetDownloadUrlsRequest(this.uploadManager.getJsonManager());
7979
((GetDownloadUrlsRequest) request).setPackageId(packageId);
@@ -82,6 +82,9 @@ private void createRequest (String packageId, String fileId, int startSegment, i
8282
((GetDownloadUrlsRequest) request).setEndSegment(endSegment);
8383
((GetDownloadUrlsRequest) request).setChecksum(checksum);
8484
((GetDownloadUrlsRequest) request).setForceProxy(forceProxy);
85+
if(password != null){
86+
((GetDownloadUrlsRequest) request).setPassword(password);
87+
}
8588
}
8689
private void createRequest (String packageId, String fileId, String directoryId, int startSegment, int endSegment, boolean forceProxy, String checksum) {
8790

0 commit comments

Comments
 (0)