forked from mengzonefire/baidupan-rapidupload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.html
140 lines (122 loc) · 7.34 KB
/
gen.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no" />
<title>百度网盘秒传链接生成</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.0.2/css/bootstrap.min.css" />
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.0.2/js/bootstrap.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<div id="app">
<div id="container" class="container">
<div class="row">
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<h1>百度网盘秒传链接生成</h1>
<p id="version">v0.6 mengzonefire version</p>
<p><b>请先阅读 <a href='./manual.html' target=_blank>使用教程</b></a></br></p>
<p><a href='./index.html'>秒传转存</a> <a href='./multisave.html'>批量转存</a> <a
href='./convert.html'>秒传转换</a></p>
<p><b>支持批量生成, 需要在度盘中存在相同文件才能使秒传生效!</b></p>
</div>
<div class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<input id=file type=file placeholder="select a file" multiple>
<p id=log style="margin-top: 15px;"></p>
<script src="https://cdn.staticfile.org/spark-md5/3.0.2/spark-md5.min.js"></script>
<script>
document.getElementById("file").addEventListener("change", function () {
var file_amount = file.files.length;
calculate(file.files, file_amount, 0);
})
function slicemd5(files, file_amount, file_index, file_md5) {
var file = files[file_index],
fileReader = new FileReader(),
blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype
.slice,
chunkSize = 262144,
// read in chunks of 256KB
chunks = Math.ceil(1),
currentChunk = 0,
spark = new SparkMD5();
fileReader.onload = function (e) {
spark.appendBinary(e.target.result); // append binary string
currentChunk++;
if (currentChunk < chunks) {
loadNext();
} else {
addBdlink(spark.end());
calculate(files, file_amount, file_index + 1);
}
};
function loadNext() {
var start = currentChunk * chunkSize,
end = start + chunkSize >= file.size ? file.size : start + chunkSize;
fileReader.readAsBinaryString(blobSlice.call(file, start, end));
};
function addBdlink(slicemd5) {
document.body.appendChild(document.createElement(
'input')).id = 'link' + file_index;
document.getElementById('link' + file_index).type = 'hidden';
document.getElementById('link' + file_index).setAttribute(
'value', slicemd5);
var file_length = file.size;
var file_name = file.name;
var slice_md5 = document.getElementById('link' + file_index).value;
var link = file_md5 + '#' + slice_md5 + '#' + file_length +
'#' + file_name
document.getElementById('link').innerHTML += link +
'\n';
document.body.removeChild(document.getElementById(
'link' + file_index));
}
loadNext();
}
function calculate(files, file_amount, file_index) {
if (file_index == file_amount) {
document.getElementById('log').innerHTML = '生成完成, 共 ' + file_amount +
' 个文件';
return;
}
var file = files[file_index],
fileReader = new FileReader(),
blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype
.slice,
chunkSize = 2097152,
// read in chunks of 2MB
chunks = Math.ceil(file.size / chunkSize),
currentChunk = 0,
spark = new SparkMD5();
fileReader.onload = function (e) {
spark.appendBinary(e.target.result); // append binary string
currentChunk++;
if (currentChunk < chunks) {
loadNext();
} else {
slicemd5(files, file_amount, file_index, spark.end());
}
};
function loadNext() {
var start = currentChunk * chunkSize,
end = start + chunkSize >= file.size ? file.size : start + chunkSize;
fileReader.readAsBinaryString(blobSlice.call(file, start, end));
document.getElementById('log').innerHTML = '正在生成第 ' + (file_index + 1) + '/' +
file_amount + ' 个文件 ' + ((currentChunk / chunks) * 100).toFixed() + '%';
};
loadNext();
}
</script>
</div>
<div id="body" class="col-sm-8 offset-sm-2 col-md-6 offset-md-3 text-center">
<div class="form-group">
<label for="link">秒传链接</label>
<textarea name="link" id="link" class="form-control" placeholder="生成的链接 " rows="8"></textarea>
</div>
<b>所有请求在用户端进行,服务器不保存任何数据</b>
</div>
</div>
</div>
</div>
</body>