layui.py 1.9 KB
Newer Older
H
hjdhnx 已提交
1 2 3 4 5 6 7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : layui.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2022/9/14

from flask import Blueprint,request,render_template,jsonify,make_response,redirect
H
hjdhnx 已提交
8
from utils.web import getParmas,get_interval,layuiBack,verfy_token
H
hjdhnx 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
from utils.cfg import cfg
from controllers.service import storage_service
from utils.system import getHost
from utils.files import getCustonDict,custom_merge
from utils.encode import parseText
from js.rules import getRules,getPys

layui = Blueprint("layui", __name__)

@layui.route('/')
def hello():  # put application's code here
    return jsonify({'msg':'hello layui'})

@layui.route('/index')
def layui_index():  # put application's code here
    # return render_template('layui_index.html')
H
hjdhnx 已提交
25 26
    if not verfy_token():
        return render_template('login.html')
H
hjdhnx 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    return render_template('layui_list.html')

@layui.route('/api/list')
def layui_rule_list():
    page = int(getParmas('page',1))
    limit = int(getParmas('limit',10))
    # print(f'page:{page},limit:{limit}')
    new_conf = cfg
    lsg = storage_service()
    store_conf_dict = lsg.getStoreConfDict()
    new_conf.update(store_conf_dict)
    host = getHost(2)
    customConfig = getCustonDict(host)
    jxs = []
    lsg = storage_service()
    use_py = lsg.getItem('USE_PY')
    pys = getPys() if use_py else []
    # print(pys)
    alists = []
    live_url = []
    html = render_template('config.txt', pys=pys, rules=getRules('js'), host=host, mode=2, jxs=jxs, alists=alists,
                           alists_str='[]', live_url=live_url, config=new_conf)
    merged_config = custom_merge(parseText(html), customConfig)
    sites = merged_config['sites']
    for i in range(len(sites)):
        sites[i]['id'] = i+1
    new_sites = sites[(page-1)*limit:page*limit]
    return layuiBack('获取成功',new_sites,count=len(sites))