Browse Source

test

tags/v0.1.8
Gitea 4 years ago
parent
commit
c8f1fa957e
7 changed files with 483 additions and 328 deletions
  1. +2
    -1
      options/locale/locale_zh-CN.ini
  2. +88
    -4
      package-lock.json
  3. +1
    -0
      package.json
  4. +1
    -1
      templates/repo/cloudbrain/index.tmpl
  5. +3
    -0
      templates/repo/datasets/index.tmpl
  6. +68
    -3
      templates/repo/header.tmpl
  7. +320
    -319
      web_src/js/components/MinioUploader.vue

+ 2
- 1
options/locale/locale_zh-CN.ini View File

@@ -756,7 +756,8 @@ cloudbrain.commit_image=提交
balance=余额 balance=余额
balance.total_view=余额总览 balance.total_view=余额总览
balance.available=可用余额: balance.available=可用余额:
balance.disable=不可用余额:
cloudbrain1=云脑1
cloudbrain2=云脑2


template.items=模板选项 template.items=模板选项
template.git_content=Git数据(默认分支) template.git_content=Git数据(默认分支)


+ 88
- 4
package-lock.json View File

@@ -1922,9 +1922,9 @@
"axios": { "axios": {
"version": "0.21.1", "version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": { "requires": {
"follow-redirects": "1.5.10"
"follow-redirects": "^1.10.0"
} }
}, },
"babel-loader": { "babel-loader": {
@@ -3409,6 +3409,11 @@
"assert-plus": "^1.0.0" "assert-plus": "^1.0.0"
} }
}, },
"date-format": {
"version": "3.0.0",
"resolved": "https://registry.npm.taobao.org/date-format/download/date-format-3.0.0.tgz",
"integrity": "sha1-64eANlx9KxURB4+0keZHl4DzrZU="
},
"dateformat": { "dateformat": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz", "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz",
@@ -4020,6 +4025,15 @@
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
}, },
"esdk-obs-nodejs": {
"version": "3.20.11",
"resolved": "https://registry.npm.taobao.org/esdk-obs-nodejs/download/esdk-obs-nodejs-3.20.11.tgz?cache=0&sync_timestamp=1610351636380&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fesdk-obs-nodejs%2Fdownload%2Fesdk-obs-nodejs-3.20.11.tgz",
"integrity": "sha1-/bMuzu3qoT+xLgmCcgg8yM6MIsE=",
"requires": {
"log4js": "^6.3.0",
"xml2js": "^0.4.23"
}
},
"eslint": { "eslint": {
"version": "6.8.0", "version": "6.8.0",
"resolved": "https://registry.npm.taobao.org/eslint/download/eslint-6.8.0.tgz", "resolved": "https://registry.npm.taobao.org/eslint/download/eslint-6.8.0.tgz",
@@ -5195,8 +5209,7 @@
"flatted": { "flatted": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz",
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==",
"dev": true
"integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA=="
}, },
"flatten": { "flatten": {
"version": "1.0.3", "version": "1.0.3",
@@ -5367,6 +5380,16 @@
"readable-stream": "^2.0.0" "readable-stream": "^2.0.0"
} }
}, },
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npm.taobao.org/fs-extra/download/fs-extra-8.1.0.tgz?cache=0&sync_timestamp=1611075469998&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffs-extra%2Fdownload%2Ffs-extra-8.1.0.tgz",
"integrity": "sha1-SdQ8RaiM2Wd2aMt74bRu/bjS4cA=",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"fs-minipass": { "fs-minipass": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
@@ -7700,6 +7723,14 @@
"minimist": "^1.2.5" "minimist": "^1.2.5"
} }
}, },
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/jsonfile/download/jsonfile-4.0.0.tgz?cache=0&sync_timestamp=1604161797011&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjsonfile%2Fdownload%2Fjsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
},
"jsprim": { "jsprim": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@@ -8184,6 +8215,18 @@
"chalk": "^2.4.2" "chalk": "^2.4.2"
} }
}, },
"log4js": {
"version": "6.3.0",
"resolved": "https://registry.npm.taobao.org/log4js/download/log4js-6.3.0.tgz",
"integrity": "sha1-EN+vu0NDUaPjAnegC5h5RG9xW8s=",
"requires": {
"date-format": "^3.0.0",
"debug": "^4.1.1",
"flatted": "^2.0.1",
"rfdc": "^1.1.4",
"streamroller": "^2.2.4"
}
},
"longest": { "longest": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
@@ -11821,6 +11864,11 @@
"resolved": "https://registry.npmjs.org/rework-visit/-/rework-visit-1.0.0.tgz", "resolved": "https://registry.npmjs.org/rework-visit/-/rework-visit-1.0.0.tgz",
"integrity": "sha1-mUWygD8hni96ygCtuLyfZA+ELJo=" "integrity": "sha1-mUWygD8hni96ygCtuLyfZA+ELJo="
}, },
"rfdc": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/rfdc/download/rfdc-1.2.0.tgz?cache=0&sync_timestamp=1610744108114&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Frfdc%2Fdownload%2Frfdc-1.2.0.tgz",
"integrity": "sha1-npiUJY9I8oS0PDFDxoBwpPNzuUk="
},
"rgb-regex": { "rgb-regex": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/rgb-regex/-/rgb-regex-1.0.1.tgz", "resolved": "https://registry.npmjs.org/rgb-regex/-/rgb-regex-1.0.1.tgz",
@@ -12428,6 +12476,23 @@
"resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz",
"integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==" "integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ=="
}, },
"streamroller": {
"version": "2.2.4",
"resolved": "https://registry.npm.taobao.org/streamroller/download/streamroller-2.2.4.tgz",
"integrity": "sha1-wZjO1C25QIamGTYIGHzoCl8rDlM=",
"requires": {
"date-format": "^2.1.0",
"debug": "^4.1.1",
"fs-extra": "^8.1.0"
},
"dependencies": {
"date-format": {
"version": "2.1.0",
"resolved": "https://registry.npm.taobao.org/date-format/download/date-format-2.1.0.tgz",
"integrity": "sha1-MdW16iEc9f12TNOLr50DPffhJc8="
}
}
},
"strict-uri-encode": { "strict-uri-encode": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
@@ -13983,6 +14048,11 @@
"os-name": "^3.1.0" "os-name": "^3.1.0"
} }
}, },
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npm.taobao.org/universalify/download/universalify-0.1.2.tgz?cache=0&sync_timestamp=1603179967633&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funiversalify%2Fdownload%2Funiversalify-0.1.2.tgz",
"integrity": "sha1-tkb2m+OULavOzJ1mOcgNwQXvqmY="
},
"unquote": { "unquote": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/unquote/-/unquote-1.1.1.tgz", "resolved": "https://registry.npmjs.org/unquote/-/unquote-1.1.1.tgz",
@@ -15035,6 +15105,20 @@
"repeat-string": "^1.5.2" "repeat-string": "^1.5.2"
} }
}, },
"xml2js": {
"version": "0.4.23",
"resolved": "https://registry.npm.taobao.org/xml2js/download/xml2js-0.4.23.tgz?cache=0&sync_timestamp=1599054229598&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fxml2js%2Fdownload%2Fxml2js-0.4.23.tgz",
"integrity": "sha1-oMaVFnUkIesqx1juTUzPWIQ+rGY=",
"requires": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
}
},
"xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npm.taobao.org/xmlbuilder/download/xmlbuilder-11.0.1.tgz",
"integrity": "sha1-vpuuHIoEbnazESdyY0fQrXACvrM="
},
"xtend": { "xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",


+ 1
- 0
package.json View File

@@ -19,6 +19,7 @@
"cssnano": "4.1.10", "cssnano": "4.1.10",
"domino": "2.1.5", "domino": "2.1.5",
"dropzone": "5.7.2", "dropzone": "5.7.2",
"esdk-obs-nodejs": "3.20.11",
"fast-glob": "3.2.2", "fast-glob": "3.2.2",
"file-loader": "6.0.0", "file-loader": "6.0.0",
"fomantic-ui": "2.8.4", "fomantic-ui": "2.8.4",


+ 1
- 1
templates/repo/cloudbrain/index.tmpl View File

@@ -198,7 +198,7 @@
<!-- 中间云脑和新建任务按钮 --> <!-- 中间云脑和新建任务按钮 -->
<div class="ui three column stack able grid"> <div class="ui three column stack able grid">
<div class="column"> <div class="column">
<h2>{{.i18n.Tr "repo.cloudbrain"}}</h2>
<h2>{{.i18n.Tr "repo.cloudbrain1"}}</h2>
</div> </div>


<div class="column"> <div class="column">


+ 3
- 0
templates/repo/datasets/index.tmpl View File

@@ -50,6 +50,7 @@
</div> </div>
</div> </div>


<!-- 左侧数据集显示区域 -->
<div class="ui divider"></div> <div class="ui divider"></div>
<div class="ui stackable grid"> <div class="ui stackable grid">
<div class="twelve wide column"> <div class="twelve wide column">
@@ -118,6 +119,8 @@
</div> </div>
</form> </form>
</div> </div>

<!-- 删除模态框 -->
<div class="ui small basic delete modal" id="data-dataset-delete-modal"> <div class="ui small basic delete modal" id="data-dataset-delete-modal">
<div class="ui icon header"> <div class="ui icon header">
<i class="trash icon"></i> <i class="trash icon"></i>


+ 68
- 3
templates/repo/header.tmpl View File

@@ -1,3 +1,8 @@
<style>
.ui.form .ui.button{
margin-bottom: 15px;
}
</style>
<div class="header-wrapper"> <div class="header-wrapper">
{{with .Repository}} {{with .Repository}}
<div class="ui container"> <div class="ui container">
@@ -140,12 +145,13 @@
{{end}} {{end}}


{{if .Permission.CanRead $.UnitTypeCloudBrain}} {{if .Permission.CanRead $.UnitTypeCloudBrain}}
<a class="{{if .PageIsCloudBrain}}active{{end}} item" href="{{.RepoLink}}/cloudbrain">
<a class="{{if .PageIsCloudBrain}}active{{end}} item cloudbrain">
{{svg "octicon-server" 16}} {{.i18n.Tr "repo.cloudbrain"}} {{svg "octicon-server" 16}} {{.i18n.Tr "repo.cloudbrain"}}
<span style="display:none" class="cloudbrain_link">{{.RepoLink}}</span>
</a> </a>
{{end}} {{end}}


<a class="{{if .PageIsBlockChain}}active{{end}} item " href="{{.RepoLink}}/blockchain">
<a class="{{if .PageIsBlockChain}}active{{end}} item ">
{{svg "octicon-law" 16}} {{svg "octicon-law" 16}}
{{.i18n.Tr "repo.balance"}} {{.i18n.Tr "repo.balance"}}
</a> </a>
@@ -163,4 +169,63 @@
{{end}} {{end}}
</div> </div>
<div class="ui tabs divider"></div> <div class="ui tabs divider"></div>
</div>
</div>

<div class="ui select_cloudbrain modal">
<div class="header">
云脑选择
</div>
<div class="content">
<div class="ui form" method="post">
<div class="grouped fields">
<label for="CloudBrain">选择您准备使用的云脑平台:</label>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="CloudBrain" checked tabindex="0" class="hidden" value="0">
<label>云脑1</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="CloudBrain" tabindex="0" class="hidden" value="1">
<label>云脑2</label>
</div>
</div>
</div>
<div class="actions">
<div class="ui positive right labeled icon button">
确定
<i class="checkmark icon"></i>
</div>
</div>
</div>
</div>


</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script>
$('.item.cloudbrain').click(function(){
$('.ui.select_cloudbrain.modal')
.modal('closable', false)
.modal('show');
// $('.ui.select_cloudbrain.modal').modal('show');
$('.ui.radio.checkbox').checkbox();

var repolink = $(".cloudbrain_link").text()
$(".ui.positive.right.icon.button").click(function(){
// 声明一个变量来接收以及获取单选框选择的情况
var checked_radio = $("input[type='radio']:checked").val()
console.log(checked_radio)
if(checked_radio=='0'){
window.location.href = repolink+'/cloudbrain'
}else if(checked_radio=='1'){
window.location.href = repolink+'/blockchain'
}else{

return;
}
})

})
</script>

+ 320
- 319
web_src/js/components/MinioUploader.vue View File

@@ -134,325 +134,326 @@ export default {
// }, 1000); // }, 1000);
}, },


