via:https://www.onesrc.cn/p/using-cloudflare-to-write-a-download-assistant.html
demo:
https://proxy.onesrc.workers.dev/
下载走 cloudflare,支持断点续传,mime 响应与原链接一致。
但不支持非直链下载。
例如 Github 下载速度过慢,可使用本工具加速。
代码示例
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const html = `
<html><head></head><body>
<input type="url" placeholder="url" id="url" style="width: 80%; display: block;">
<input type="submit" id="submit" value="submit"/>
<div id="res"></div>
<a id="a" href=""></a>
<div>注:该工具只针对直链有效</div>
<script>
document.getElementById('submit').onclick=function(){
let url = document.getElementById('url').value;
console.log('url: '+url);
let a = document.getElementById('a');
let div = document.getElementById('res');
if(!url || !url.startsWith('http')){
div.textContent="链接不合法: "+url;
a.style="display:none";
}else{
div.textContent="";
let res = (new URL(window.location.href)).origin+'?url='+encodeURIComponent(url);
a.textContent=res;
a.href=res;
a.style="";
}
}
</script>
</body></html>`;
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
let url = (new URL(request.url)).searchParams.get('url');
if (!url) {
return new Response(html, { status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' } });
}
let r = request.headers.get('Range');
console.log(r);
return await fetch(url, {
headers: {
range: r || 'bytes=0-'
}
});
}
最后于 20/01.28 16:16
被zsxwz编辑
,原因:
上一篇:
OLAINDEX魔改版—支持挂载多个onedrive下一篇:
谷歌浏览器全局媒体播放控件