This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
forked from moeloli/baidupan-rapidupload
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathgen.html
122 lines (110 loc) · 5.15 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
<!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>
<meta name="description" content="百度网盘秒传链接在线转存/生成/转换,支持iOS/Android/PC and more">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.2.0/css/bootstrap.min.css">
</head>
<body>
<div 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">v1.5 mengzonefire version</p>
<p><b>请先阅读 <a href="./manual.html" target="_blank">使用教程</a></b><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>
</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>
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.2.0/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/spark-md5/3.0.2/spark-md5.min.js"></script>
<script>
$('#file').on('change', () => {
const file_amount = file.files.length;
calculate(file.files, file_amount, 0);
})
function slicemd5(files, file_amount, file_index, file_md5) {
const 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),
spark = new SparkMD5();
let currentChunk = 0;
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() {
const 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}`;
$(`#link${file_index}`).prop('type', 'hidden');
$(`#link${file_index}`).val(slicemd5);
const file_length = file.size;
const file_name = file.name;
const slice_md5 = $(`#link${file_index}`).val();
const link = `${file_md5}#${slice_md5}#${file_length}#${file_name}`
$('#link').append(`${link}\n`);
document.body.removeChild($(`#link${file_index}`)[0]);
}
loadNext();
}
function calculate(files, file_amount, file_index) {
if (file_index === file_amount) {
$('#log').html(`生成完成, 共 ${file_amount} 个文件`);
return;
}
const 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),
spark = new SparkMD5();
let currentChunk = 0;
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() {
const start = currentChunk * chunkSize,
end = start + chunkSize >= file.size ? file.size : start + chunkSize;
fileReader.readAsBinaryString(blobSlice.call(file, start, end));
$('#log').html(`正在生成第 ${file_index + 1}/${file_amount} 个文件 ${((currentChunk / chunks) * 100).toFixed()}%`);
}
loadNext();
}
</script>
</body>
</html>