Skip to content

Commit cb9c307

Browse files
committed
refactor download function to handle upload
1 parent 2a38bc5 commit cb9c307

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/components/BucketSync.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@ class BucketSync extends Component {
2525
return (this.props.selectedBucket.length && this.props.downloadDirectory.length) > 0;
2626
}
2727

28-
downloadBucket() {
28+
syncBucket(syncType) {
2929
// TODO: Killing the app should kill this process
3030
// TODO: Conditionally use s3 SDK or CLI depending on user config - https://www.npmjs.com/package/electron-config
31-
// TODO: https://github.com/atom/node-keytar - look into this for key storage
3231
fixPath();
3332

34-
var startMessage = `Starting Download from ${this.props.selectedBucket}`;
33+
var startMessage = `Starting ${syncType} - ${this.props.selectedBucket}`;
3534
this.updateConsoleOutput(startMessage);
3635

37-
var sync = spawn('aws', ['s3', 'sync', `s3://${this.props.selectedBucket}`, `${this.props.downloadDirectory}`]);
3836
var _this = this;
37+
var syncArgs = [];
38+
if(syncType === 'download'){
39+
syncArgs = ['s3', 'sync', `s3://${this.props.selectedBucket}`, `${this.props.downloadDirectory}`]
40+
} else if(syncType === 'upload') {
41+
syncArgs = ['s3', 'sync', `${this.props.downloadDirectory}`, `s3://${this.props.selectedBucket}`]
42+
}
43+
44+
var sync = spawn('aws', syncArgs);
3945

4046
sync.stdout.on('data', function(data) {
4147
_this.updateConsoleOutput(data);
@@ -81,7 +87,7 @@ class BucketSync extends Component {
8187
<div>
8288
<div className="row bottom-buffer">
8389
<div className="col-md-4 text-left">
84-
<Button onClick={() => this.downloadBucket()} disabled={!this.showDownloadButton()}>Download Bucket</Button>
90+
<Button onClick={() => this.syncBucket('download')} disabled={!this.showDownloadButton()}>Download Bucket</Button>
8591
</div>
8692
</div>
8793

0 commit comments

Comments
 (0)