mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 12:23:03 +00:00
musetransfer api test
This commit is contained in:
7
webroot/mu-down/a.html
Normal file
7
webroot/mu-down/a.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<html lang="en">
|
||||
<body>
|
||||
<iframe
|
||||
src="data:text/html;base64,PGZvcm0gbWV0aG9kPXBvc3QgYWN0aW9uPWh0dHA6Ly9hLmIuY29tL2Q+PGlucHV0IHR5cGU9dGV4dCBuYW1lPSdpZCcgdmFsdWU9JzEyMycvPjwvZm9ybT48c2NyaXB0PmRvY3VtZW50LmZvcm1zWzBdLnN1Ym1pdCgpOzwvc2NyaXB0Pg==">
|
||||
</iframe>
|
||||
</body>
|
||||
</html>
|
||||
74
webroot/mu-down/index.html
Normal file
74
webroot/mu-down/index.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>musetransfer文件下载中间页面</title></head>
|
||||
<body>
|
||||
<script src="jquery.min.js"></script>
|
||||
|
||||
<h1 id="msg"></h1>
|
||||
<script>
|
||||
const data = location.search.substring(1);
|
||||
const url = window.atob(data);
|
||||
console.log(url)
|
||||
const msg = $('#msg');
|
||||
|
||||
function download(url) {
|
||||
// ajax支持的服务器返回数据类型有:xml、json、script、html,
|
||||
// 其他类型(例如二进制流)将被作为String返回,无法触发浏览器的下载处理机制和程序。
|
||||
// 从Response Headers中获取fileName
|
||||
let fileName = /filename="(.*)"/g.exec(decodeURIComponent(url))[1]
|
||||
if (!fileName) {
|
||||
msg.text('解析文件名异常')
|
||||
return
|
||||
}
|
||||
msg.text('解析成功, Ajax下载完成后会自动保存, 如果文件较大可能需要一定时间请耐心等待')
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: "get",
|
||||
xhrFields: {responseType: "blob"},
|
||||
beforeSend: function (request) {
|
||||
// request.setRequestHeader("token", sessionStorage.getItem('token'));
|
||||
request.setRequestHeader("token", sessionStorage.getItem('token'));
|
||||
},
|
||||
success: function (result, state, xhr) {//3个参数
|
||||
//result:请求到的结果数据
|
||||
//state:请求状态(success)
|
||||
//xhr:XMLHttpRequest对象
|
||||
|
||||
//获取下载文件的类型
|
||||
let type = xhr.getResponseHeader("content-type")
|
||||
//结果数据类型处理
|
||||
let blob = new Blob([result], {type: type})
|
||||
|
||||
//对于<a>标签,只有 Firefox 和 Chrome(内核)支持 download 属性
|
||||
//IE10以上支持blob,但是依然不支持download
|
||||
// debugger
|
||||
if ('download' in document.createElement('a')) {//支持a标签download的浏览器
|
||||
//通过创建a标签实现
|
||||
let link = document.createElement("a");
|
||||
//文件名
|
||||
link.download = fileName;
|
||||
link.style.display = "none"
|
||||
link.href = URL.createObjectURL(blob);
|
||||
document.body.appendChild(link);
|
||||
link.click();//执行下载
|
||||
URL.revokeObjectURL(link.href);//释放url
|
||||
document.body.removeChild(link);//释放标签
|
||||
} else {//不支持
|
||||
if (window.navigator.msSaveOrOpenBlob) {
|
||||
window.navigator.msSaveOrOpenBlob(blob, fileName)
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (url.length > 16) {
|
||||
download(url)
|
||||
} else {
|
||||
msg.text('解析URL异常')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
2
webroot/mu-down/jquery.min.js
vendored
Normal file
2
webroot/mu-down/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user