computeMD5(file) {
this.resetStatus();
const blobSlice =
File.prototype.slice ||
File.prototype.mozSlice ||
File.prototype.webkitSlice,
chunkSize = 1024 * 1024 * 64,
chunks = Math.ceil(file.size / chunkSize),
spark = new SparkMD5.ArrayBuffer(),
fileReader = new FileReader();
let currentChunk = 0;

const time = new Date().getTime();
// console.log('计算MD5...')
this.status = this.dropzoneParams.data('md5-computing');
file.totalChunkCounts = chunks;
loadNext();

fileReader.onload = (e) => {
fileLoaded.call(this, e);
};
fileReader.onerror = (err) => {
console.warn('oops, something went wrong.', err);
file.cancel();
};

function fileLoaded(e) {
spark.append(e.target.result); // Append array buffer
currentChunk++;
if (currentChunk < chunks) {
// console.log(`第${currentChunk}分片解析完成, 开始第${currentChunk +1}/${chunks}分片解析`);
this.status = `${this.dropzoneParams.data('loading-file')} ${(
(currentChunk / chunks) *
100
).toFixed(2)}% (${currentChunk}/${chunks})`;
this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
loadNext();
return;
}

const md5 = spark.end();
console.log(
`MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${
file.size
} 用时:${(new Date().getTime() - time) / 1000} s`
);
spark.destroy(); // 释放缓存
file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识
file.cmd5 = false; // 取消计算md5状态
this.computeMD5Success(file);
}

function loadNext() {
const start = currentChunk * chunkSize;
const end =
start + chunkSize >= file.size ? file.size : start + chunkSize;
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
}
},

