fix: not encode file name. fix: sha1 big file.

pull/276/head
qkqpttgf 2021-03-13 13:47:46 +08:00 committed by GitHub
parent 119ac5280d
commit 377a9f8aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 74 additions and 58 deletions

View File

@ -954,7 +954,7 @@
getuplink(i); getuplink(i);
} }
} }
xhr1.send('upbigfilename='+ encodeURIComponent(upbigfilename) +'&filesize='+ file.size +'&filelastModified='+ file.lastModified +'&filemd5='+ filemd5); xhr1.send('upbigfilename='+ upbigfilename +'&filesize='+ file.size +'&filelastModified='+ file.lastModified +'&filemd5='+ filemd5);
<!--GuestStart--> <!--GuestStart-->
} }
} }
@ -1111,69 +1111,85 @@
return; return;
}*/ }*/
var upbigfilename = encodeURIComponent((file.webkitRelativePath||file.name)); var upbigfilename = encodeURIComponent((file.webkitRelativePath||file.name));
var spark = sha1.create();
var reader = new FileReader(); var reader = new FileReader();
reader.onprogress = function(e) { var chunksize=10*1024*1024;
td2.innerText = '计算SHA1... ' + (e.loaded*100/file.size).toFixed(2) + " %"; var asize = 0;
var filesha1;
function readblob(start) {
var end=start+chunksize;
var blob = file.slice(start,end);
reader.readAsArrayBuffer(blob);
} }
reader.onload = function(e) { readblob(asize);
var filesha1 = sha1(this.result);
<!--GuestStart--> reader.onload = function(e){
function getext(str) { td2.innerHTML='<!--constStr@Calculate--> SHA1: '+(asize*100/file.size).toFixed(2)+'%';
let p = str.lastIndexOf('.'); var binary = this.result;
if (p===-1) return ''; spark.update(binary);
if (p===0) return ''; asize += chunksize;
return str.substr(p); if (asize < file.size) {
} readblob(asize);
var ext = getext(file.webkitRelativePath||file.name);
upbigfilename = filesha1 + ext;
<!--GuestEnd-->
while (upbigfilename.indexOf('%2F')>0) upbigfilename = upbigfilename.replace('%2F', '/');
td2.innerHTML='<!--constStr@GetUploadLink--> ...';
var html = JSON.parse(localStorage.getItem(filesha1));
//console.log(html);
if (html!==null && ('part_info_list' in html)) {
td2.innerHTML='<!--constStr@UploadStart--> ...';
binupfile(file, html, timea+'_'+i, upbigfilename, filesha1, chunksize);
} else { } else {
var xhr1 = new XMLHttpRequest(); filesha1 = spark.hex();
xhr1.open("POST", '?action=upbigfile'); td2.innerHTML='SHA1: ' + filesha1;
//xhr1.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8"); <!--GuestStart-->
xhr1.setRequestHeader('x-requested-with','XMLHttpRequest'); function getext(str) {
xhr1.onload = function(e){ let p = str.lastIndexOf('.');
//console.log(xhr1.status+xhr1.responseText); if (p===-1) return '';
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font>'; if (p===0) return '';
if (xhr1.status==201) { return str.substr(p);
if (xhr1.responseText=='') { }
getuplink(i,1); var ext = getext(file.webkitRelativePath||file.name);
return; upbigfilename = filesha1 + ext;
} <!--GuestEnd-->
var html=JSON.parse(xhr1.responseText); while (upbigfilename.indexOf('%2F')>0) upbigfilename = upbigfilename.replace('%2F', '/');
//console.log(html); td2.innerHTML='<!--constStr@GetUploadLink--> ...';
if (!html['part_info_list']) { var html = JSON.parse(localStorage.getItem(filesha1));
if (html.name!='') { //console.log(html);
if (html.exist==true) td2.innerHTML=html.name+' 文件名已有'; if (html!==null && ('part_info_list' in html)) {
else if (html.rapid_upload==true) td2.innerHTML=html.name+' 秒传'; td2.innerHTML='<!--constStr@UploadStart--> ...';
else td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>'; binupfile(file, html, timea+'_'+i, upbigfilename, filesha1, chunksize);
td1.innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+td1.innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>'; } else {
} else { var xhr1 = new XMLHttpRequest();
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>'; xhr1.open("POST", '?action=upbigfile');
} //xhr1.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
} else { xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
td2.innerHTML='<!--constStr@UploadStart--> ...'; xhr1.onload = function(e){
//console.log(html); //console.log(xhr1.status+xhr1.responseText);
localStorage.setItem(filesha1, JSON.stringify(html)); td2.innerHTML='<font color="red">'+xhr1.responseText+'</font>';
binupfile(file, html, timea+'_'+i, upbigfilename, filesha1, chunksize); if (xhr1.status==201) {
} if (xhr1.responseText=='') {
} getuplink(i,1);
if (i<files.length-1) { return;
i++; }
getuplink(i); var html=JSON.parse(xhr1.responseText);
} //console.log(html);
if (!html['part_info_list']) {
if (html.name!='') {
if (html.exist==true) td2.innerHTML=html.name+' 文件名已有';
else if (html.rapid_upload==true) td2.innerHTML=html.name+' 秒传';
else td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>';
td1.innerHTML='<div style="color:green"><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'?preview" id="upfile_a_'+tdnum+'" target="_blank">'+td1.innerHTML+'</a><br><a href="<!--base_disk_path--><!--Path-->'+upbigfilename+'" id="upfile_a1_'+tdnum+'"></a><!--constStr@UploadComplete--><button onclick="CopyAllDownloadUrl(\'#upfile_a1_'+tdnum+'\');" id="upfile_cpbt_'+tdnum+'" <!--AdminStart--> style="display:none"<!--AdminEnd--> ><!--constStr@CopyUrl--></button></div>';
} else {
td2.innerHTML='<font color="red">'+xhr1.responseText+'</font><br>';
}
} else {
td2.innerHTML='<!--constStr@UploadStart--> ...';
//console.log(html);
localStorage.setItem(filesha1, JSON.stringify(html));
binupfile(file, html, timea+'_'+i, upbigfilename, filesha1, chunksize);
}
}
if (i<files.length-1) {
i++;
getuplink(i);
}
}
xhr1.send('upbigfilename='+ upbigfilename +'&filesize='+ file.size +'&filelastModified='+ file.lastModified + '&filesha1=' + filesha1 + '&chunksize=' + chunksize);
} }
xhr1.send('upbigfilename='+ encodeURIComponent(upbigfilename) +'&filesize='+ file.size +'&filelastModified='+ file.lastModified + '&filesha1=' + filesha1 + '&chunksize=' + chunksize);
} }
} }
reader.readAsArrayBuffer(file);
} }
uploadbuttonshow(); uploadbuttonshow();
} }