From c69bbe3eca28679ebacf5b39cba3c6969ae6d6a1 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Sat, 30 May 2020 15:00:13 +0800
Subject: [PATCH] guest calculate md5 before upload
---
theme/classic.html | 98 ++++++++++++++++++++++++----------------------
1 file changed, 52 insertions(+), 46 deletions(-)
diff --git a/theme/classic.html b/theme/classic.html
index efebcb5..8bf93ef 100644
--- a/theme/classic.html
+++ b/theme/classic.html
@@ -821,20 +821,55 @@
tr1.setAttribute('data-to',1);
var td1=document.createElement('td');
tr1.appendChild(td1);
- td1.setAttribute('style','width:30%');
+ td1.setAttribute('style','width:30%;word-break:break-word;');
td1.setAttribute('id','upfile_td1_'+timea+'_'+i);
td1.innerHTML=(file.webkitRelativePath||file.name)+'
'+size_format(file.size);
var td2=document.createElement('td');
tr1.appendChild(td2);
td2.setAttribute('id','upfile_td2_'+timea+'_'+i);
- td2.innerHTML=' ...';
if (file.size>100*1024*1024*1024) {
td2.innerHTML='';
uploadbuttonshow();
return;
}
+ upbigfilename = encodeURIComponent((file.webkitRelativePath||file.name));
+
+ function getext(str) {
+ strarry=str.split('.');
+ ext=strarry[strarry.length-1].toLowerCase();
+ var reg = new RegExp(".","g");
+ var a = str.replace(reg,"");
+ if (a == ext) ext = "";
+ else ext = "." + ext;
+ return ext;
+ }
+ var ext = getext(file.webkitRelativePath||file.name);
+ var spark = new SparkMD5.ArrayBuffer();
+ var reader = new FileReader();
+ var chunksize=10*1024*1024;
+ var asize = 0;
+ function readblob(start) {
+ var end=start+chunksize;
+ var blob = file.slice(start,end);
+ reader.readAsArrayBuffer(blob);
+ }
+ readblob(asize);
+
+ reader.onload = function(e){
+ td2.innerHTML=' md5: '+(asize*100/file.size).toFixed(2)+'%';
+ var binary = this.result;
+ spark.append(binary);
+ asize += chunksize;
+ if (asize < file.size) {
+ readblob(asize);
+ } else {
+ var filemd5 = spark.end();
+ td2.innerHTML='md5: '+filemd5;
+ upbigfilename = filemd5+ext;
+
+ td2.innerHTML=' ...';
var xhr1 = new XMLHttpRequest();
- xhr1.open("GET", '?action=upbigfile&upbigfilename='+ encodeURIComponent((file.webkitRelativePath||file.name)) +'&filesize='+ file.size +'&lastModified='+ file.lastModified);
+ xhr1.open("GET", '?action=upbigfile&upbigfilename='+ upbigfilename +'&filesize='+ file.size +'&lastModified='+ file.lastModified);
xhr1.setRequestHeader('x-requested-with','XMLHttpRequest');
xhr1.send(null);
xhr1.onload = function(e){
@@ -847,14 +882,23 @@
uploadbuttonshow();
} else {
td2.innerHTML=' ...';
- binupfile(file,html['uploadUrl'],timea+'_'+i);
+ binupfile(file,html['uploadUrl'],timea+'_'+i, upbigfilename);
}
}
+ if (xhr1.status==409) {
+ td2.innerHTML='md5: '+filemd5;
+ tdnum = timea+'_'+i;
+ document.getElementById('upfile_td1_'+tdnum).innerHTML='