From 115d1c95df02a76bbbdea05ba8acc1dd4f2230b5 Mon Sep 17 00:00:00 2001 From: nineven Date: Fri, 25 Feb 2022 16:47:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/api/base_views.py | 4 +- fir_ser/api/utils/utils.py | 14 ++++--- fir_ser/api/views/__init__.py | 4 ++ fir_ser/api/views/apps.py | 4 +- fir_ser/api/views/uploads.py | 4 +- .../common/core/{singals.py => signals.py} | 14 ++++++- fir_ser/common/libs/mp/wechat.py | 22 ++++++++++ fir_ser/common/utils/download.py | 2 +- .../xsign/utils/{singals.py => signals.py} | 42 +++++++++++++++++-- 9 files changed, 92 insertions(+), 18 deletions(-) rename fir_ser/common/core/{singals.py => signals.py} (53%) rename fir_ser/xsign/utils/{singals.py => signals.py} (68%) diff --git a/fir_ser/api/base_views.py b/fir_ser/api/base_views.py index b1925ec..631cb3c 100644 --- a/fir_ser/api/base_views.py +++ b/fir_ser/api/base_views.py @@ -11,7 +11,7 @@ from api.utils.response import BaseResponse from api.utils.utils import delete_local_files, delete_app_screenshots_files, change_storage_and_change_head_img, \ migrating_storage_data, clean_storage_data, check_storage_is_new_storage from common.cache.state import MigrateStorageState -from common.core.singals import delete_app_signal +from common.core.signals import delete_app_signal from common.utils.caches import del_cache_response_by_short, del_cache_by_delete_app, \ del_cache_storage from common.utils.storage import Storage @@ -31,7 +31,7 @@ def app_delete(app_obj): res.msg = "数据迁移中" return res - delete_app_signal.send(None, app_pk=app_obj.pk) + delete_app_signal.send(None, app_pk=app_obj) storage = Storage(user_obj) has_combo = app_obj.has_combo diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index 3b8fd3f..ea5c7e5 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -16,6 +16,7 @@ from api.models import UserInfo, AppReleaseInfo, AppScreenShot, Token, UserAdDis from api.utils.modelutils import get_app_d_count_by_app_id from common.base.baseutils import get_real_ip_address from common.cache.storage import UserTokenCache, TempCache +from common.core.signals import xsign_migrate_data_signal, xsign_clean_data_signal from common.core.sysconfig import Config from common.libs.storage.localApi import LocalStorage from common.utils.caches import consume_user_download_times @@ -229,9 +230,11 @@ def migrating_storage_data(user_obj, new_storage_obj, clean_old_data): for screenshot_obj in AppScreenShot.objects.filter(app_id=app_release_obj.app_id).all(): migrating_storage_file_data(user_obj, screenshot_obj.screenshot_url, new_storage_obj, clean_old_data) # 迁移超级签数据 - for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): - filename = get_filename_from_apptype(apptodev_obj.binary_file, app_release_obj.release_type) - migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_data) + xsign_migrate_data_signal.send(None, app_release_obj=app_release_obj, user_obj=user_obj, + new_storage_obj=new_storage_obj, clean_old_data=clean_old_data) + # for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): + # filename = get_filename_from_apptype(apptodev_obj.binary_file, app_release_obj.release_type) + # migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_data) # 消费下载次数 amount = get_app_d_count_by_app_id(app_release_obj.app_id.app_id) consume_user_download_times(user_obj.pk, app_release_obj.app_id, amount, auth_status) @@ -246,8 +249,9 @@ def clean_storage_data(user_obj, storage_obj=None): storage_obj.delete_file(app_release_obj.icon_url) for screenshot_obj in AppScreenShot.objects.filter(app_id=app_release_obj.app_id).all(): storage_obj.delete_file(screenshot_obj.screenshot_url) - for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): - storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) + xsign_clean_data_signal.send(None, app_release_obj=app_release_obj, storage_obj=storage_obj) + # for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): + # storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) return True diff --git a/fir_ser/api/views/__init__.py b/fir_ser/api/views/__init__.py index 87c5556..5a9293f 100644 --- a/fir_ser/api/views/__init__.py +++ b/fir_ser/api/views/__init__.py @@ -3,3 +3,7 @@ # project: 10月 # author: liuyu # date: 2020/10/12 + +from xsign.utils.signals import main + +main() diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index be5e504..ffac372 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -19,7 +19,7 @@ from api.utils.serializer import AppsSerializer, AppReleaseSerializer, AppsListS from api.utils.utils import delete_local_files, delete_app_screenshots_files from common.cache.state import MigrateStorageState from common.core.auth import ExpiringTokenAuthentication -from common.core.singals import delete_app_signal +from common.core.signals import delete_app_signal from common.utils.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app from common.utils.storage import Storage @@ -249,7 +249,7 @@ class AppReleaseInfoView(APIView): app_release_obj.delete() elif app_release_obj.is_master and app_release_count < 2: logger.info(f"delete app master release {app_release_obj} and clean app {app_obj}") - delete_app_signal.send(None, app_pk=app_obj.pk) + delete_app_signal.send(None, app_pk=app_obj) storage.delete_file(app_release_obj.release_id, app_release_obj.release_type) delete_local_files(app_release_obj.release_id, app_release_obj.release_type) diff --git a/fir_ser/api/views/uploads.py b/fir_ser/api/views/uploads.py index 2813549..89af1bd 100644 --- a/fir_ser/api/views/uploads.py +++ b/fir_ser/api/views/uploads.py @@ -17,7 +17,7 @@ from api.utils.response import BaseResponse from common.base.baseutils import make_app_uuid, make_from_user_uuid from common.cache.state import MigrateStorageState from common.core.auth import ExpiringTokenAuthentication -from common.core.singals import run_resign_task_signal +from common.core.signals import run_resign_task_signal from common.core.sysconfig import Config from common.utils.caches import upload_file_tmp_name, del_cache_response_by_short from common.utils.storage import Storage @@ -145,7 +145,7 @@ class AppAnalyseView(APIView): app_obj = Apps.objects.filter(bundle_id=data.get("bundleid"), user_id=request.user, type=1).first() if app_obj: - run_resign_task_signal.send(sender=None, app_pk=app_obj.pk) + run_resign_task_signal.send(sender=None, app_obj=app_obj) else: storage.delete_file(app_tmp_filename) storage.delete_file(png_tmp_filename) diff --git a/fir_ser/common/core/singals.py b/fir_ser/common/core/signals.py similarity index 53% rename from fir_ser/common/core/singals.py rename to fir_ser/common/core/signals.py index 25f328f..3c2f6b9 100644 --- a/fir_ser/common/core/singals.py +++ b/fir_ser/common/core/signals.py @@ -11,15 +11,25 @@ logger = logging.getLogger(__name__) """ 更新应用的时候,是否同时更新超级签名数据 """ -run_resign_task_signal = Signal(providing_args=["app_pk"]) +run_resign_task_signal = Signal(providing_args=["app_obj"]) """ 删除应用时的信号,用户清理签名相关数据 """ -delete_app_signal = Signal(providing_args=["app_pk"]) +delete_app_signal = Signal(providing_args=["app_obj"]) """ 下载超级签名数据 """ xsign_app_download_url_signal = Signal(providing_args=["app_pk", "udid", "download_url_type", "limit"]) + +""" +迁移超级签名数据 +""" +xsign_migrate_data_signal = Signal(providing_args=["app_release_obj", "user_obj", "new_storage_obj", "clean_old_data"]) + +""" +清理超级签名数据 +""" +xsign_clean_data_signal = Signal(providing_args=["app_release_obj", "storage_obj"]) diff --git a/fir_ser/common/libs/mp/wechat.py b/fir_ser/common/libs/mp/wechat.py index 4764fc0..721a7d0 100644 --- a/fir_ser/common/libs/mp/wechat.py +++ b/fir_ser/common/libs/mp/wechat.py @@ -379,3 +379,25 @@ class WxTemplateMsg(object): }, } return self.send_msg(to_user, msg_id, content_data) + + def auth_code_msg(self, to_user, wx_nick_name, code, expire_date): + msg_id = 'vRCegZatP18LAe9ytLirwfL1CFyzaCQwM89hMAKsUAA' + content_data = { + "first": { + "value": f"您好,“{wx_nick_name}”", + "color": "#173177" + }, + "keyword1": { + "value": code, + "color": "#173177" + }, + "keyword2": { + "value": f"{expire_date}内有效", + "color": "#173177" + }, + "remark": { + "value": "若非本人操作,可能您的帐号存在安全风险,请及时修改密码", + "color": "#173177" + }, + } + return self.send_msg(to_user, msg_id, content_data) diff --git a/fir_ser/common/utils/download.py b/fir_ser/common/utils/download.py index c308e4e..8ddbbda 100644 --- a/fir_ser/common/utils/download.py +++ b/fir_ser/common/utils/download.py @@ -12,7 +12,7 @@ from api.models import Apps, UserInfo from api.utils.modelutils import get_app_d_count_by_app_id, add_remote_info_from_request from common.base.baseutils import check_app_password, get_real_ip_address from common.cache.storage import AppDownloadTodayTimesCache, AppDownloadTimesCache, DownloadUrlCache, AppInstanceCache -from common.core.singals import xsign_app_download_url_signal +from common.core.signals import xsign_app_download_url_signal from common.core.sysconfig import Config from common.utils.caches import consume_user_download_times from common.utils.storage import Storage, LocalStorage diff --git a/fir_ser/xsign/utils/singals.py b/fir_ser/xsign/utils/signals.py similarity index 68% rename from fir_ser/xsign/utils/singals.py rename to fir_ser/xsign/utils/signals.py index b20fbf2..0864cdb 100644 --- a/fir_ser/xsign/utils/singals.py +++ b/fir_ser/xsign/utils/signals.py @@ -7,8 +7,9 @@ import logging from django.dispatch import receiver from api.models import AppReleaseInfo -from api.models import Apps -from common.core.singals import run_resign_task_signal, delete_app_signal, xsign_app_download_url_signal +from api.utils.utils import migrating_storage_file_data, get_filename_from_apptype +from common.core.signals import run_resign_task_signal, delete_app_signal, xsign_app_download_url_signal, \ + xsign_migrate_data_signal, xsign_clean_data_signal from common.core.sysconfig import Config from common.libs.storage.localApi import LocalStorage from xsign.models import AppUDID, APPToDeveloper, APPSuperSignUsedInfo @@ -24,7 +25,7 @@ logger = logging.getLogger(__name__) @receiver(run_resign_task_signal) def run_resign_task_callback(sender, **kwargs): - app_obj = Apps.objects.filter(pk=kwargs.get('app_pk')).first() + app_obj = kwargs.get('app_obj') if app_obj: AppUDID.objects.filter(app_id=app_obj, sign_status__gte=3).update(sign_status=3) if app_obj.change_auto_sign: @@ -40,7 +41,7 @@ def run_resign_task_callback(sender, **kwargs): @receiver(delete_app_signal) def delete_app_callback(sender, **kwargs): - app_obj = Apps.objects.filter(pk=kwargs.get('app_pk')).first() + app_obj = kwargs.get('app_obj') if app_obj: count = APPToDeveloper.objects.filter(app_id=app_obj).count() if app_obj.issupersign or count > 0: @@ -83,3 +84,36 @@ def xsign_app_download_url_callback(sender, **kwargs): return "", "" else: return "", "" + + +""" +迁移超级签名数据 +""" + + +@receiver(xsign_migrate_data_signal) +def xsign_migrate_data_signal_callback(sender, **kwargs): + app_release_obj = kwargs.get('app_release_obj') + user_obj = kwargs.get('user_obj') + new_storage_obj = kwargs.get('new_storage_obj') + clean_old_data = kwargs.get('clean_old_data') + for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): + filename = get_filename_from_apptype(apptodev_obj.binary_file, app_release_obj.release_type) + migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_data) + + +""" +清理超级签名数据 +""" + + +@receiver(xsign_clean_data_signal) +def xsign_clean_data_signal_callback(sender, **kwargs): + app_release_obj = kwargs.get('app_release_obj') + storage_obj = kwargs.get('storage_obj') + for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): + storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) + + +def main(): + logger.info('signal receiver init success')