diff --git a/app.py b/app.py index 80a56bf53a702f98ccc3c06699b873b08afdf6d2..19cdb10459845a2968eca9d7e09775324f4c51fb 100644 --- a/app.py +++ b/app.py @@ -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/",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__': diff --git a/pycms.json b/pycms.json index 743d3b1d6729119219cbf9b9166a908f48620c14..865e788c102da88de960a790e4b14279c6a93f32 100644 --- a/pycms.json +++ b/pycms.json @@ -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 diff --git a/pycms2.json b/pycms2.json index 03f5db09bab29837e1c2c99954e9810087c6ad20..c2806ea5c8792cb1dfd47bc195fb494500f2885f 100644 --- a/pycms2.json +++ b/pycms2.json @@ -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 diff --git a/templates/index.html b/templates/index.html index 695989bd4697027dd7ba6bc8717e3cb66bf45ce7..fb5e80ae29b536b125e04cdb89b12bc5ef7d65f1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,14 +8,31 @@ dr_py首页 +

欢迎使用dr_py项目

可以简单的自定义爬虫实现cms数据接口

-
+ -
- 缓存文件列表 + + \ No newline at end of file diff --git a/templates/raw.html b/templates/raw.html new file mode 100644 index 0000000000000000000000000000000000000000..6cfe6ee7b0b6cd9a2ef769afe89000a845946003 --- /dev/null +++ b/templates/raw.html @@ -0,0 +1,61 @@ + + + + + + + + + 已缓存规则列表-{{rules.count}} + + + + + +{% if rules.count < 1 %} +

暂无已缓存的规则

+{% endif %} + +{% for rule in rules.list %} + + {% if rule|length > 2 %} + +
  • + + {{ rule }} +
  • + + {% else %} + +
  • + {{ rule }} +
  • + + {% endif %} + + + {% endfor %} + + + \ No newline at end of file diff --git a/utils/parser.py b/utils/parser.py index e3cb7ca9b3d6937d856d151420aaf19bc4acbc10..4552ba453099c6b2e02a614c9f28d6126d4b14bd 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -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)