提交 72e11600 编写于 作者: H hjdhnx

增加缓存文件查看接口

上级 4d0c204c
......@@ -102,19 +102,33 @@ def clear():
os.remove(cache_path)
return jsonify(error.success('成功删除文件:'+cache_path))
@app.route('/rules')
def rules():
# base_path = os.path.dirname(os.path.abspath(__file__))+'cache' # 当前文件所在目录
def getRules():
base_path = 'cache/' # 当前文件所在目录
print(base_path)
file_name = os.listdir(base_path)
file_name = list(filter(lambda x: str(x).endswith('.js'), file_name))
# print(file_name)
rule_list = [file.replace('.js', '') for file in file_name]
rules = {'list':rule_list,'count':len(rule_list)}
# print(rule_list)
# return jsonify(obj)
return render_template('rules.html',rules=rules)
rules = {'list': rule_list, 'count': len(rule_list)}
return rules
@app.route('/rules')
def rules():
return render_template('rules.html',rules=getRules())
@app.route('/raw')
def rules_raw():
return render_template('raw.html',rules=getRules())
@app.route("/plugin/<name>",methods=['GET'])
def plugin(name):
# name=道长影视模板.js
if not name or not name.split('.')[-1] in ['js','txt','py','json']:
return jsonify(error.failed(f'非法威胁,未指定文件名。必须包含js|txt|json|py'))
try:
return parser.toJs(name)
except Exception as e:
return jsonify(error.failed(f'非法猥亵\n{e}'))
if __name__ == '__main__':
......
......@@ -47,7 +47,7 @@
"key":"dr_ckmv",
"name":"cokemv(道长)",
"type":1,
"api":"http://cms.nokia.press/vod?rule=cokemv",
"api":"http://cms.nokia.press/vod?rule=cokemv&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/cokemv.js",
"searchable": 1,
"quickSearch": 1,
"filterable": 1
......
......@@ -48,7 +48,7 @@
"key":"dr_ckmv",
"name":"cokemv(道长)",
"type":1,
"api":"http://localhost:5705/vod?rule=cokemv",
"api":"http://localhost:5705/vod?rule=cokemv&ext=https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/cokemv.js",
"searchable": 1,
"quickSearch": 1,
"filterable": 1
......
......@@ -8,14 +8,31 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>dr_py首页</title>
</head>
<style>
.btn{
margin-bottom: 2rem;
border:1px solid #F00;
width: 180px;
height: 30px;
text-align: center;
background-color: #1379cb;
color: #ffffff;
}
.btn a{
color: #ffffff;
}
</style>
<body>
<h1>欢迎使用dr_py项目</h1>
<p>可以简单的自定义爬虫实现cms数据接口</p>
<div>
<div class="btn">
<a href="/clear?rule=">缓存清理接口</a>
</div>
<div>
<a href="/rules">缓存文件列表</a>
<div class="btn">
<a href="/rules">缓存文件列表-清除</a>
</div>
<div class="btn">
<a href="/raw">缓存文件列表-查看</a>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-siteapp;no-transform">
<meta name="applicable-device" content="pc,mobile">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>已缓存规则列表-{{rules.count}}</title>
<script src="/static/js/jquery.min.js"></script>
</head>
<style>
.red {
color:red;
font-weight: bold
}
.yellow {
color:yellow;
font-weight: bold
}
.refresh{
}
</style>
<body>
<script>
$(document).ready(function(){
$(".refresh").click(function(){
// location.reload();
let rule = this.innerText.trim();
location.href = '/plugin/'+rule+'.js';
});
});
</script>
{% if rules.count < 1 %}
<h3>暂无已缓存的规则</h3>
{% endif %}
{% for rule in rules.list %}
{% if rule|length > 2 %}
<!-- | 为过滤条件 -->
<li class="red">
<!-- <a class="refresh" href="/clear?rule={{rule}}" target="_blank">{{ rule }}</a>-->
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
</li>
{% else %}
<!-- 如果是if条件,最后必须要有else,否则就会报错 -->
<li class="yellow">
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
</li>
{% endif %}
<!-- if条件必须有endif,否则会报错 -->
{% endfor %}
</body>
</html>
\ No newline at end of file
......@@ -48,7 +48,8 @@ def runJs(jsPath):
def toJs(jsPath):
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录
js_path = os.path.join(base_path, jsPath)
js_path = os.path.join(base_path, f'cache/{jsPath}')
print(js_path)
if not os.path.exists(js_path):
return jsonify({'code': -2, 'msg': f'非法猥亵,文件不存在'})
with open(js_path, 'r', encoding='UTF-8') as fp:
......@@ -59,7 +60,7 @@ def toJs(jsPath):
def toHtml(jsPath):
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录
js_path = os.path.join(base_path, jsPath)
js_path = os.path.join(base_path, f'cache/{jsPath}')
with open(js_path, 'r', encoding='UTF-8') as fp:
js = fp.read()
response = make_response(js)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册