Skip to content

Commit

Permalink
简化部署步骤
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzhouprogram committed Aug 21, 2021
1 parent 7d07b28 commit b8b2b4f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
34 changes: 25 additions & 9 deletions index.html
Expand Up @@ -11,6 +11,7 @@
<meta name="description"
content="海外文件加速代下载,github加速下载,无限速及文件大小限制,支持任意文件直链下载,支持命令行代下。加速文件下载速度" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=0" />
<meta name="referrer" content="origin" />
</head>
<style>
* {
Expand Down Expand Up @@ -237,6 +238,12 @@
padding: 10px;
line-height: 20px;
}
.count-box-child {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 12px;
}
.scroll-content .box > p {
margin-bottom: 15px;
text-align: center;
Expand Down Expand Up @@ -299,28 +306,36 @@ <h1 class="header-top">
</div>
<div class="count-box">
<!-- <div>加速服务使用统计:</div> -->
<div>&nbsp;-&nbsp;今日加速:&nbsp;<span class="today"></span>&nbsp;次</div>
<div>&nbsp;-&nbsp;昨日加速:&nbsp;<span class="yesterday"></span>&nbsp;次</div>
<div>&nbsp;-&nbsp;总加速:&nbsp;<span class="total"></span>&nbsp;次</div>
<div class="count-box-child">&nbsp;-&nbsp;今日加速:&nbsp;<span class="today"></span>&nbsp;次</div>
<div class="count-box-child">&nbsp;-&nbsp;昨日加速:&nbsp;<span class="yesterday"></span>&nbsp;次</div>
<div class="count-box-child">&nbsp;-&nbsp;总加速:&nbsp;<span class="total"></span>&nbsp;次</div>
</div>
<div class="box">
<div class="tips">
<p>使用本站服务器加速前缀: <b style="color: #000">https://pd.zwc365.com/seturl/</b></p>
<p>使用本站服务器加速前缀: <b style="color: #000">https://pd.zwc365.com/</b></p>
<p>Cloudflare Workers 加速前缀: <b style="color: #000">https://pd.zwc365.com/cfworker/</b></p>
<p><b style="color: #000">支持命令行</b>,可在 Git Bash 中 clone,或终端 wget 代下(详情见项目说明)</p>
<p>CloudFlare 代下无速度及文件大小限制,服务器代下限制文件大小 2G</p>
<p>本站现在有 <a href="https://github.com/zwc456baby/file-proxy/tree/master/chrome-app">Chrome 扩展</a>
,安装扩展后,使用鼠标右键即可选择线路加速下载文件</p>
<p>Github 请在仓库页面点击绿色按钮: "Code" -> "Download Zip" 右键复制链接</p>
</div>
<p>欢迎小伙伴们 <b style="color: #000">收藏和分享</b> 本服务</p>
<p>
<b style="color: #000">一个小小的提示:</b>
</p>
<p>
<b style="color: #000">大量使用本站服务的用户,请部署CloudFlare下载节点,并添加节点</b>
</p>
<p>
<a href="https://zwc365.com/2020/09/24/file-proxy-download#%E5%A6%82%E4%BD%95%E9%83%A8%E7%BD%B2%E4%B8%8B%E8%BD%BD%E8%8A%82%E7%82%B9">点这里查看部署 CloudFlare 节点教程</a>
</p>
<div class="example">
<p>如果是网页使用,直接将原链接粘贴到输入框点击下载即可加速。</p>
<p>如果使用其他工具进行文件下载,则在原链接前新增加速前缀:</p>
<p>Git 项目加速:git clone https://pd.zwc365.com/seturl/< https 开头的项目地址></p>
<p>Wget 加速下载:wget https://pd.zwc365.com/seturl/<原来的文件链接></p>
<p>Git 项目加速:git clone https://pd.zwc365.com/< https 开头的项目地址></p>
<p>Wget 加速下载:wget https://pd.zwc365.com/<原来的文件链接></p>
<p>google 或 jcenter 仓库镜像:https://pd.zwc365.com/cfworker/<仓库地址></p>
<p>加速任意链接:https://pd.zwc365.com/seturl/<任意 http 或 https 链接></p>
<p>加速任意链接:https://pd.zwc365.com/<任意 http 或 https 链接></p>
</div>
<div class="urlexample">
<p>在后面拼接的URL必须是 <b style="color: #000">http://</b> 或者 <b style="color: #000">https://</b> 开头</p>
Expand All @@ -329,6 +344,7 @@ <h1 class="header-top">
<p>不合格的示例: github.com/zwc456baby/file-proxy/archive/master.zip</p>
<p>不合格的示例: www.baidu.com</p>
</div>
<p>欢迎小伙伴们 <b style="color: #000">收藏和分享</b> 本服务</p>
<p>开源地址:<a style="color: #3294ea" href="https://github.com/zwc456baby/file-proxy">file-proxy</a>
| 更多用法或捐赠:<a href="https://zwc365.com/2020/09/24/file-proxy-download">项目说明</a>
</p>
Expand Down Expand Up @@ -451,7 +467,7 @@ <h1 class="header-top">
xhr.send(null);
}
getCount();
setInterval(getCount, 60000);
setInterval(getCount, 2000);
</script>
<script type="text/javascript">
function checkUrl(instr) {
Expand Down
14 changes: 8 additions & 6 deletions index.js
Expand Up @@ -7,7 +7,9 @@ const ASSET_URL = 'https://pd.zwc365.com/'
// 前缀,如果自定义路由为example.com/gh/*,将PREFIX改为 '/gh/',注意,少一个杠都会错!
const PREFIX = '/cfdownload/'
// cloudflare workers 的链接,用来识别正确的 referer
const CF_URL = 'https://twilight-lab-22b6.zhouzhou-program.workers.dev'
// 此配置已经不再需要。之前的部署教程中提到了此配置,故而依旧留在此处
// 使用最新的文件部署,可以忽略此处配置
const CF_URL = ''
// git使用cnpmjs镜像、分支文件使用jsDelivr镜像的开关,0为关闭,默认开启
const Config = {
jsdelivr: 1,
Expand Down Expand Up @@ -84,14 +86,14 @@ async function fetchHandler(e) {
const exp4 = /^(?:https?:\/\/)?raw\.githubusercontent\.com\/.+?\/.+?\/.+?\/.+$/i

if (path.search(exp1) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) {
return httpHandler(req, path)
return httpHandler(req, urlObj, path)
} else if (path.search(exp2) === 0) {
if (Config.jsdelivr){
const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh')
return Response.redirect(newUrl, 302)
}else{
path = path.replace('/blob/', '/raw/')
return httpHandler(req, path)
return httpHandler(req, urlObj, path)
}
} else if (path.search(exp3) === 0) {
const newUrl = path.replace(/^(?:https?:\/\/)?github\.com/, 'https://github.com.cnpmjs.org')
Expand All @@ -104,7 +106,7 @@ async function fetchHandler(e) {
if (path === '' || path === '/') {
return new Response("success", {status: 200})
}
return httpHandler(req, path)
return httpHandler(req, urlObj, path)
}
}

Expand All @@ -113,7 +115,7 @@ async function fetchHandler(e) {
* @param {Request} req
* @param {string} pathname
*/
function httpHandler(req, pathname) {
function httpHandler(req, reqUrlObj, pathname) {
console.log("http handler")
const reqHdrRaw = req.headers

Expand All @@ -128,7 +130,7 @@ function httpHandler(req, pathname) {

const reqHdrNew = new Headers(reqHdrRaw)

const fullReqUrl = CF_URL + PREFIX
const fullReqUrl = reqUrlObj.origin + PREFIX
if (reqHdrNew.get('Referer') && reqHdrNew.get('Referer').indexOf(fullReqUrl) == 0){
reqHdrNew.set('Referer', reqHdrNew.get('Referer').substr(fullReqUrl.length))
}
Expand Down

0 comments on commit b8b2b4f

Please sign in to comment.