From 3f3eda6c1eac9058131f687e80787bedd1d62e4e Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Sat, 27 Aug 2022 22:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=A3=E7=A1=AE=E8=8E=B7?= =?UTF-8?q?=E5=8F=96ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 27 ++++++++++++++++++++++++++- models/rule_classes.py | 4 ++++ templates/raw.html | 24 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index d942d2f..35f9799 100644 --- a/app.py +++ b/app.py @@ -132,6 +132,27 @@ def getRules(path='cache'): rules = {'list': rule_list, 'count': len(rule_list)} return rules +def getClasses(): + if not db: + msg = '未提供数据库连接' + logger.info(msg) + return [] + res = db.session.query(RuleClass).all() + return [rc.name for rc in res] + +def getClassInfo(cls): + if not db: + msg = f'未提供数据库连接,获取{cls}详情失败' + logger.info(msg) + return None + logger.info(f'开始查询{cls}的分类详情') + res = db.session.query(RuleClass).filter(RuleClass.name == cls).first() + if res: + logger.info(str(res)) + return str(res) + else: + return f'数据库不存在{cls}的分类缓存' + @app.route('/favicon.ico') # 设置icon def favicon(): @@ -139,6 +160,10 @@ def favicon(): # 对于当前文件所在路径,比如这里是static下的favicon.ico return send_from_directory(os.path.join(app.root_path, 'static'), 'img/favicon.svg', mimetype='image/vnd.microsoft.icon') +@app.route('/cls/') +def getClassInfoApi(cls): + info = getClassInfo(cls) + return jsonify({'msg':info}) @app.route('/rules') def rules(): @@ -146,7 +171,7 @@ def rules(): @app.route('/raw') def rules_raw(): - return render_template('raw.html',rules=getRules()) + return render_template('raw.html',rules=getRules(),classes=getClasses()) @app.route('/config/') def config_render(mode): diff --git a/models/rule_classes.py b/models/rule_classes.py index 149fcf0..368acf4 100644 --- a/models/rule_classes.py +++ b/models/rule_classes.py @@ -16,6 +16,10 @@ def init(db): class_name = db.Column(db.String(255)) class_url = db.Column(db.String(255)) + def __repr__(self): + return "" % ( + self.name, self.class_name, self.class_url) + # db.create_all() db.create_all() return RuleClass \ No newline at end of file diff --git a/templates/raw.html b/templates/raw.html index a55e6b0..c538fd1 100644 --- a/templates/raw.html +++ b/templates/raw.html @@ -31,9 +31,16 @@ let rule = this.innerText.trim(); location.href = '/plugin/'+rule+'.js'; }); + + $(".cls").click(function(){ + // location.reload(); + let cls = this.innerText.trim(); + location.href = '/cls/'+cls; + }); }); +

缓存规则列表

{% if rules.count < 1 %}

暂无已缓存的规则

{% endif %} @@ -57,6 +64,23 @@ {% endfor %} +

缓存分类列表

+{% if classes|length < 1 %} +

暂无已缓存的分类

+{% endif %} +{% for cls in classes %} + {% if cls|length > 2 %} +
  • + {{ cls }} +
  • + + {% else %} +
  • + {{ cls }} +
  • + + {% endif %} + {% endfor %} \ No newline at end of file -- GitLab