async computeMD5Success(md5edFile) {
const file = await this.getSuccessChunks(md5edFile);
try {
if (file.uploadID == '' || file.uuid == '') {
// 未上传过
await this.newMultiUpload(file);
if (file.uploadID != '' && file.uuid != '') {
file.chunks = '';
this.multipartUpload(file);
} else {
// 失败如何处理
return;
}
return;
}

if (file.uploaded == '1') {
// 已上传成功
// 秒传
if (file.attachID == '0') {
// 删除数据集记录,未删除文件
await addAttachment(file);
}
//不同数据集上传同一个文件
if (file.datasetID != '') {
if (Number(file.datasetID) != file.datasetId) {
var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")";
window.alert(info);
window.location.reload();
}
}
console.log('文件已上传完成');
this.progress = 100;
this.status = this.dropzoneParams.data('upload-complete');
this.finishUpload(file);
} else {
// 断点续传
this.multipartUpload(file);
}
} catch (error) {
this.emitDropzoneFailed(file);
console.log(error);
}

async function addAttachment(file) {
return await axios.post(
'/attachments/add',
qs.stringify({
uuid: file.uuid,
file_name: file.name,
size: file.size,
dataset_id: file.datasetId,
_csrf: csrf
})
);
}
},

async getSuccessChunks(file) {
const params = {
params: {
md5: file.uniqueIdentifier,
type: cloud_brain_type,
_csrf: csrf
}
};
try {
const response = await axios.get('/attachments/get_chunks', params);
file.uploadID = response.data.uploadID;
file.uuid = response.data.uuid;
file.uploaded = response.data.uploaded;
file.chunks = response.data.chunks;
file.attachID = response.data.attachID;
file.datasetID = response.data.datasetID;
file.datasetName = response.data.datasetName;
file.realName = response.data.fileName;
return file;
} catch (error) {
this.emitDropzoneFailed(file);
console.log('getSuccessChunks catch: ', error);
return null;
}
},

