diff --git a/tools/build_out/application/signal_manager.py b/tools/build_out/application/signal_manager.py index 77f74e415c65275a9e4cfc00478a6e1298427b1f..057c337c361066772cc445106b5f99bed6c75cad 100644 --- a/tools/build_out/application/signal_manager.py +++ b/tools/build_out/application/signal_manager.py @@ -1,7 +1,7 @@ ''' Author: your name Date: 2021-06-30 18:03:41 -LastEditTime: 2021-07-19 18:47:22 +LastEditTime: 2021-07-20 03:14:41 LastEditors: Please set LastEditors Description: In User Settings Edit FilePath: \evm-store\tools\build_out\application\signal_manager.py @@ -65,6 +65,10 @@ class SignalManager(object): actionPostFilePaste = PySignal() # api actionPostAppReview = PySignal() + actionGetLauncher = PySignal() + actionSetLauncher = PySignal() + actionGetAppList = PySignal() + actionGetEpk = PySignal() actionApplicationBuild = PySignal() def __init__(self): diff --git a/tools/build_out/controllers/__init__.py b/tools/build_out/controllers/__init__.py index c4e88e847413a0f8040b8acce6d799e32131986a..780c53b494087dcdf1d343e75b6f75223363d582 100644 --- a/tools/build_out/controllers/__init__.py +++ b/tools/build_out/controllers/__init__.py @@ -1,7 +1,7 @@ ''' Author: your name Date: 2021-06-30 17:43:46 -LastEditTime: 2021-07-19 18:47:50 +LastEditTime: 2021-07-20 03:15:10 LastEditors: Please set LastEditors Description: In User Settings Edit FilePath: \evm-store\tools\build_out\controllers\__init__.py @@ -9,6 +9,7 @@ FilePath: \evm-store\tools\build_out\controllers\__init__.py #!/usr/bin/env python # -*- coding: utf_8 -*- +from signal import SIGABRT from application.signal_manager import signalManager from .area import areaManager from .api import appReview, buildAppResource @@ -79,4 +80,9 @@ def initConnect(): signalManager.actionPostFilePaste.connect(fileManager.paste) # api signalManager.actionPostAppReview.connect(appReview.post) + signalManager.actionSetLauncher.connect(appReview.get) + signalManager.actionGetLauncher.connect(appReview.getLauncher) signalManager.actionApplicationBuild.connect(buildAppResource.post) + signalManager.actionGetAppList.connect(appReview.getAppList) + signalManager.actionGetApp.connect(appReview.getApp) + signalManager.actionGetEpk.connect(appReview.getDownloadFile) diff --git a/tools/build_out/controllers/api.py b/tools/build_out/controllers/api.py index ebc93d609763505bcd33b683789ea2db644a6ee7..971bbcc5a562377a1eb0ff3e2c02a3219d596153 100644 --- a/tools/build_out/controllers/api.py +++ b/tools/build_out/controllers/api.py @@ -1,7 +1,7 @@ ''' Author: your name Date: 2021-07-12 11:14:48 -LastEditTime: 2021-07-19 19:25:09 +LastEditTime: 2021-07-20 03:14:03 LastEditors: Please set LastEditors Description: In User Settings Edit FilePath: \evm-store\tools\build_out\controllers\appi.py @@ -12,16 +12,49 @@ import json import shutil from pprint import pprint from pathlib import Path +import urllib from datetime import datetime +from urllib import parse, request +from urllib.parse import urlparse from application.app import db, config +from models.device import DeviceModel from models.annex import AnnexModel from models.app import AppModel from models.user import UserModel from models.package import PackageModel from webcreator.log import logger +from webcreator.utils import ThreadMaker from webcreator.utils.epk import EpkApp from webcreator.response import ResponseCode +@ThreadMaker +def update_download_information(ip, id): + params = { 'ak': 'aZEAgYG8wKuLd6DS9BmCloGtfnGGkRMn', 'coor': 'bd09ll' } + parameters = urllib.parse.urlencode(params) + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko' + } + + if ip != '127.0.0.1': + params.update({'ip': ip}) + parameters = urllib.parse.urlencode(params) + + url = 'http://api.map.baidu.com/location/ip' + req = request.Request(url='%s%s%s' % (url, '?', parameters), headers=headers) + ret = request.urlopen(req).read() + jsonData = json.loads(ret) + logger.info(jsonData) + + if (0 != jsonData['status']): + return None + + pack = PackageModel.query.filter(PackageModel.id==id).one_or_none() + if pack: + pack.address=jsonData['address'] + pack.ip=ip + pack.remarks=json.dumps(jsonData['content'], ensure_ascii=False) + db.session.commit() + class BuildAppResource(object): def __init__(self): super().__init__() @@ -109,6 +142,60 @@ class AppReview(object): def __init__(self): super().__init__() + def get(self, params, jwt={}): + logger.info(params) + user = UserModel.query.filter(UserModel.uuid==jwt.get("uuid")).one_or_none() + if not user: + return None, ResponseCode.USER_NOT_EXISTS + + app = AppModel.query.filter(AppModel.launcher=="yes", AppModel.create_at==user.id, AppModel.is_delete==False).one_or_none() + if app: + app.launcher = "no" + db.session.commit() + app = AppModel.query.filter(AppModel.uuid==params.get("app"), AppModel.create_at==user.id, AppModel.is_delete==False).one_or_none() + if not app: + return None, ResponseCode.APPLICATION_NOT_EXISTS + + app.launcher = "yes" + app.update_at = datetime.now() + app.update_by = user.id + db.session.commit() + return True, ResponseCode.HTTP_SUCCESS + + def getApp(self, params, jwt={}): + app = AppModel.query.filter(AppModel.uuid==params.get("uuid"), AppModel.is_delete==False).one_or_none() + if not app: + return None, ResponseCode.APPLICATION_NOT_EXISTS + + return app, ResponseCode.HTTP_SUCCESS + + def getLauncher(self, params, jwt={}): + device = DeviceModel.query.filter(DeviceModel.imei==params.get("imei"), AppModel.is_delete==False).one_or_none() + if not device: + return None, ResponseCode.DEVICE_NOT_EXISTS + + app = AppModel.query.filter(AppModel.launcher=="yes", AppModel.create_by==device.create_by, AppModel.is_delete==False).one_or_none() + if not app: + return None, ResponseCode.APPLICATION_NOT_EXISTS + + # æ ¹æ®app找到EPK文件,读å–出二进制数æ®ï¼Œè¿”回 + target_file = Path(config.UPLOAD_ROOT_DIR).joinpath(app.download_url) + if not target_file.exists(): + return None, ResponseCode.APPLICATION_NOT_EXISTS + return target_file, ResponseCode.HTTP_SUCCESS + + def getAppList(self, params, jwt={}): + filters = [AppModel.is_delete==False] + if params.get("review"): + filters.append(AppModel.app_review==params.get("review")) + if params.get("category"): + filters.append(AppModel.category==params.get("category")) + apps = AppModel.query.filter(*filters).all() + if not apps: + return None, ResponseCode.APPLICATION_NOT_EXISTS + + return apps, ResponseCode.HTTP_SUCCESS + def post(self, app, review, jwt={}): user = UserModel.query.filter(UserModel.uuid==jwt.get("uuid")).one_or_none() if not user: @@ -124,4 +211,56 @@ class AppReview(object): db.session.commit() return True, ResponseCode.HTTP_SUCCESS + def getDownloadFile(self, params, jwt={}): + # æµç¨‹å¦‚下: + # 获å–å‰ç«¯ä¼ æ¥çš„应用UUIDå’ŒIMEI + # æ ¹æ®åº”用UUID查找应用信æ¯ï¼Œæ‰¾ä¸åˆ°è¿”å›žå¤±è´¥ä¿¡æ¯ + # 如果应用ID是evue_launcherï¼Œåˆ™è¿›è¡Œå¦‚ä¸‹å¤„ç† + # éåŽ†ç³»ç»Ÿæ‰€æœ‰åº”ç”¨ï¼Œå°†ç›¸å…³åº”ç”¨æ ¹æ®4个一组拼接到一个数组里é¢åŽ» + # 最åŽå°†è¿™äº›ä¿¡æ¯å¯¼å‡ºä¸ºä¸€ä¸ªJSON文件 + # å°†evue_launcher.evueå’Œevue_dock.evue以åŠç›¸å…³èµ„æºæ–‡ä»¶è¿›è¡Œæ‰“包 + # 以上文件全部是å¤åˆ¶å¤„ç†ï¼Œæœ€åŽæ ¹æ®æ ¼å¼ç”Ÿæˆæ–‡ä»¶å¤¹ï¼Œå°†epk文件写入到这里 + # 读å–这个epk文件,以encoding='utf8'æ ¼å¼è¿”回å—èŠ‚æµ + # å¦åˆ™å°±æ˜¯æ™®é€šåº”用 + # 查找出这个应用路径以åŠä¾èµ–文件 + # 将这些文件进行打包 + # 读å–这个epk文件,以encoding='utf8'æ ¼å¼è¿”回å—èŠ‚æµ + # æ¤æ¬¡ä¸‹è½½å°†ç”Ÿæˆä¸€æ¬¡ä¸‹è½½è®°å½• + + # 当å‰è¿˜æ²¡æœ‰æ ¡éªŒå‰ç«¯ä¼ æ¥çš„IMEIæ˜¯å¦æ˜¯åˆæ³•çš„ + # æ ¹æ®IMEIæŸ¥æ‰¾è®¾å¤‡ï¼Œæ ¹æ®è®¾å¤‡æŸ¥æ‰¾ç”¨æˆ·ï¼Œæ ¹æ®ç”¨æˆ·æŸ¥æ‰¾åº”用 + + app = [] + # æ ¹æ®IMEI查找设备 + # device = Device.select().where(imei=data.get("imei")).first() + # logger.info(data) + # if not device: + # return False, "device not found" + # if not device.create_by: + # return False, "create user is null" + + if params.get("byId"): # 通过id下载应用 + app = AppModel.query.filter(AppModel.uuid==params.get("uuid")).one_or_none() + if not app: + return False, ResponseCode.APPLICATION_NOT_EXISTS + else: + app = AppModel.query.filter(AppModel.app_name==params.get("name")).order_by(AppModel.create_at.desc()) + if len(app) > 1: + app = AppModel.query.filter(AppModel.app_name == params.get("name")).order_by(AppModel.create_at.desc()).one_or_none() + + if not app: + return False, "app not found" + + epk_path = Path(config.UPLOAD_ROOT_DIR).joinpath(app.download_url) + if not epk_path.exists(): + return False, "epk file not found" + + pack = PackageModel(app=app.id, imei=params.get("imei")) + db.session.addd(pack) + db.session.commit() + if pack: + update_download_information(params.get('real_ip', '127.0.0.1'), pack.id) + + return epk_path, "get dictionary {}.".format("success" if epk_path else "no data") + appReview = AppReview() \ No newline at end of file diff --git a/tools/build_out/models/app.py b/tools/build_out/models/app.py index 7b317a14b2df0bc3777485fceddc24ad25e661c7..11c08b17413bcc4e8e6b1173ef7fea9954a31a05 100644 --- a/tools/build_out/models/app.py +++ b/tools/build_out/models/app.py @@ -11,7 +11,7 @@ class AppModel(PrimaryModel): app_icon = db.Column(db.String(200), nullable = False) app_version = db.Column(db.String(20), nullable = False) category = db.Column(db.String(50), nullable = False) - category_2th = db.Column(db.String(50), nullable = False) + launcher = db.Column(db.String(50), nullable = False) developer = db.Column(db.String(50), nullable = False) download_url = db.Column(db.String(200), nullable = False, default = '') app_file_size = db.Column(db.Integer, nullable = False) @@ -23,12 +23,12 @@ class AppModel(PrimaryModel): # db.Index('idx_xxx', 'xxx', mysql_using='btree'), # ) - def __init__(self, app_name, app_icon, app_version, category='', category_2th='', developer=0, download_url='', app_file_size=0, app_screen_size='', app_arch='', app_review=0, create_by=None, create_at=None, update_by=None, update_at=None, remarks=""): + def __init__(self, app_name, app_icon, app_version, category='', launcher='', developer=0, download_url='', app_file_size=0, app_screen_size='', app_arch='', app_review=0, create_by=None, create_at=None, update_by=None, update_at=None, remarks=""): self.app_name = app_name self.app_icon = app_icon self.app_version = app_version self.category = category - self.category_2th = category_2th + self.launcher = launcher self.developer = developer self.download_url = download_url self.app_file_size = app_file_size @@ -50,7 +50,7 @@ class AppModel(PrimaryModel): 'app_icon': self.app_icon, 'app_version': self.app_version, 'category': self.category, - 'category_2th': self.category_2th, + 'launcher': self.launcher, 'developer': self.developer, 'download_url': self.download_url, 'app_file_size': self.app_file_size, @@ -74,7 +74,7 @@ class PostAppSchema(ma.SQLAlchemySchema): app_icon = fields.String(required=False) app_version = ma.auto_field() category = ma.auto_field() - category_2th = fields.String(required=False) + launcher = fields.String(required=False) developer = fields.String(required=False) app_screen_size = ma.auto_field() app_arch = ma.auto_field() @@ -130,7 +130,7 @@ class GetAppSchema(ma.SQLAlchemySchema): app_name = ma.auto_field() app_version = ma.auto_field() category = ma.auto_field() - category_2th = ma.auto_field() + launcher = ma.auto_field() app_arch = ma.auto_field() getAppSchema = GetAppSchema() @@ -148,6 +148,6 @@ class PutAppSchema(ma.SQLAlchemySchema): app_arch = ma.auto_field() app_review = ma.auto_field() category = ma.auto_field() - category_2th = ma.auto_field() + launcher = ma.auto_field() putAppSchema = PutAppSchema() diff --git a/tools/build_out/views/openapi.py b/tools/build_out/views/openapi.py index 079a2639903926b9514b026412d9771473936261..ae5f49240a7a504053f806d261409195b64fd9b4 100644 --- a/tools/build_out/views/openapi.py +++ b/tools/build_out/views/openapi.py @@ -1,7 +1,7 @@ ''' Author: your name Date: 2021-07-19 14:29:33 -LastEditTime: 2021-07-19 19:27:21 +LastEditTime: 2021-07-20 03:02:05 LastEditors: Please set LastEditors Description: In User Settings Edit FilePath: \evm-store\tools\build_out\views\api.py @@ -22,15 +22,42 @@ from werkzeug.datastructures import FileStorage from marshmallow.exceptions import ValidationError from application.config import config from application.signal_manager import signalManager +from models.app import postAppSchema, deleteAppSchema, getListAppSchema, getListAppsSchema, getAppSchema from webcreator.log import logger from webcreator.utils.ccode import convert_string from webcreator.response import ResponseCode, response_result class AppReviewResource(Resource): def __init__(self): - # ç‰¹æ®Šå‚æ•°ï¼Œå³ä¸æ˜¯ä»Žjson获å–傿•°çš„æŽ¥å£ï¼Œå¯ä»¥å°†è¿™ä¸ªæ³¨é‡Šæ‰“å¼€ self.parser = RequestParser() + # 设置å¯åŠ¨å™¨æŽ¥å£ + @jwt_required(locations=["headers"]) + def get(self): + self.parser.add_argument("app", type=str, location="args", required=False) + args = self.parser.parse_args() + + try: + data = dict() + for key, value in args.items(): + if value != None: + data[key] = value + + jwt = get_jwt_identity() + result, message = signalManager.actionSetLauncher.emit(data, jwt) + if result: + return response_result(message, data=result) + return response_result(message) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + traceback.print_exc() + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + @jwt_required(locations=["headers"]) def post(self): self.parser.add_argument("review", type=int, location="json", default=0, required=True) @@ -163,3 +190,185 @@ class ObfuscatedCode(Resource): data = e.args current_app.logger.error(e) return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +# 获å–å¯åŠ¨å™¨æŽ¥å£ +class LauncherResource(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + # self.parser.add_argument("page", type=int, location="args", default=1) + self.parser.add_argument("imei", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + jwt = get_jwt_identity() + data = dict() + for key, value in args.items(): + if value != None: + data[key] = value + + result, message = signalManager.actionGetLauncher.emit(data, jwt) + if result: + ret = result.read_bytes() + # with open(result.as_posix(), "rb") as f: + # ret = f.read() + # logger.info(type(ret)) + return ret + return response_result(message, data=result) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +# 获å–Appåˆ—è¡¨æŽ¥å£ +class AppListResource(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + # self.parser.add_argument("page", type=int, location="args", default=1) + self.parser.add_argument("category", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + data = dict() + for key, value in args.items(): + if value != None: + data[key] = value + result, message = signalManager.actionGetApp.emit(data, {}) + if result: + result = getListAppsSchema.dumps(result.items) + return response_result(message, data=result) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +# 获å–åº”ç”¨æŽ¥å£ +class App(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + # self.parser.add_argument("page", type=int, location="args", default=1) + self.parser.add_argument("uuid", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + data = dict() + for key, value in args.items(): + if value != None: + data[key] = value + + result, message = signalManager.actionGetApp.emit(data) + if result: + result = getAppSchema.dump(result) + return response_result(message, data=result) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +# 获å–åº”ç”¨ä¿¡æ¯æŽ¥å£ +class AppInfo(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + # self.parser.add_argument("page", type=int, location="args", default=1) + self.parser.add_argument("imei", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + + return response_result(ResponseCode.HTTP_SUCCESS) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +# 下载EPKæ–‡ä»¶æŽ¥å£ +class DownloadEpk(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + self.parser.add_argument("uuid", type=str, location="json", required=True) + self.parser.add_argument("imei", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + data = dict() + for key, value in args.items(): + if value != None: + data[key] = value + + data.update({ 'real_ip': request.headers.get('X-Forwarded-For', '127.0.0.1') }) + result, message = signalManager.actionGetDownload.emit(data) + # 读å–epkæ–‡ä»¶ï¼ŒæŒ‰ç…§æ ¼å¼è¿”å›žç›¸åº”ç»“æž„ä½“æ•°æ® + logger.info(data) + if result: + ret = result.read_bytes() + # with open(result.as_posix(), "rb") as f: + # ret = f.read() + # logger.info(type(ret)) + return ret + return response_result(message, data=result) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) + +class DownloadApp(Resource): + def __init__(self) -> None: + super().__init__() + self.parser = RequestParser() + + def get(self): + # self.parser.add_argument("page", type=int, location="args", default=1) + self.parser.add_argument("imei", type=str, location="json", required=True) + args = self.parser.parse_args() + + try: + print(args) + + return response_result(ResponseCode.HTTP_SUCCESS) + except ValidationError as e: + return response_result(ResponseCode.HTTP_INVAILD_REQUEST, data=e.messages) + except Exception as e: + data = None + if hasattr(e, 'args'): + data = e.args + current_app.logger.error(e) + return response_result(ResponseCode.HTTP_SERVER_ERROR, data=data) diff --git a/tools/config.json b/tools/config.json index 168a976928e2a749d16b9483bf225e0f148404ce..1fe7d90da20f34560ab925a12297bed60da5ee63 100644 --- a/tools/config.json +++ b/tools/config.json @@ -370,7 +370,7 @@ "toJson": true }, { - "name": "category_2th", + "name": "launcher", "dataType": "String", "default": "''", "length": 20, @@ -443,7 +443,7 @@ "name": "category" }, { - "name": "category_2th" + "name": "launcher" }, { "name": "developer" @@ -494,7 +494,7 @@ "name": "category" }, { - "name": "category_2th" + "name": "launcher" }, { "name": "app_arch" @@ -516,7 +516,7 @@ "name": "category" }, { - "name": "category_2th" + "name": "launcher" }, { "name": "app_arch" @@ -550,7 +550,7 @@ "name": "category" }, { - "name": "category_2th" + "name": "launcher" } ] } diff --git a/tools/frontend/src/api/openapi.js b/tools/frontend/src/api/openapi.js index cc8cf3d7071c79b6d67e0aca9719adc5c39db58d..41895a5f47e693aa3e455e346f0eb243c482281f 100644 --- a/tools/frontend/src/api/openapi.js +++ b/tools/frontend/src/api/openapi.js @@ -1,7 +1,7 @@ /* * @Author: your name * @Date: 2021-07-15 09:33:39 - * @LastEditTime: 2021-07-19 21:02:00 + * @LastEditTime: 2021-07-20 01:59:15 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \evm-store\tools\frontend\src\api\openapi.js @@ -85,6 +85,14 @@ export function updateReview(params) { }); } +export function updateLauncher(params) { + return request({ + url: "/api/v1/api/app-review", + method: "get", + params, + }); +} + export function getDeviceList(params) { return request({ url: "/api/v1/device", diff --git a/tools/frontend/src/views/Application/Index.vue b/tools/frontend/src/views/Application/Index.vue index 59d7299798c8639d7c0e8c61b97dc4d22b08c137..8b71df8f9e32dbb44f073b4d118ebd4a7d876df4 100644 --- a/tools/frontend/src/views/Application/Index.vue +++ b/tools/frontend/src/views/Application/Index.vue @@ -307,6 +307,8 @@ <a-divider type="vertical" /> <a href="javascript:;" @click="updateReview(record, 0)">下架</a> <a-divider type="vertical" /> + <a href="javascript:;" @click="updateLauncher(record)">设为å¯åЍ噍</a> + <a-divider type="vertical" /> <a href="javascript:;" @click="deleteApplication(record)">åˆ é™¤</a> </template> </a-table> @@ -378,7 +380,8 @@ import { getApplicationList, rebuildApplication, deleteApplication, - updateReview + updateReview, + updateLauncher } from "@/api/openapi"; import { mapTrim } from "@/utils/index"; @@ -479,6 +482,13 @@ export default { message.error(err.msg) }) }, + updateLauncher(record) { + updateLauncher({ app: record.uuid }).then(res => { + message.success(res.msg) + }).catch(err => { + message.error(err.msg) + }) + }, resetForm() { this.$nextTick(() => { this.form.resetFields();