From 377a9f8aaabd91f130b8406262bb99b493b2f04d Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Sat, 13 Mar 2021 13:47:46 +0800
Subject: [PATCH] fix: not encode file name. fix: sha1 big file.
---
theme/classic.html | 132 +++++++++++++++++++++++++--------------------
1 file changed, 74 insertions(+), 58 deletions(-)
diff --git a/theme/classic.html b/theme/classic.html
index e9747d5..0be7935 100644
--- a/theme/classic.html
+++ b/theme/classic.html
@@ -954,7 +954,7 @@
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);
}
}
@@ -1111,69 +1111,85 @@
return;
}*/
var upbigfilename = encodeURIComponent((file.webkitRelativePath||file.name));
+ var spark = sha1.create();
var reader = new FileReader();
- reader.onprogress = function(e) {
- td2.innerText = '计算SHA1... ' + (e.loaded*100/file.size).toFixed(2) + " %";
+ var chunksize=10*1024*1024;
+ 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) {
- var filesha1 = sha1(this.result);
-
- function getext(str) {
- let p = str.lastIndexOf('.');
- if (p===-1) return '';
- if (p===0) return '';
- return str.substr(p);
- }
- var ext = getext(file.webkitRelativePath||file.name);
- upbigfilename = filesha1 + ext;
-
- while (upbigfilename.indexOf('%2F')>0) upbigfilename = upbigfilename.replace('%2F', '/');
- td2.innerHTML=' ...';
- var html = JSON.parse(localStorage.getItem(filesha1));
- //console.log(html);
- if (html!==null && ('part_info_list' in html)) {
- td2.innerHTML=' ...';
- binupfile(file, html, timea+'_'+i, upbigfilename, filesha1, chunksize);
+ readblob(asize);
+
+ reader.onload = function(e){
+ td2.innerHTML=' SHA1: '+(asize*100/file.size).toFixed(2)+'%';
+ var binary = this.result;
+ spark.update(binary);
+ asize += chunksize;
+ if (asize < file.size) {
+ readblob(asize);
} else {
- var xhr1 = new XMLHttpRequest();
- xhr1.open("POST", '?action=upbigfile');
- //xhr1.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
- xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
- xhr1.onload = function(e){
- //console.log(xhr1.status+xhr1.responseText);
- td2.innerHTML=''+xhr1.responseText+'';
- if (xhr1.status==201) {
- if (xhr1.responseText=='') {
- getuplink(i,1);
- return;
- }
- 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=''+xhr1.responseText+'
';
- td1.innerHTML='