mirror of https://github.com/hunshcn/gh-proxy
add size_limit
parent
9963eab51c
commit
b9ce795818
|
@ -7,6 +7,10 @@ github release、archive以及项目文件的加速项目,支持clone,有Clo
|
||||||
|
|
||||||
[https://gh.api.99988866.xyz/](https://gh.api.99988866.xyz/)
|
[https://gh.api.99988866.xyz/](https://gh.api.99988866.xyz/)
|
||||||
|
|
||||||
|
## python版本和cf worker版本差异
|
||||||
|
|
||||||
|
- python版本支持进行文件大小限制,超过设定返回原地址 [issue #8](https://github.com/hunshcn/gh-proxy/issues/8)
|
||||||
|
|
||||||
## 使用
|
## 使用
|
||||||
|
|
||||||
直接在copy出来的url前加`https://gh.api.99988866.xyz/`即可
|
直接在copy出来的url前加`https://gh.api.99988866.xyz/`即可
|
||||||
|
|
|
@ -8,12 +8,12 @@ from flask import Flask, Response, redirect, request
|
||||||
# git使用cnpmjs镜像、分支文件使用jsDelivr镜像的开关,0为关闭,默认开启
|
# git使用cnpmjs镜像、分支文件使用jsDelivr镜像的开关,0为关闭,默认开启
|
||||||
jsdelivr = 1
|
jsdelivr = 1
|
||||||
cnpmjs = 1
|
cnpmjs = 1
|
||||||
|
size_limit = 1024 * 1024 * 1024 * 999 # 允许的文件大小,默认999GB,相当于无限制了 https://github.com/hunshcn/gh-proxy/issues/8
|
||||||
HOST = '127.0.0.1' # 监听地址,建议监听本地然后由web服务器反代
|
HOST = '127.0.0.1' # 监听地址,建议监听本地然后由web服务器反代
|
||||||
PORT = 80 # 监听端口
|
PORT = 80 # 监听端口
|
||||||
ASSET_URL = 'https://hunshcn.github.io/gh-proxy' # 主页
|
ASSET_URL = 'https://hunshcn.github.io/gh-proxy' # 主页
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.debug = True
|
|
||||||
CHUNK_SIZE = 1024 * 10
|
CHUNK_SIZE = 1024 * 10
|
||||||
index_html = requests.get(ASSET_URL, timeout=10).text
|
index_html = requests.get(ASSET_URL, timeout=10).text
|
||||||
exp1 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:releases|archive)/.*$')
|
exp1 = re.compile(r'^(?:https?://)?github\.com/.+?/.+?/(?:releases|archive)/.*$')
|
||||||
|
@ -60,9 +60,12 @@ def proxy(u):
|
||||||
headers = dict(r.headers)
|
headers = dict(r.headers)
|
||||||
try:
|
try:
|
||||||
headers.pop('Transfer-Encoding')
|
headers.pop('Transfer-Encoding')
|
||||||
except:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if int(r.headers['Content-length']) > size_limit:
|
||||||
|
return redirect(u + request.url.replace(request.base_url, '', 1))
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
for chunk in r.iter_content(chunk_size=CHUNK_SIZE):
|
for chunk in r.iter_content(chunk_size=CHUNK_SIZE):
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
Loading…
Reference in New Issue