async newMultiUpload(file) {
const res = await axios.get('/attachments/new_multipart', {
params: {
totalChunkCounts: file.totalChunkCounts,
md5: file.uniqueIdentifier,
size: file.size,
fileType: file.type,
type: cloud_brain_type,
_csrf: csrf
}
});
file.uploadID = res.data.uploadID;
file.uuid = res.data.uuid;
},

multipartUpload(file) {
const blobSlice =
File.prototype.slice ||
File.prototype.mozSlice ||
File.prototype.webkitSlice,
chunkSize = 1024 * 1024 * 64,
chunks = Math.ceil(file.size / chunkSize),
fileReader = new FileReader(),
time = new Date().getTime();
let currentChunk = 0;

function loadNext() {
const start = currentChunk * chunkSize;
const end =
start + chunkSize >= file.size ? file.size : start + chunkSize;
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
}

function checkSuccessChunks() {
const index = successChunks.indexOf((currentChunk + 1).toString());
if (index == -1) {
return false;
}
return true;
}

async function getUploadChunkUrl(currentChunk, partSize) {
const res = await axios.get('/attachments/get_multipart_url', {
params: {
uuid: file.uuid,
uploadID: file.uploadID,
size: partSize,
chunkNumber: currentChunk + 1,
type: cloud_brain_type,
_csrf: csrf
}
});
urls[currentChunk] = res.data.url;
}

async function uploadMinio(url, e) {
const res = await axios.put(url, e.target.result);
etags[currentChunk] = res.headers.etag;
}

async function updateChunk(currentChunk) {
await axios.post(
'/attachments/update_chunk',
qs.stringify({
uuid: file.uuid,
chunkNumber: currentChunk + 1,
etag: etags[currentChunk],
_csrf: csrf
})
);
}

async function uploadPart(currentChunk, partSize, e) {
console.log(e);
let params = new FormData();
params.append("uuid", file.uuid);
params.append("uploadId", file.uploadID);
params.append("size", partSize);
params.append("chunkNumber", currentChunk + 1);
params.append("file", e.target.file);
params.append("_csrf", csrf);
return await axios.post('/attachments/upload_part',
params,
{headers: {'Content-Type': 'multipart/form-data'}}
);
}

async function uploadChunk(e) {
try {
if (!checkSuccessChunks()) {
const start = currentChunk * chunkSize;
const partSize =
start + chunkSize >= file.size ? file.size - start : chunkSize;
await uploadPart(currentChunk, partSize, e);

// 获取分片上传url
// await getUploadChunkUrl(currentChunk, partSize);
// if (urls[currentChunk] != '') {
// // 上传到minio
// await uploadMinio(urls[currentChunk], e);
// if (etags[currentChunk] != '') {
// // 更新数据库:分片上传结果
// //await updateChunk(currentChunk);
// } else {
// console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO
// }
// } else {
// console.log("uploadChunk urls[currentChunk] != ''");// TODO
// }

}
} catch (error) {
console.log(error);
this.emitDropzoneFailed(file);
}
}

async function completeUpload() {
return await axios.post(
'/attachments/complete_multipart',
qs.stringify({
uuid: file.uuid,
uploadID: file.uploadID,
file_name: file.name,
size: file.size,
dataset_id: file.datasetId,
type: cloud_brain_type,
_csrf: csrf
})
);
}

const successChunks = [];
let successParts = [];
successParts = file.chunks.split(',');
for (let i = 0; i < successParts.length; i++) {
successChunks[i] = successParts[i].split('-')[0];
}
const urls = []; // TODO const ?
const etags = [];
console.log('上传分片...');
this.status = this.dropzoneParams.data('uploading');
loadNext();
fileReader.onload = async (e) => {
await uploadChunk(e);
fileReader.abort();
currentChunk++;
if (currentChunk < chunks) {
console.log(
`第${currentChunk}个分片上传完成, 开始第${currentChunk +
1}/${chunks}个分片上传`
);
this.progress = Math.ceil((currentChunk / chunks) * 100);
this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
this.status = `${this.dropzoneParams.data('uploading')} ${(
(currentChunk / chunks) *
100
).toFixed(2)}%`;
await loadNext();
} else {
await completeUpload();
console.log(
`文件上传完成:${file.name} \n分片:${chunks} 大小:${
file.size
} 用时:${(new Date().getTime() - time) / 1000} s`
);
this.progress = 100;
this.status = this.dropzoneParams.data('upload-complete');
this.finishUpload(file);
}
};
}
}
};
</script>
// computeMD5(file) {
// this.resetStatus();
// const blobSlice =
// File.prototype.slice ||
// File.prototype.mozSlice ||
// File.prototype.webkitSlice,
// chunkSize = 1024 * 1024 * 64,
// chunks = Math.ceil(file.size / chunkSize),
// spark = new SparkMD5.ArrayBuffer(),
// fileReader = new FileReader();
// let currentChunk = 0;

