Skip to content

Commit

Permalink
Merge pull request #17 from LanceGin/dev
Browse files Browse the repository at this point in the history
Add: batchDownload
  • Loading branch information
LanceGin authored Dec 7, 2017
2 parents dd25869 + 5e96094 commit 8cfeceb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
},
"mac": {
"icon": "build/icons/icon.icns",
"target": ["mas", "dmg", "pkg"],
"target": [
"mas",
"dmg",
"pkg"
],
"bundleVersion": "1.5.0"
},
"win": {
Expand All @@ -61,6 +65,7 @@
"dependencies": {
"axios": "^0.16.1",
"element-ui": "^1.4.0",
"jszip": "^3.1.5",
"moment": "^2.18.1",
"request": "^2.81.0",
"request-promise": "^4.2.1",
Expand Down
41 changes: 36 additions & 5 deletions src/renderer/components/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,38 @@
// batch download
Bus.$on('batchDownload', () => {
console.log('批量下载');
// import jszip and fileSaver
const JSZip = require('jszip');
const saveAs = require('jszip/vendor/FileSaver');
const bucket = this.$route.query.bucket;
const accessKey = localStorage.accessKey;
const secretKey = localStorage.secretKey;
const zip = new JSZip();
const items = this.multipleSelection;
Qiniu.domain(accessKey, secretKey, bucket)
.then((data) => {
const domain = data[data.length - 1];
items.forEach((item) => {
const link = `http://${domain}/${item.key}`;
// add file to the zip file through promise
const promise = Util.urlToBlob(link).then(res => res.blob());
zip.file(item.key, promise);
});
// compress and download
zip.generateAsync({
type: 'blob',
mimeType: 'application/zip',
})
.then((content) => {
saveAs(content, 'qbox-batchDownload.zip.zip');
});
})
.catch();
});
// search filter
Expand All @@ -168,7 +199,7 @@
const secretKey = localStorage.secretKey;
Qiniu.list(accessKey, secretKey, bucket, '', filter)
.then((data) => {
console.log(data);
// console.log(data);
this.filter = filter;
this.marker = data.marker == null ? '' : data.marker;
this.fileList = data.items;
Expand All @@ -187,7 +218,7 @@
const secretKey = localStorage.secretKey;
Qiniu.list(accessKey, secretKey, bucket)
.then((data) => {
console.log(data);
// console.log(data);
this.marker = data.marker == null ? '' : data.marker;
this.fileList = data.items;
})
Expand Down Expand Up @@ -269,7 +300,7 @@
const bucket = this.$route.query.bucket;
const accessKey = localStorage.accessKey;
const secretKey = localStorage.secretKey;
console.log(bucket, this.oldName, this.currentName);
// console.log(bucket, this.oldName, this.currentName);
Qiniu.rename(accessKey, secretKey, bucket, this.oldName, this.currentName)
.then(() => {
this.renameDialogVisible = false;
Expand Down Expand Up @@ -334,7 +365,7 @@
},
// loadMore feature
loadMore() {
console.log(this.filter);
// console.log(this.filter);
const bucket = this.$route.query.bucket;
const accessKey = localStorage.accessKey;
const secretKey = localStorage.secretKey;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ManageTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<el-button class="w-btn" type="text" icon="upload" @click="upload()"> 上传</el-button>
<el-button class="w-btn" type="text" icon="time" @click="refresh()"> 刷新</el-button>
<el-button class="w-btn" type="text" icon="delete" :disabled="batchShow" @click="batchDelete()">删除</el-button>
<!-- <el-button class="w-btn" type="text" :disabled="true" icon="document" @click="batchDownload()"> 下载</el-button> -->
<el-button class="w-btn" type="text" :disabled="batchShow" icon="document" @click="batchDownload()"> 下载</el-button>
</div>
<div class="search-input">
<el-input
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ export default class Util {
const safeDigest = this.base64ToUrlSafe(digest);
return `QBox ${mac.accessKey}:${safeDigest}`;
}

/**
* transfer url string to Blob object
* @param url url string
*/
static urlToBlob(url) {
return fetch(url);
}
}

0 comments on commit 8cfeceb

Please sign in to comment.