pull/628/head
Mr Chen 7 months ago
parent 32eefbba10
commit a35ae6df9e
  1. 56
      web/admin/plugins/__init__.py
  2. 53
      web/core/mw.py
  3. 42
      web/utils/mwplugin.py

@ -8,23 +8,20 @@
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
import os
from flask import Blueprint, render_template
from flask import request
from utils.mwplugin import MwPlugin
import core.mw as mw
blueprint = Blueprint('plugins', __name__, url_prefix='/plugins', template_folder='../../templates/default')
@blueprint.route('/index', endpoint='index')
def index():
return render_template('plugins.html', data={})
# 插件列表
@blueprint.route('/list', endpoint='list', methods=['GET'])
def list():
pg = MwPlugin.instance()
# print(pg.getList())
return pg.getList()
# 初始化检查,首页提示选择安装
@blueprint.route('/init', endpoint='init', methods=['POST'])
def init():
@ -36,3 +33,48 @@ def init():
'phpmyadmin': '4.4.15',
}
return []
# 插件列表
@blueprint.route('/list', endpoint='list', methods=['GET'])
def list():
plugins_type = request.args.get('type', '0')
page = request.args.get('p', '1')
search = request.args.get('search', '').lower()
if not mw.isNumber(plugins_type):
plugins_type = 1
if not mw.isNumber(page):
page = 0
pg = MwPlugin.instance()
# pg.getList(plugins_type, search, int(page))
return pg.getList(plugins_type, search, int(page))
# 图片文件读取
@blueprint.route('/file', endpoint='file', methods=['GET'])
def file():
name = request.args.get('name', '')
if name.strip() == '':
return ''
f = request.args.get('f', '')
if f.strip() == '':
return ''
file = mw.getPluginDir() + '/' + name + '/' + f
if not os.path.exists(file):
return ''
suffix = mw.getPathSuffix(file)
if suffix == '.css':
content = mw.readFile(file)
from flask import Response
from flask import make_response
v = Response(content, headers={'Content-Type': 'text/css; charset="utf-8"'})
return make_response(v)
content = open(file, 'rb').read()
return content

@ -130,6 +130,25 @@ def writeFile(filename, content, mode='w+'):
except Exception as e:
return False
def isNumber(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
def getPathSuffix(path):
return os.path.splitext(path)[-1]
def dbSqitePrefix():
WIN = sys.platform.startswith('win')
if WIN: # 如果是 Windows 系统,使用三个斜线
@ -138,3 +157,37 @@ def dbSqitePrefix():
prefix = 'sqlite:////'
return prefix
def getPage(args, result='1,2,3,4,5,8'):
data = getPageObject(args, result)
return data[0]
def getPageObject(args, result='1,2,3,4,5,8'):
# 取分页
from utils import page
# 实例化分页类
page = page.Page()
info = {}
info['count'] = 0
if 'count' in args:
info['count'] = int(args['count'])
info['row'] = 10
if 'row' in args:
info['row'] = int(args['row'])
info['p'] = 1
if 'p' in args:
info['p'] = int(args['p'])
info['uri'] = {}
info['return_js'] = ''
if 'tojs' in args:
info['return_js'] = args['tojs']
if 'args_tpl' in args:
info['args_tpl'] = args['args_tpl']
return (page.GetPage(info, result), page)

@ -177,7 +177,7 @@ class MwPlugin(object):
"coexist": coexist,
"versions": info['versions'],
# "updates": info['updates'],
"task": False,
"task": True,
"display": False,
"setup": False,
"setup_version": "",
@ -256,9 +256,9 @@ class MwPlugin(object):
if keyword != '' and not self.searchKey(data, keyword):
return info
plugin_info_t = self.makeCoexistList(data, type)
print(plugin_info_t)
plugin_t = self.makeCoexistList(data, type)
for index in range(len(plugin_t)):
info.append(plugin_t[index])
return info
@ -266,32 +266,46 @@ class MwPlugin(object):
self,
type: str | None = None,
keyword: str | None = None,
page: str | None = 1,
size: str | None = 10,
page: int | None = 1,
size: int | None = 10,
):
plugins_info = []
info = []
# print(mw.getPluginDir())
for name in os.listdir(self.__plugin_dir):
if name.startswith('.'):
continue
plugin_list = self.getPluginList(name,keyword,type=type)
print(plugin_list)
t = self.getPluginList(name, keyword, type=type)
for index in range(len(t)):
info.append(t[index])
return plugins_info
start = (page - 1) * size
end = start + size
_info = info[start:end]
# print(info)
return (_info, len(info))
def getList(
self,
type: str | None = None,
keyword: str | None = None,
page: str | None = 1,
size: str | None = 10,
page: int | None = 1,
size: int | None = 10,
) -> object:
# print(type,keyword,page,size)
rdata = {}
rdata['type'] = self.def_plugin_type
# print(type,keyword,page,size)
self.getAllPluginList(type,keyword, page, size)
data = self.getAllPluginList(type,keyword, page, size)
rdata['data'] = data[0]
args = {}
args['count'] = data[1]
args['p'] = page
args['tojs'] = 'getSList'
args['row'] = size
rdata['list'] = mw.getPage(args)
return rdata

Loading…
Cancel
Save