// const time = new Date().getTime();
// // console.log('计算MD5...')
// this.status = this.dropzoneParams.data('md5-computing');
// file.totalChunkCounts = chunks;
// loadNext();

// fileReader.onload = (e) => {
// fileLoaded.call(this, e);
// };
// fileReader.onerror = (err) => {
// console.warn('oops, something went wrong.', err);
// file.cancel();
// };

// function fileLoaded(e) {
// spark.append(e.target.result); // Append array buffer
// currentChunk++;
// if (currentChunk < chunks) {
// // console.log(`第${currentChunk}分片解析完成, 开始第${currentChunk +1}/${chunks}分片解析`);
// this.status = `${this.dropzoneParams.data('loading-file')} ${(
// (currentChunk / chunks) *
// 100
// ).toFixed(2)}% (${currentChunk}/${chunks})`;
// this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
// loadNext();
// return;
// }

// const md5 = spark.end();
// console.log(
// `MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${
// file.size
// } 用时:${(new Date().getTime() - time) / 1000} s`
// );
// spark.destroy(); // 释放缓存
// file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识
// file.cmd5 = false; // 取消计算md5状态
// this.computeMD5Success(file);
// }

// function loadNext() {
// const start = currentChunk * chunkSize;
// const end =
// start + chunkSize >= file.size ? file.size : start + chunkSize;
// fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
// }
// },

