From 863ca3058d48de765fb1a3621ea9167d2810876a Mon Sep 17 00:00:00 2001 From: flaskfarm Date: Fri, 7 Oct 2022 15:11:05 +0900 Subject: [PATCH] updae --- files/requirements.txt | 3 +- lib/framework/init_main.py | 13 +- lib/framework/init_route.py | 14 ++- lib/framework/init_web.py | 1 + lib/framework/static/js/ff_global1.js | 8 +- lib/framework/templates/macro_menu.html | 18 ++- lib/system/mod_tool.py | 43 +++++++ lib/system/setup.py | 6 +- .../templates/system_plugin_setting.html | 2 +- .../templates/system_setting_notify.html | 2 +- .../templates/system_setting_terminal.html | 112 ------------------ lib/system/templates/system_tool_upload.html | 36 ++++++ 12 files changed, 125 insertions(+), 133 deletions(-) create mode 100644 lib/system/mod_tool.py delete mode 100644 lib/system/templates/system_setting_terminal.html create mode 100644 lib/system/templates/system_tool_upload.html diff --git a/files/requirements.txt b/files/requirements.txt index 4ec8b89..1ddf26f 100644 --- a/files/requirements.txt +++ b/files/requirements.txt @@ -20,4 +20,5 @@ requests==2.26.0 discord-webhook pyyaml pycryptodome -telepot-mod \ No newline at end of file +telepot-mod +Flask-Dropzone \ No newline at end of file diff --git a/lib/framework/init_main.py b/lib/framework/init_main.py index 175238b..f56030e 100644 --- a/lib/framework/init_main.py +++ b/lib/framework/init_main.py @@ -90,7 +90,16 @@ class Framework: self.celery = self.__init_celery() - + from flask_dropzone import Dropzone + self.app.config.update( + DROPZONE_MAX_FILE_SIZE = 102400, + DROPZONE_TIMEOUT = 5*60*1000, + #DROPZONE_ALLOWED_FILE_CUSTOM = True, + #DROPZONE_ALLOWED_FILE_TYPE = 'default, image, audio, video, text, app, *.*', + ) + self.dropzone = Dropzone(self.app) + + def __init_celery(self): try: from celery import Celery @@ -190,7 +199,7 @@ class Framework: self.__make_default_logger() self.logger.info('### LAST') - self.logger.info(f"### PORT: {self.config['port']}") + self.logger.info(f"### PORT: {self.config.get('port')}") self.logger.info('### Now you can access App by webbrowser!!') diff --git a/lib/framework/init_route.py b/lib/framework/init_route.py index 4f7f236..b8ccbf0 100644 --- a/lib/framework/init_route.py +++ b/lib/framework/init_route.py @@ -35,9 +35,11 @@ def global_ajax(sub): # globalEditBtn try: import flaskcode - return jsonify(True) + from flaskcode.setup import P as PP + ret = {'ret':True, 'target':PP.ModelSetting.get('setting_open_target')} + return jsonify(ret) except: - return jsonify(False) + return jsonify({'ret':False}) @@ -92,7 +94,7 @@ def file2(path): -@F.app.route("/up", methods=['GET', 'POST']) +@F.app.route("/upload", methods=['GET', 'POST']) def upload(): # curl -F file=@downloader_video.tar https://dev.soju6jan.com/up # @@ -100,9 +102,9 @@ def upload(): if request.method == 'POST': f = request.files['file'] from werkzeug import secure_filename - tmp = secure_filename(f.filename) - F.logger.debug('upload : %s', tmp) - f.save(os.path.join(F.path_data, 'upload', tmp)) + upload_path = F.SystemModelSetting.get('path_upload') + os.makedirs(upload_path, exist_ok=True) + f.save(os.path.join(upload_path, secure_filename(f.filename))) return jsonify('success') except Exception as exception: F.logger.error('Exception:%s', exception) diff --git a/lib/framework/init_web.py b/lib/framework/init_web.py index ee43859..12ba665 100644 --- a/lib/framework/init_web.py +++ b/lib/framework/init_web.py @@ -49,6 +49,7 @@ def jinja_initialize(app): app.jinja_env.globals.update(get_theme=get_theme) app.jinja_env.globals.update(get_menu_map=MenuManager.get_menu_map) app.jinja_env.globals.update(get_web_title=get_web_title) + app.jinja_env.globals.update(dropzone=F.dropzone) app.jinja_env.filters['get_menu'] = get_menu app.jinja_env.filters['get_theme'] = get_theme diff --git a/lib/framework/static/js/ff_global1.js b/lib/framework/static/js/ff_global1.js index 50a77c1..e4e866e 100644 --- a/lib/framework/static/js/ff_global1.js +++ b/lib/framework/static/js/ff_global1.js @@ -112,8 +112,8 @@ $("body").on('click', '#globalEditBtn', function(e) { data: {}, dataType: "json", success: function (ret) { - if (ret) { - window.location.href = '/flaskcode?open=' + file; + if (ret.ret) { + window.open('/flaskcode?open=' + file, ret.target); } else { notify('편집기 플러그인을 설치해야 합니다.', 'warning'); } @@ -160,11 +160,11 @@ function shutdown_confirm() { var select_local_file_modal_callback = null; -function selectLocalFile(title, init_path, func) { +function globalSelectLocalFile(title, init_path, func) { _selectLocalFileModal(title, init_path, false, func); } -function selectLocalFolder(title, init_path, func) { +function globalSelectLocalFolder(title, init_path, func) { _selectLocalFileModal(title, init_path, true, func); } diff --git a/lib/framework/templates/macro_menu.html b/lib/framework/templates/macro_menu.html index 60fd0a7..fc7a5fa 100644 --- a/lib/framework/templates/macro_menu.html +++ b/lib/framework/templates/macro_menu.html @@ -46,7 +46,11 @@ {% if category_child['uri'] == menu[0] %} {{ category_child['name'] }} {% else %} - {{ category_child['name'] }} + {% if category_child['target'] == '__blank' %} + {{ category_child['name'] }} + {% else %} + {{ category_child['name'] }} + {% endif %} {% endif %} {% endif %} {% endfor %} @@ -85,9 +89,17 @@ {% endif %} {% else %} {% if current_menu[1] == module['uri'] or (current_menu[2] is not none and current_menu[1] + "/" + current_menu[2] == module['uri']) %} - + {% if 'target' in module and module['target'] == '_blank' %} + + {% else %} + + {% endif %} {% else %} - + {% if 'target' in module and module['target'] == '_blank' %} + + {% else %} + + {% endif %} {% endif %} {% endif %} {% endfor %} diff --git a/lib/system/mod_tool.py b/lib/system/mod_tool.py new file mode 100644 index 0000000..74a100d --- /dev/null +++ b/lib/system/mod_tool.py @@ -0,0 +1,43 @@ +from support import SupportFile + +from .setup import * + +name = 'tool' + +class ModuleTool(PluginModuleBase): + db_default = { + 'path_upload': os.path.join(F.config['path_data'], 'upload'), + } + + + def __init__(self, P): + super(ModuleTool, self).__init__(P, name=name, first_menu='celery') + + + def process_menu(self, page, req): + arg = P.ModelSetting.to_dict() + try: + return render_template(f'{__package__}_{name}_{page}.html', arg=arg) + except Exception as e: + P.logger.error(f'Exception:{str(e)}') + P.logger.error(traceback.format_exc()) + return render_template('sample.html', title=f"{__package__}/{name}/{page}") + + + def process_command(self, command, arg1, arg2, arg3, req): + ret = {'ret':'success'} + if command == 'plugin_install': + ret = F.PluginManager.plugin_install(arg1) + + return jsonify(ret) + + + def plugin_load(self): + try: + pass + except Exception as e: + P.logger.error(f'Exception:{str(e)}') + P.logger.error(traceback.format_exc()) + + + \ No newline at end of file diff --git a/lib/system/setup.py b/lib/system/setup.py index 927f3ca..9646915 100644 --- a/lib/system/setup.py +++ b/lib/system/setup.py @@ -73,11 +73,11 @@ try: SystemModelSetting = P.ModelSetting from .mod_home import ModuleHome - from .mod_plugin import ModulePlugin from .mod_route import ModuleRoute from .mod_setting import ModuleSetting - - P.set_module_list([ModuleSetting, ModuleHome, ModuleRoute, ModulePlugin]) + from .mod_plugin import ModulePlugin + from .mod_tool import ModuleTool + P.set_module_list([ModuleHome, ModuleRoute, ModuleSetting, ModulePlugin, ModuleTool]) except Exception as e: P.logger.error(f'Exception:{str(e)}') diff --git a/lib/system/templates/system_plugin_setting.html b/lib/system/templates/system_plugin_setting.html index 2838e82..97b2ee7 100644 --- a/lib/system/templates/system_plugin_setting.html +++ b/lib/system/templates/system_plugin_setting.html @@ -16,7 +16,7 @@ -{% endblock %} diff --git a/lib/system/templates/system_tool_upload.html b/lib/system/templates/system_tool_upload.html new file mode 100644 index 0000000..2b48c64 --- /dev/null +++ b/lib/system/templates/system_tool_upload.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} +{% block content %} + + {{ dropzone.load_css() }} + {{ dropzone.style('border: 2px dashed #0087F7; margin: 10%; min-height: 400px;') }} + + +
+ {{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}} + {{ macros.m_row_start('5') }} + {{ macros.m_row_end() }} + {{ macros.m_hr() }} +
+ {{ macros.setting_input_text_and_buttons('path_upload', '업로드 경로', [['select_btn', '폴더 선택']], value=arg['path_upload'], desc=['설정 저장 후부터 적용']) }} +
+ {{ macros.m_hr_black() }} + {{ dropzone.create(action='upload') }} + {{ dropzone.load_js() }} + {{ dropzone.config() }} + + + +{% endblock %}