From 2f2dca29fe1eed89297008e6147fe3d40ce0aff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=9A=E9=A3=8E=E6=8B=82=E6=9F=B3=E9=A2=9C?= <434857005@qq.com> Date: Fri, 28 Jul 2023 17:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0js=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=97=B6=E7=9A=84=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81es6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/admin.py | 26 +++++++++++++++++++++----- js/version.txt | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/controllers/admin.py b/controllers/admin.py index 5a66b01..561dd52 100644 --- a/controllers/admin.py +++ b/controllers/admin.py @@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename from utils.web import md5 from utils.common_api import js_render from utils.files import get_jar_list, get_jsd_list, get_drop_js +from quickjs import Function, Context admin = Blueprint("admin", __name__) @@ -410,16 +411,31 @@ def upload_file(): return R.failed(f'上传失败,文件已存在,请先查看删除再试') with open('js/模板.js', encoding='utf-8') as f2: before = f2.read().split('export')[0] + end_code = """\nif (rule.模板 && muban.hasOwnProperty(rule.模板)) {rule = Object.assign(muban[rule.模板], rule);}""" upcode = file.stream.read().decode('utf-8') - check_to_run = before + upcode + check_to_run = before + upcode + end_code # print(check_to_run) + # try: + # loader, _ = runJScode(check_to_run) + # rule = loader.eval('rule') + # if not rule: + # return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码') + # except Exception as e: + # logger.info(f'上传文件发生了错误:{e}') + # return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码') + try: - loader, _ = runJScode(check_to_run) - rule = loader.eval('rule') - if not rule: + ctx = Context() + ctx.eval(check_to_run) + js_ret = ctx.get('rule') + rule_json = js_ret.json() # 规则的json字符串 + ruleDict = ujson.loads(rule_json) + if not ruleDict: return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码') - except: + except Exception as e: + logger.info(f'上传文件发生了错误:{e}') return R.failed('文件上传失败,检测到上传的文件不是drpy框架支持的源代码') + # print(savePath) file.seek(0) # 读取后变成空文件,重新赋能 file.save(savePath) diff --git a/js/version.txt b/js/version.txt index 5b1e272..e7118f6 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.9.47beta16 \ No newline at end of file +3.9.47beta17 \ No newline at end of file