// async computeMD5Success(md5edFile) {
// const file = await this.getSuccessChunks(md5edFile);
// try {
// if (file.uploadID == '' || file.uuid == '') {
// // 未上传过
// await this.newMultiUpload(file);
// if (file.uploadID != '' && file.uuid != '') {
// file.chunks = '';
// this.multipartUpload(file);
// } else {
// // 失败如何处理
// return;
// }
// return;
// }

// if (file.uploaded == '1') {
// // 已上传成功
// // 秒传
// if (file.attachID == '0') {
// // 删除数据集记录,未删除文件
// await addAttachment(file);
// }
// //不同数据集上传同一个文件
// if (file.datasetID != '') {
// if (Number(file.datasetID) != file.datasetId) {
// var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")";
// window.alert(info);
// window.location.reload();
// }
// }
// console.log('文件已上传完成');
// this.progress = 100;
// this.status = this.dropzoneParams.data('upload-complete');
// this.finishUpload(file);
// } else {
// // 断点续传
// this.multipartUpload(file);
// }
// } catch (error) {
// this.emitDropzoneFailed(file);
// console.log(error);
// }

// async function addAttachment(file) {
// return await axios.post(
// '/attachments/add',
// qs.stringify({
// uuid: file.uuid,
// file_name: file.name,
// size: file.size,
// dataset_id: file.datasetId,
// _csrf: csrf
// })
// );
// }
// },

// async getSuccessChunks(file) {
// const params = {
// params: {
// md5: file.uniqueIdentifier,
// type: cloud_brain_type,
// _csrf: csrf
// }
// };
// try {
// const response = await axios.get('/attachments/get_chunks', params);
// file.uploadID = response.data.uploadID;
// file.uuid = response.data.uuid;
// file.uploaded = response.data.uploaded;
// file.chunks = response.data.chunks;
// file.attachID = response.data.attachID;
// file.datasetID = response.data.datasetID;
// file.datasetName = response.data.datasetName;
// file.realName = response.data.fileName;
// return file;
// } catch (error) {
// this.emitDropzoneFailed(file);
// console.log('getSuccessChunks catch: ', error);
// return null;
// }
// },

// async newMultiUpload(file) {
// const res = await axios.get('/attachments/new_multipart', {
// params: {
// totalChunkCounts: file.totalChunkCounts,
// md5: file.uniqueIdentifier,
// size: file.size,
// fileType: file.type,
// type: cloud_brain_type,
// _csrf: csrf
// }
// });
// console.log("dsnjs", res)
// file.uploadID = res.data.uploadID;
// file.uuid = res.data.uuid;
// },

// multipartUpload(file) {
// const blobSlice =
// File.prototype.slice ||
// File.prototype.mozSlice ||
// File.prototype.webkitSlice,
// chunkSize = 1024 * 1024 * 64,
// chunks = Math.ceil(file.size / chunkSize),
// fileReader = new FileReader(),
// time = new Date().getTime();
// let currentChunk = 0;

