增加新功能
This commit is contained in:
parent
1e022cb1a5
commit
089da0eaae
@ -6,17 +6,17 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from flask import Blueprint,request,render_template,render_template_string,jsonify,make_response,redirect
|
from flask import Blueprint, request, render_template, render_template_string, jsonify, make_response, redirect
|
||||||
from controllers.service import storage_service,rules_service,parse_service
|
from controllers.service import storage_service, rules_service, parse_service
|
||||||
from base.R import R
|
from base.R import R
|
||||||
from base.database import db
|
from base.database import db
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
import shutil
|
import shutil
|
||||||
from utils.update import getLocalVer,getOnlineVer,download_new_version,download_lives,copy_to_update
|
from utils.update import getLocalVer, getOnlineVer, download_new_version, download_lives, copy_to_update
|
||||||
from utils import parser
|
from utils import parser
|
||||||
from utils.env import get_env,update_env
|
from utils.env import get_env, update_env
|
||||||
from utils.web import getParmas,verfy_token
|
from utils.web import getParmas, verfy_token
|
||||||
from js.rules import getRules,getCacheCount
|
from js.rules import getRules, getCacheCount
|
||||||
from utils.parser import runJScode
|
from utils.parser import runJScode
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from utils.web import md5
|
from utils.web import md5
|
||||||
@ -24,6 +24,7 @@ from utils.common_api import js_render
|
|||||||
|
|
||||||
admin = Blueprint("admin", __name__)
|
admin = Blueprint("admin", __name__)
|
||||||
|
|
||||||
|
|
||||||
# @admin.route("/",methods=['get'])
|
# @admin.route("/",methods=['get'])
|
||||||
# def index():
|
# def index():
|
||||||
# return R.ok(msg='欢迎进入首页',data=None)
|
# return R.ok(msg='欢迎进入首页',data=None)
|
||||||
@ -46,7 +47,9 @@ def admin_index(): # 管理员界面
|
|||||||
# print(rules)
|
# print(rules)
|
||||||
cache_count = getCacheCount()
|
cache_count = getCacheCount()
|
||||||
# print(cache_count)
|
# print(cache_count)
|
||||||
return render_template('admin.html',js0_password=js0_password, pystate=use_py,rules=rules,cache_count=cache_count, ver=getLocalVer(), live_url=live_url)
|
return render_template('admin.html', js0_password=js0_password, pystate=use_py, rules=rules,
|
||||||
|
cache_count=cache_count, ver=getLocalVer(), live_url=live_url)
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/settings')
|
@admin.route('/settings')
|
||||||
def admin_settings(): # 管理员界面
|
def admin_settings(): # 管理员界面
|
||||||
@ -56,9 +59,10 @@ def admin_settings(): # 管理员界面
|
|||||||
# conf_list = 'LIVE_URL|USE_PY|PLAY_URL|PLAY_DISABLE|LAZYPARSE_MODE|WALL_PAPER_ENABLE|WALL_PAPER|UNAME|PWD|LIVE_MODE|LIVE_URL|CATE_EXCLUDE|TAB_EXCLUDE'.split('|')
|
# conf_list = 'LIVE_URL|USE_PY|PLAY_URL|PLAY_DISABLE|LAZYPARSE_MODE|WALL_PAPER_ENABLE|WALL_PAPER|UNAME|PWD|LIVE_MODE|LIVE_URL|CATE_EXCLUDE|TAB_EXCLUDE'.split('|')
|
||||||
conf_lists = lsg.getStoreConf()
|
conf_lists = lsg.getStoreConf()
|
||||||
# print(conf_lists)
|
# print(conf_lists)
|
||||||
return render_template('settings.html', conf_lists=conf_lists,ver=getLocalVer())
|
return render_template('settings.html', conf_lists=conf_lists, ver=getLocalVer())
|
||||||
|
|
||||||
@admin.route('/save_conf',methods=['POST'])
|
|
||||||
|
@admin.route('/save_conf', methods=['POST'])
|
||||||
def admin_save_conf(): # 管理员界面
|
def admin_save_conf(): # 管理员界面
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
# return render_template('login.html')
|
# return render_template('login.html')
|
||||||
@ -67,10 +71,11 @@ def admin_save_conf(): # 管理员界面
|
|||||||
value = getParmas('value')
|
value = getParmas('value')
|
||||||
print(f'key:{key},value:{value}')
|
print(f'key:{key},value:{value}')
|
||||||
lsg = storage_service()
|
lsg = storage_service()
|
||||||
res_id = lsg.setItem(key,value)
|
res_id = lsg.setItem(key, value)
|
||||||
return R.success(f'修改成功,记录ID为:{res_id}')
|
return R.success(f'修改成功,记录ID为:{res_id}')
|
||||||
|
|
||||||
@admin.route('/update_env',methods=['POST'])
|
|
||||||
|
@admin.route('/update_env', methods=['POST'])
|
||||||
def admin_update_env(): # 更新环境变量中的某个值
|
def admin_update_env(): # 更新环境变量中的某个值
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
# return render_template('login.html')
|
# return render_template('login.html')
|
||||||
@ -78,17 +83,39 @@ def admin_update_env(): # 更新环境变量中的某个值
|
|||||||
key = getParmas('key')
|
key = getParmas('key')
|
||||||
value = getParmas('value')
|
value = getParmas('value')
|
||||||
print(f'key:{key},value:{value}')
|
print(f'key:{key},value:{value}')
|
||||||
ENV = update_env(key,value)
|
ENV = update_env(key, value)
|
||||||
return R.success(f'修改成功,最新的完整ENV见data',data=ENV)
|
return R.success(f'修改成功,最新的完整ENV见data', data=ENV)
|
||||||
|
|
||||||
@admin.route("/edit/<name>",methods=['GET'])
|
|
||||||
|
@admin.route("/edit/<name>", methods=['GET'])
|
||||||
def admin_edit_rule(name):
|
def admin_edit_rule(name):
|
||||||
# print(name)
|
# print(name)
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return render_template('login.html')
|
return render_template('login.html')
|
||||||
return render_template('edit_rule.html', name=name)
|
return render_template('edit_rule.html', name=name)
|
||||||
|
|
||||||
@admin.route("/view/<name>",methods=['GET'])
|
|
||||||
|
@admin.route("/save_edit/<name>", methods=['POST'])
|
||||||
|
def admin_save_edit_rule(name):
|
||||||
|
# print(name)
|
||||||
|
if not verfy_token():
|
||||||
|
return R.error('请登录后再试')
|
||||||
|
|
||||||
|
code = getParmas('code')
|
||||||
|
file_path = os.path.abspath(f'js/{name}')
|
||||||
|
if 'var rule' not in code and name != '模板.js':
|
||||||
|
return R.error(f'文件{name}保存失败,未检测到关键词:var rule')
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
return R.error('服务端没有此文件!' + file_path)
|
||||||
|
|
||||||
|
logger.info(f'待保存文件路径:{file_path}')
|
||||||
|
with open(file_path, mode='w+', encoding='utf-8') as f:
|
||||||
|
f.write(code)
|
||||||
|
|
||||||
|
return R.success(f'保存成功')
|
||||||
|
|
||||||
|
|
||||||
|
@admin.route("/view/<name>", methods=['GET'])
|
||||||
def admin_view_rule(name):
|
def admin_view_rule(name):
|
||||||
return js_render(name)
|
return js_render(name)
|
||||||
# if not name or not name.split('.')[-1] in ['js','txt','py','json']:
|
# if not name or not name.split('.')[-1] in ['js','txt','py','json']:
|
||||||
@ -123,9 +150,10 @@ def admin_view_rule(name):
|
|||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# return R.error(f'非法猥亵\n{e}')
|
# return R.error(f'非法猥亵\n{e}')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/clear/<name>')
|
@admin.route('/clear/<name>')
|
||||||
def admin_clear_rule(name):
|
def admin_clear_rule(name):
|
||||||
if not name or not name.split('.')[-1] in ['js','txt','py','json']:
|
if not name or not name.split('.')[-1] in ['js', 'txt', 'py', 'json']:
|
||||||
return R.error(f'非法猥亵,未指定文件名。必须包含js|txt|json|py')
|
return R.error(f'非法猥亵,未指定文件名。必须包含js|txt|json|py')
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return render_template('login.html')
|
return render_template('login.html')
|
||||||
@ -133,9 +161,10 @@ def admin_clear_rule(name):
|
|||||||
file_path = os.path.abspath(f'js/{name}')
|
file_path = os.path.abspath(f'js/{name}')
|
||||||
print(file_path)
|
print(file_path)
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
return R.error('服务端没有此文件!'+file_path)
|
return R.error('服务端没有此文件!' + file_path)
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
return R.ok('成功删除文件:'+file_path)
|
return R.ok('成功删除文件:' + file_path)
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/get_ver')
|
@admin.route('/get_ver')
|
||||||
def admin_get_ver():
|
def admin_get_ver():
|
||||||
@ -144,8 +173,9 @@ def admin_get_ver():
|
|||||||
return R.error('请登录后再试')
|
return R.error('请登录后再试')
|
||||||
lsg = storage_service()
|
lsg = storage_service()
|
||||||
update_proxy = lsg.getItem('UPDATE_PROXY')
|
update_proxy = lsg.getItem('UPDATE_PROXY')
|
||||||
online_ver,msg = getOnlineVer(update_proxy)
|
online_ver, msg = getOnlineVer(update_proxy)
|
||||||
return jsonify({'local_ver':getLocalVer(),'online_ver':online_ver,'msg':msg})
|
return jsonify({'local_ver': getLocalVer(), 'online_ver': online_ver, 'msg': msg})
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/update_db')
|
@admin.route('/update_db')
|
||||||
def admin_update_db():
|
def admin_update_db():
|
||||||
@ -159,12 +189,13 @@ def admin_update_db():
|
|||||||
db.session.execute('drop table if exists alembic_version')
|
db.session.execute('drop table if exists alembic_version')
|
||||||
cmd = 'flask db migrate && flask db upgrade'
|
cmd = 'flask db migrate && flask db upgrade'
|
||||||
if not os.path.exists('migrations'):
|
if not os.path.exists('migrations'):
|
||||||
cmd = 'flask db init && '+cmd
|
cmd = 'flask db init && ' + cmd
|
||||||
logger.info(f'开始执行cmd:{cmd}')
|
logger.info(f'开始执行cmd:{cmd}')
|
||||||
result = os.system(cmd)
|
result = os.system(cmd)
|
||||||
logger.info(f'cmd执行结果:{result}')
|
logger.info(f'cmd执行结果:{result}')
|
||||||
return R.success('数据库升级完毕')
|
return R.success('数据库升级完毕')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/update_ver')
|
@admin.route('/update_ver')
|
||||||
def admin_update_ver():
|
def admin_update_ver():
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
@ -174,7 +205,8 @@ def admin_update_ver():
|
|||||||
msg = download_new_version(update_proxy)
|
msg = download_new_version(update_proxy)
|
||||||
return R.success(msg)
|
return R.success(msg)
|
||||||
|
|
||||||
@admin.route('/rule_state/<int:state>',methods=['POST'])
|
|
||||||
|
@admin.route('/rule_state/<int:state>', methods=['POST'])
|
||||||
def admin_rule_state(state=0): # 管理员修改规则状态
|
def admin_rule_state(state=0): # 管理员修改规则状态
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return R.error('请登录后再试')
|
return R.error('请登录后再试')
|
||||||
@ -189,14 +221,15 @@ def admin_rule_state(state=0): # 管理员修改规则状态
|
|||||||
success_list = []
|
success_list = []
|
||||||
for rule in rule_list:
|
for rule in rule_list:
|
||||||
try:
|
try:
|
||||||
res_id = rules.setState(rule,state)
|
res_id = rules.setState(rule, state)
|
||||||
success_list.append(f'{rule}:{res_id}')
|
success_list.append(f'{rule}:{res_id}')
|
||||||
except:
|
except:
|
||||||
success_list.append(rule)
|
success_list.append(rule)
|
||||||
|
|
||||||
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
||||||
|
|
||||||
@admin.route('/rule_order/<int:order>',methods=['POST'])
|
|
||||||
|
@admin.route('/rule_order/<int:order>', methods=['POST'])
|
||||||
def admin_rule_order(order=0): # 管理员修改规则顺序
|
def admin_rule_order(order=0): # 管理员修改规则顺序
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return R.error('请登录后再试')
|
return R.error('请登录后再试')
|
||||||
@ -209,17 +242,18 @@ def admin_rule_order(order=0): # 管理员修改规则顺序
|
|||||||
# print(rules.getState(rule_list[0]))
|
# print(rules.getState(rule_list[0]))
|
||||||
# print(rule_list)
|
# print(rule_list)
|
||||||
success_list = []
|
success_list = []
|
||||||
rule_list.reverse() # 倒序解决时间多重排序问题
|
rule_list.reverse() # 倒序解决时间多重排序问题
|
||||||
for rule in rule_list:
|
for rule in rule_list:
|
||||||
try:
|
try:
|
||||||
res_id = rules.setOrder(rule,order)
|
res_id = rules.setOrder(rule, order)
|
||||||
success_list.append(f'{rule}:{res_id}')
|
success_list.append(f'{rule}:{res_id}')
|
||||||
except:
|
except:
|
||||||
success_list.append(rule)
|
success_list.append(rule)
|
||||||
|
|
||||||
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
||||||
|
|
||||||
@admin.route('/parse/save_data',methods=['POST'])
|
|
||||||
|
@admin.route('/parse/save_data', methods=['POST'])
|
||||||
def admin_parse_save_data(): # 管理员保存拖拽排序后的解析数据
|
def admin_parse_save_data(): # 管理员保存拖拽排序后的解析数据
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return R.error('请登录后再试')
|
return R.error('请登录后再试')
|
||||||
@ -244,13 +278,13 @@ def admin_parse_save_data(): # 管理员保存拖拽排序后的解析数据
|
|||||||
# if not d.get('url') and d.get('name') != '🌐Ⓤ':
|
# if not d.get('url') and d.get('name') != '🌐Ⓤ':
|
||||||
# continue
|
# continue
|
||||||
obj = {
|
obj = {
|
||||||
'name':d.get('name', ''),
|
'name': d.get('name', ''),
|
||||||
'url':d.get('url', ''),
|
'url': d.get('url', ''),
|
||||||
'state':d.get('state',1),
|
'state': d.get('state', 1),
|
||||||
'type': d.get('state',0),
|
'type': d.get('state', 0),
|
||||||
'order':i+1,
|
'order': i + 1,
|
||||||
'ext':d.get('ext',''),
|
'ext': d.get('ext', ''),
|
||||||
'header':d.get('header',''),
|
'header': d.get('header', ''),
|
||||||
}
|
}
|
||||||
# print(obj)
|
# print(obj)
|
||||||
try:
|
try:
|
||||||
@ -264,6 +298,7 @@ def admin_parse_save_data(): # 管理员保存拖拽排序后的解析数据
|
|||||||
# print(len(success_list))
|
# print(len(success_list))
|
||||||
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
return R.success(f'修改成功,服务器反馈信息为:{success_list}')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/force_update')
|
@admin.route('/force_update')
|
||||||
def admin_force_update():
|
def admin_force_update():
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
@ -276,6 +311,7 @@ def admin_force_update():
|
|||||||
msg = '升级失败。具体原因只能去看实时日志(通过9001端口)'
|
msg = '升级失败。具体原因只能去看实时日志(通过9001端口)'
|
||||||
return R.failed(msg)
|
return R.failed(msg)
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/update_lives')
|
@admin.route('/update_lives')
|
||||||
def admin_update_lives():
|
def admin_update_lives():
|
||||||
url = getParmas('url')
|
url = getParmas('url')
|
||||||
@ -290,6 +326,7 @@ def admin_update_lives():
|
|||||||
else:
|
else:
|
||||||
return R.failed(f'直播源{live_url}同步失败')
|
return R.failed(f'直播源{live_url}同步失败')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/write_live_url')
|
@admin.route('/write_live_url')
|
||||||
def admin_write_live_url():
|
def admin_write_live_url():
|
||||||
url = getParmas('url')
|
url = getParmas('url')
|
||||||
@ -298,10 +335,11 @@ def admin_write_live_url():
|
|||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return R.failed('请登录后再试')
|
return R.failed('请登录后再试')
|
||||||
lsg = storage_service()
|
lsg = storage_service()
|
||||||
id = lsg.setItem('LIVE_URL',url)
|
id = lsg.setItem('LIVE_URL', url)
|
||||||
msg = f'已修改的配置记录id为:{id}'
|
msg = f'已修改的配置记录id为:{id}'
|
||||||
return R.success(msg)
|
return R.success(msg)
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/change_use_py')
|
@admin.route('/change_use_py')
|
||||||
def admin_change_use_py():
|
def admin_change_use_py():
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
@ -314,6 +352,7 @@ def admin_change_use_py():
|
|||||||
msg = f'已修改的配置记录id为:{id},结果为{state}'
|
msg = f'已修改的配置记录id为:{id},结果为{state}'
|
||||||
return R.success(msg)
|
return R.success(msg)
|
||||||
|
|
||||||
|
|
||||||
# @admin.route('/get_use_py')
|
# @admin.route('/get_use_py')
|
||||||
# def admin_get_use_py():
|
# def admin_get_use_py():
|
||||||
# if not verfy_token():
|
# if not verfy_token():
|
||||||
@ -351,7 +390,7 @@ def upload_file():
|
|||||||
except:
|
except:
|
||||||
return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码')
|
return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码')
|
||||||
# print(savePath)
|
# print(savePath)
|
||||||
file.seek(0) # 读取后变成空文件,重新赋能
|
file.seek(0) # 读取后变成空文件,重新赋能
|
||||||
file.save(savePath)
|
file.save(savePath)
|
||||||
return R.success('文件上传成功')
|
return R.success('文件上传成功')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -360,12 +399,13 @@ def upload_file():
|
|||||||
# return render_template('upload.html')
|
# return render_template('upload.html')
|
||||||
return R.failed('文件上传失败')
|
return R.failed('文件上传失败')
|
||||||
|
|
||||||
@admin.route('/login',methods=['GET','POST'])
|
|
||||||
|
@admin.route('/login', methods=['GET', 'POST'])
|
||||||
def login_api():
|
def login_api():
|
||||||
username = getParmas('username')
|
username = getParmas('username')
|
||||||
password = getParmas('password')
|
password = getParmas('password')
|
||||||
autologin = getParmas('autologin')
|
autologin = getParmas('autologin')
|
||||||
if not all([username,password]):
|
if not all([username, password]):
|
||||||
return R.failed('账号密码字段必填')
|
return R.failed('账号密码字段必填')
|
||||||
token = md5(f'{username};{password}')
|
token = md5(f'{username};{password}')
|
||||||
check = verfy_token(token=token)
|
check = verfy_token(token=token)
|
||||||
@ -377,12 +417,14 @@ def login_api():
|
|||||||
else:
|
else:
|
||||||
return R.failed('登录失败,用户名或密码错误')
|
return R.failed('登录失败,用户名或密码错误')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/logtail')
|
@admin.route('/logtail')
|
||||||
def admin_logtail():
|
def admin_logtail():
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
return R.failed('请登录后再试')
|
return R.failed('请登录后再试')
|
||||||
return render_template('logtail.html')
|
return render_template('logtail.html')
|
||||||
|
|
||||||
|
|
||||||
@admin.route('/lives')
|
@admin.route('/lives')
|
||||||
def admin_lives():
|
def admin_lives():
|
||||||
if not verfy_token():
|
if not verfy_token():
|
||||||
@ -393,6 +435,7 @@ def admin_lives():
|
|||||||
# 不带http的前缀 host
|
# 不带http的前缀 host
|
||||||
# 当前路径 path
|
# 当前路径 path
|
||||||
host_url = request.host_url
|
host_url = request.host_url
|
||||||
|
|
||||||
def get_lives():
|
def get_lives():
|
||||||
base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
|
base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
|
||||||
# print(base_path)
|
# print(base_path)
|
||||||
@ -401,11 +444,12 @@ def admin_lives():
|
|||||||
files = os.listdir(live_path)
|
files = os.listdir(live_path)
|
||||||
# print(files)
|
# print(files)
|
||||||
# files = list(filter(lambda x: str(x).endswith('.txt') and str(x).find('模板') < 0, files))
|
# files = list(filter(lambda x: str(x).endswith('.txt') and str(x).find('模板') < 0, files))
|
||||||
files = list(filter(lambda x: str(x).split('.')[-1] in ['txt','json','m3u'] and str(x).find('模板') < 0, files))
|
files = list(
|
||||||
|
filter(lambda x: str(x).split('.')[-1] in ['txt', 'json', 'm3u'] and str(x).find('模板') < 0, files))
|
||||||
files = [f'{host_url}lives?path=txt/lives/{file}' for file in files]
|
files = [f'{host_url}lives?path=txt/lives/{file}' for file in files]
|
||||||
return files
|
return files
|
||||||
|
|
||||||
files = '\n'.join(get_lives())
|
files = '\n'.join(get_lives())
|
||||||
response = make_response(files)
|
response = make_response(files)
|
||||||
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
|
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
|
||||||
return response
|
return response
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
###### 2023/06/09
|
||||||
|
- [X] 发布新版本,增加上传源覆盖提示,增加在线编辑源功能(手机使用可能在此界面会卡死,推荐电脑)
|
||||||
|
|
||||||
###### 2023/06/08
|
###### 2023/06/08
|
||||||
- [X] 后台管理增加优选源功能。参考config.py进行配置优选源参数
|
- [X] 后台管理增加优选源功能。参考config.py进行配置优选源参数
|
||||||
配置好优选源后在动态的在线配置链接ver=2后面添加参数 &sp=1 可以开启优选结果
|
配置好优选源后在动态的在线配置链接ver=2后面添加参数 &sp=1 可以开启优选结果
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
3.9.43beta3
|
3.9.43beta4
|
||||||
@ -14,29 +14,85 @@
|
|||||||
<link href="/static/plugin/codemirror/lib/codemirror.css" rel="stylesheet" >
|
<link href="/static/plugin/codemirror/lib/codemirror.css" rel="stylesheet" >
|
||||||
<script src="/static/plugin/codemirror/lib/codemirror.js"></script>
|
<script src="/static/plugin/codemirror/lib/codemirror.js"></script>
|
||||||
<link href="/static/plugin/codemirror/theme/monokai.css" rel="stylesheet">
|
<link href="/static/plugin/codemirror/theme/monokai.css" rel="stylesheet">
|
||||||
|
<link href="/static/plugin/codemirror/theme/idea.css" rel="stylesheet">
|
||||||
|
<link href="/static/plugin/codemirror/theme/eclipse.css" rel="stylesheet">
|
||||||
|
<link href="/static/plugin/codemirror/theme/rubyblue.css" rel="stylesheet">
|
||||||
|
<link href="/static/plugin/codemirror/theme/ambiance-mobile.css" rel="stylesheet">
|
||||||
|
<link href="/static/plugin/codemirror/theme/3024-day.css" rel="stylesheet">
|
||||||
<link href="/static/plugin/codemirror/theme/3024-night.css" rel="stylesheet">
|
<link href="/static/plugin/codemirror/theme/3024-night.css" rel="stylesheet">
|
||||||
<link href="/static/plugin/codemirror/theme/erlang-dark.css" rel="stylesheet">
|
<link href="/static/plugin/codemirror/theme/erlang-dark.css" rel="stylesheet">
|
||||||
<script src="/static/plugin/codemirror/mode/javascript/javascript.js"></script>
|
<script src="/static/plugin/codemirror/mode/javascript/javascript.js"></script>
|
||||||
<script src="/static/plugin/codemirror/mode/python/python.js"></script>
|
<script src="/static/plugin/codemirror/mode/python/python.js"></script>
|
||||||
<script src="/static/plugin/codemirror/mode/shell/shell.js"></script>
|
<script src="/static/plugin/codemirror/mode/shell/shell.js"></script>
|
||||||
|
<script src="/static/plugin/codemirror/mode/php/php.js"></script>
|
||||||
|
<script src="/static/plugin/codemirror/mode/go/go.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
}
|
}
|
||||||
|
.footer {
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-left: 10px;
|
||||||
|
text-align: left;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0px;
|
||||||
|
background-color:#ddd;
|
||||||
|
width:100%;
|
||||||
|
|
||||||
|
}
|
||||||
|
.footer > button{
|
||||||
|
border-radius: 25px;
|
||||||
|
}
|
||||||
|
.center{
|
||||||
|
margin-bottom: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {*/
|
||||||
|
/* padding: 2px;*/
|
||||||
|
/* margin: 2px;*/
|
||||||
|
/*}*/
|
||||||
|
|
||||||
|
/*.container {*/
|
||||||
|
/* height: 100vh;*/
|
||||||
|
/* width: 100%;*/
|
||||||
|
/* display: flex;*/
|
||||||
|
/* flex-direction: column;*/
|
||||||
|
/* justify-content: space-between;*/
|
||||||
|
/*}*/
|
||||||
|
/*.container .header {*/
|
||||||
|
/* display: flex;*/
|
||||||
|
/* align-items: flex-start;*/
|
||||||
|
/*}*/
|
||||||
|
/*.container .center {*/
|
||||||
|
/* flex: 1;*/
|
||||||
|
/* overflow: hidden;*/
|
||||||
|
/* display: flex;*/
|
||||||
|
/*}*/
|
||||||
|
/*.container .footer {*/
|
||||||
|
/* height: 50px;*/
|
||||||
|
/* display: flex;*/
|
||||||
|
/* align-items: flex-start;*/
|
||||||
|
/*}*/
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div class="layui-form layuimini-form layuimini-container layui-form-pane" lay-filter="scripts">
|
<div class="layui-form layuimini-form layuimini-container layui-form-pane container" lay-filter="scripts">
|
||||||
<!--<div class="layui-form layui-form-pane" lay-filter="scripts">-->
|
<!--<div class="layui-form layui-form-pane" lay-filter="scripts">-->
|
||||||
|
|
||||||
|
<div class="header">
|
||||||
<div class="layui-form-item" pane="">
|
<div class="layui-form-item" pane="">
|
||||||
<label class="layui-form-label required">脚本类型</label>
|
<label class="layui-form-label required">脚本类型</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<input type="radio" name="script_code" id="script_code_sh" lay-filter="ck-code" value="shell" title="shell">
|
<input type="radio" name="script_code" id="script_code_php" lay-filter="ck-code" value="python" title="php">
|
||||||
<input type="radio" name="script_code" id="script_code_py" lay-filter="ck-code" value="python" title="python">
|
<input type="radio" name="script_code" id="script_code_py" lay-filter="ck-code" value="python" title="python">
|
||||||
<input type="radio" name="script_code" id="script_code_js" lay-filter="ck-code" value="javascript" title="js" checked>
|
<input type="radio" name="script_code" id="script_code_js" lay-filter="ck-code" value="javascript" title="js" checked>
|
||||||
|
|
||||||
|
<input type="radio" name="script_code" id="script_code_jinja2" lay-filter="ck-code" value="jinja2" title="jinja2">
|
||||||
|
<input type="radio" name="script_code" id="script_code_sh" lay-filter="ck-code" value="shell" title="shell">
|
||||||
|
<input type="radio" name="script_code" id="script_code_go" lay-filter="ck-code" value="python" title="go">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -46,41 +102,52 @@
|
|||||||
<select name="interest" lay-filter="select_theme" id="select_theme">
|
<select name="interest" lay-filter="select_theme" id="select_theme">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<option value="default">default</option>
|
<option value="default">default</option>
|
||||||
|
<option value="idea">idea</option>
|
||||||
|
<option value="eclipse">eclipse</option>
|
||||||
|
<option value="rubyblue">rubyblue</option>
|
||||||
|
<option value="ambiance-mobile">ambiance-mobile</option>
|
||||||
|
<option value="3024-day">3024-day</option>
|
||||||
<option value="3024-night">3024-night</option>
|
<option value="3024-night">3024-night</option>
|
||||||
<option value="erlang-dark">erlang-dark</option>
|
<option value="erlang-dark">erlang-dark</option>
|
||||||
<option value="monokai" selected>monokai</option>
|
<option value="monokai" selected>monokai</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="center">
|
||||||
<div class="layui-form-item layui-form-text">
|
<div class="layui-form-item layui-form-text">
|
||||||
<label class="layui-form-label required">脚本区域</label>
|
<label class="layui-form-label required">脚本区域</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
<!--textarea-->
|
<!--textarea-->
|
||||||
<textarea id="script_shell" style="display: none">#!/bin/sh
|
<textarea id="script_shell" class="hide" style="display: none">#!/bin/sh
|
||||||
</textarea>
|
</textarea>
|
||||||
<textarea id="script_python" class="hide" style="display: none">
|
<textarea id="script_python" class="hide" style="display: none">
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf8 -*-
|
# -*- coding: utf8 -*-
|
||||||
</textarea>
|
</textarea>
|
||||||
<textarea id="script_js" name='scripts_code' class="hide" style="display: none">
|
<textarea id="script_js" class="hide" style="display: none">
|
||||||
// javascript
|
// javascript
|
||||||
function f(){
|
function f(){
|
||||||
|
|
||||||
}</textarea>
|
}</textarea>
|
||||||
|
<textarea id="script_code" name='scripts_code' class="hide" style="display: none">
|
||||||
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="layui-btn-container">
|
<div class="layui-btn-container footer">
|
||||||
<button class="layui-btn layui-btn-normal " lay-submit lay-filter="reBtn"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
|
<button class="layui-btn layui-btn-normal " lay-submit lay-filter="reBtn"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
|
||||||
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"><i class="layui-icon layui-icon-ok"></i>保存</button>
|
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"><i class="layui-icon layui-icon-ok"></i>保存</button>
|
||||||
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="openRawBtn"><i class="layui-icon layui-icon-file-b"></i>查看原始文件</button>
|
<button class="layui-btn layui-btn-normal" lay-submit lay-filter="openRawBtn"><i class="layui-icon layui-icon-file-b"></i>查看原始文件</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const api_url = '/admin/view/{{name}}';
|
const api_url = '/admin/view/{{name}}';
|
||||||
const api_save_url = '/admin/save_edit';
|
const api_save_url = '/admin/save_edit/{{name}}';
|
||||||
// 初始化 脚本编辑页面
|
// 初始化 脚本编辑页面
|
||||||
function init_scripts(form) {
|
function init_scripts(form) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -91,7 +158,9 @@ function f(){
|
|||||||
// data:'',
|
// data:'',
|
||||||
// dataType:'json',
|
// dataType:'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
|
editor.setValue(data);
|
||||||
|
form.render();
|
||||||
},error: function(XMLHttpRequest,textStatus,errorThrown) {
|
},error: function(XMLHttpRequest,textStatus,errorThrown) {
|
||||||
if (XMLHttpRequest.status == 0) {
|
if (XMLHttpRequest.status == 0) {
|
||||||
layer.msg('Check Your Network.',{icon: 2},function () {});
|
layer.msg('Check Your Network.',{icon: 2},function () {});
|
||||||
@ -109,7 +178,7 @@ function f(){
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
var editor = CodeMirror.fromTextArea($("#script_js")[0], { //为你的textarea的ID号
|
var editor = CodeMirror.fromTextArea(document.getElementById("script_code"), { //为你的textarea的ID号 $("#script_code")[0]
|
||||||
lineNumbers: true,//是否显示行号
|
lineNumbers: true,//是否显示行号
|
||||||
mode: "javascript", //默认语言
|
mode: "javascript", //默认语言
|
||||||
lineWrapping:true, //是否强制换行
|
lineWrapping:true, //是否强制换行
|
||||||
@ -122,7 +191,8 @@ function f(){
|
|||||||
indentWithTabs: true,
|
indentWithTabs: true,
|
||||||
extraKeys: {"Ctrl-Space": "autocomplete"}//ctrl-space唤起智能提示
|
extraKeys: {"Ctrl-Space": "autocomplete"}//ctrl-space唤起智能提示
|
||||||
});
|
});
|
||||||
editor.setSize('auto','630px'); //设置宽度,高度
|
editor.setSize('auto','600px'); //设置宽度,高度
|
||||||
|
// editor.setSize('auto','auto'); //设置宽度,高度
|
||||||
|
|
||||||
//选择脚本类型JS
|
//选择脚本类型JS
|
||||||
var script_sh=$("#script_shell").val();
|
var script_sh=$("#script_shell").val();
|
||||||
@ -143,43 +213,26 @@ function f(){
|
|||||||
});
|
});
|
||||||
//监听提交
|
//监听提交
|
||||||
form.on('submit(saveBtn)', function (data) {
|
form.on('submit(saveBtn)', function (data) {
|
||||||
alert(111)
|
let txt = editor.getValue();
|
||||||
return false
|
|
||||||
// let txt = editor.getValue();
|
|
||||||
// console.log(txt);
|
// console.log(txt);
|
||||||
// let postData = {
|
let postData = {
|
||||||
// name:'{{name}}',
|
name:'{{name}}',
|
||||||
// // code:editor.getValue(),
|
code:txt,
|
||||||
// // code:editor.getValue().replaceAll("+","&").replaceAll("console.log","console.Log")
|
// code:txt.replaceAll("+","&").replaceAll("console.log","console.Log")
|
||||||
// }
|
}
|
||||||
// console.log(postData);
|
// console.log(postData);
|
||||||
|
$.ajax({
|
||||||
// $.ajax({
|
type:'post',
|
||||||
// type:'post',
|
url:api_save_url,
|
||||||
// url:api_save_url,
|
data:postData,
|
||||||
// data:JSON.stringify(postData),
|
dataType:'json',
|
||||||
// dataType:'json',
|
async:false,
|
||||||
// async:false,
|
success:function (ret) {
|
||||||
// success:function (ret) {
|
console.log(ret);
|
||||||
// console.log(ret);
|
layer.msg(ret.msg);
|
||||||
// // if(typeof (ret.ret)!="undefined" && ret.ret=="200"){
|
}
|
||||||
// // pstr = "params="+ret.msg+"&limit=1&page=1";
|
});
|
||||||
// // $.ajax({
|
return false;
|
||||||
// // type:'post',
|
|
||||||
// // url:api_url,
|
|
||||||
// // data:pstr,
|
|
||||||
// // async:false,
|
|
||||||
// // success:function (ret) {
|
|
||||||
// // // console.log(ret);
|
|
||||||
// // if(ret.ret == '200'){
|
|
||||||
// // layer.msg('脚本编辑成功');
|
|
||||||
// // }else {layer.msg(ret.msg);}
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -192,6 +245,7 @@ function f(){
|
|||||||
var txt=editor.getValue(); //editor.getValue()获取textarea中的值
|
var txt=editor.getValue(); //editor.getValue()获取textarea中的值
|
||||||
var lang=$(this).prop("id");
|
var lang=$(this).prop("id");
|
||||||
// console.log(txt,lang);
|
// console.log(txt,lang);
|
||||||
|
console.log(data.value);
|
||||||
editor.setOption("mode",data.value);
|
editor.setOption("mode",data.value);
|
||||||
switch (data.value) {
|
switch (data.value) {
|
||||||
case 'shell':
|
case 'shell':
|
||||||
@ -214,4 +268,4 @@ function f(){
|
|||||||
// });
|
// });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user