// function loadNext() {
// const start = currentChunk * chunkSize;
// const end =
// start + chunkSize >= file.size ? file.size : start + chunkSize;
// fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
// }

// function checkSuccessChunks() {
// const index = successChunks.indexOf((currentChunk + 1).toString());
// if (index == -1) {
// return false;
// }
// return true;
// }

// // async function getUploadChunkUrl(currentChunk, partSize) {
// // const res = await axios.get('/attachments/get_multipart_url', {
// // params: {
// // uuid: file.uuid,
// // uploadID: file.uploadID,
// // size: partSize,
// // chunkNumber: currentChunk + 1,
// // type: cloud_brain_type,
// // _csrf: csrf
// // }
// // });
// // urls[currentChunk] = res.data.url;
// // }

// // async function uploadMinio(url, e) {
// // const res = await axios.put(url, e.target.result);
// // etags[currentChunk] = res.headers.etag;
// // }

// // async function updateChunk(currentChunk) {
// // await axios.post(
// // '/attachments/update_chunk',
// // qs.stringify({
// // uuid: file.uuid,
// // chunkNumber: currentChunk + 1,
// // etag: etags[currentChunk],
// // _csrf: csrf
// // })
// // );
// // }

// async function uploadPart(currentChunk, partSize, e) {
// console.log(e);
// let params = new FormData();
// params.append("uuid", file.uuid);
// params.append("uploadId", file.uploadID);
// params.append("size", partSize);
// params.append("chunkNumber", currentChunk + 1);
// params.append("file", e.target.file);
// params.append("_csrf", csrf);
// return await axios.post('/attachments/upload_part',
// params,
// {headers: {'Content-Type': 'multipart/form-data'}}
// );
// }

// async function uploadChunk(e) {
// try {
// if (!checkSuccessChunks()) {
// const start = currentChunk * chunkSize;
// const partSize =
// start + chunkSize >= file.size ? file.size - start : chunkSize;
// await uploadPart(currentChunk, partSize, e);

// // 获取分片上传url
// // await getUploadChunkUrl(currentChunk, partSize);
// // if (urls[currentChunk] != '') {
// // // 上传到minio
// // await uploadMinio(urls[currentChunk], e);
// // if (etags[currentChunk] != '') {
// // // 更新数据库:分片上传结果
// // //await updateChunk(currentChunk);
// // } else {
// // console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO
// // }
// // } else {
// // console.log("uploadChunk urls[currentChunk] != ''");// TODO
// // }

// }
// } catch (error) {
// console.log(error);
// this.emitDropzoneFailed(file);
// }
// }

// async function completeUpload() {
// return await axios.post(
// '/attachments/complete_multipart',
// qs.stringify({
// uuid: file.uuid,
// uploadID: file.uploadID,
// file_name: file.name,
// size: file.size,
// dataset_id: file.datasetId,
// type: cloud_brain_type,
// _csrf: csrf
// })
// );
// }

// const successChunks = [];
// let successParts = [];
// successParts = file.chunks.split(',');
// for (let i = 0; i < successParts.length; i++) {
// successChunks[i] = successParts[i].split('-')[0];
// }
// const urls = []; // TODO const ?
// const etags = [];
// console.log('上传分片...');
// this.status = this.dropzoneParams.data('uploading');
// loadNext();
// fileReader.onload = async (e) => {
// await uploadChunk(e);
// fileReader.abort();
// currentChunk++;
// if (currentChunk < chunks) {
// console.log(
// `第${currentChunk}个分片上传完成, 开始第${currentChunk +
// 1}/${chunks}个分片上传`
// );
// this.progress = Math.ceil((currentChunk / chunks) * 100);
// this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2));
// this.status = `${this.dropzoneParams.data('uploading')} ${(
// (currentChunk / chunks) *
// 100
// ).toFixed(2)}%`;
// await loadNext();
// } else {
// await completeUpload();
// console.log(
// `文件上传完成:${file.name} \n分片:${chunks} 大小:${
// file.size
// } 用时:${(new Date().getTime() - time) / 1000} s`
// );
// this.progress = 100;
// this.status = this.dropzoneParams.data('upload-complete');
// this.finishUpload(file);
// }
// };
// }
// }
// };
// </script>


<style> <style>
.dropzone-wrapper { .dropzone-wrapper {


Loading…
Cancel
Save