信号优化

xsign
nineven 3 years ago
parent e54f6c1286
commit 115d1c95df
  1. 4
      fir_ser/api/base_views.py
  2. 14
      fir_ser/api/utils/utils.py
  3. 4
      fir_ser/api/views/__init__.py
  4. 4
      fir_ser/api/views/apps.py
  5. 4
      fir_ser/api/views/uploads.py
  6. 14
      fir_ser/common/core/signals.py
  7. 22
      fir_ser/common/libs/mp/wechat.py
  8. 2
      fir_ser/common/utils/download.py
  9. 42
      fir_ser/xsign/utils/signals.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, \ 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 migrating_storage_data, clean_storage_data, check_storage_is_new_storage
from common.cache.state import MigrateStorageState 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, \ from common.utils.caches import del_cache_response_by_short, del_cache_by_delete_app, \
del_cache_storage del_cache_storage
from common.utils.storage import Storage from common.utils.storage import Storage
@ -31,7 +31,7 @@ def app_delete(app_obj):
res.msg = "数据迁移中" res.msg = "数据迁移中"
return res 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) storage = Storage(user_obj)
has_combo = app_obj.has_combo has_combo = app_obj.has_combo

@ -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 api.utils.modelutils import get_app_d_count_by_app_id
from common.base.baseutils import get_real_ip_address from common.base.baseutils import get_real_ip_address
from common.cache.storage import UserTokenCache, TempCache 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.core.sysconfig import Config
from common.libs.storage.localApi import LocalStorage from common.libs.storage.localApi import LocalStorage
from common.utils.caches import consume_user_download_times 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(): 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) 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(): xsign_migrate_data_signal.send(None, app_release_obj=app_release_obj, user_obj=user_obj,
filename = get_filename_from_apptype(apptodev_obj.binary_file, app_release_obj.release_type) new_storage_obj=new_storage_obj, clean_old_data=clean_old_data)
migrating_storage_file_data(user_obj, filename, 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)
# 消费下载次数 # 消费下载次数
amount = get_app_d_count_by_app_id(app_release_obj.app_id.app_id) 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) 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) storage_obj.delete_file(app_release_obj.icon_url)
for screenshot_obj in AppScreenShot.objects.filter(app_id=app_release_obj.app_id).all(): for screenshot_obj in AppScreenShot.objects.filter(app_id=app_release_obj.app_id).all():
storage_obj.delete_file(screenshot_obj.screenshot_url) storage_obj.delete_file(screenshot_obj.screenshot_url)
for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): xsign_clean_data_signal.send(None, app_release_obj=app_release_obj, storage_obj=storage_obj)
storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) # 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 return True

@ -3,3 +3,7 @@
# project: 10月 # project: 10月
# author: liuyu # author: liuyu
# date: 2020/10/12 # date: 2020/10/12
from xsign.utils.signals import main
main()

@ -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 api.utils.utils import delete_local_files, delete_app_screenshots_files
from common.cache.state import MigrateStorageState from common.cache.state import MigrateStorageState
from common.core.auth import ExpiringTokenAuthentication 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.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app
from common.utils.storage import Storage from common.utils.storage import Storage
@ -249,7 +249,7 @@ class AppReleaseInfoView(APIView):
app_release_obj.delete() app_release_obj.delete()
elif app_release_obj.is_master and app_release_count < 2: 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}") 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) 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) delete_local_files(app_release_obj.release_id, app_release_obj.release_type)

@ -17,7 +17,7 @@ from api.utils.response import BaseResponse
from common.base.baseutils import make_app_uuid, make_from_user_uuid from common.base.baseutils import make_app_uuid, make_from_user_uuid
from common.cache.state import MigrateStorageState from common.cache.state import MigrateStorageState
from common.core.auth import ExpiringTokenAuthentication 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.core.sysconfig import Config
from common.utils.caches import upload_file_tmp_name, del_cache_response_by_short from common.utils.caches import upload_file_tmp_name, del_cache_response_by_short
from common.utils.storage import Storage 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() app_obj = Apps.objects.filter(bundle_id=data.get("bundleid"), user_id=request.user, type=1).first()
if app_obj: 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: else:
storage.delete_file(app_tmp_filename) storage.delete_file(app_tmp_filename)
storage.delete_file(png_tmp_filename) storage.delete_file(png_tmp_filename)

@ -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_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"])

@ -379,3 +379,25 @@ class WxTemplateMsg(object):
}, },
} }
return self.send_msg(to_user, msg_id, content_data) 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)

@ -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 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.base.baseutils import check_app_password, get_real_ip_address
from common.cache.storage import AppDownloadTodayTimesCache, AppDownloadTimesCache, DownloadUrlCache, AppInstanceCache 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.core.sysconfig import Config
from common.utils.caches import consume_user_download_times from common.utils.caches import consume_user_download_times
from common.utils.storage import Storage, LocalStorage from common.utils.storage import Storage, LocalStorage

@ -7,8 +7,9 @@ import logging
from django.dispatch import receiver from django.dispatch import receiver
from api.models import AppReleaseInfo from api.models import AppReleaseInfo
from api.models import Apps from api.utils.utils import migrating_storage_file_data, get_filename_from_apptype
from common.core.singals import run_resign_task_signal, delete_app_signal, xsign_app_download_url_signal 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.core.sysconfig import Config
from common.libs.storage.localApi import LocalStorage from common.libs.storage.localApi import LocalStorage
from xsign.models import AppUDID, APPToDeveloper, APPSuperSignUsedInfo from xsign.models import AppUDID, APPToDeveloper, APPSuperSignUsedInfo
@ -24,7 +25,7 @@ logger = logging.getLogger(__name__)
@receiver(run_resign_task_signal) @receiver(run_resign_task_signal)
def run_resign_task_callback(sender, **kwargs): 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: if app_obj:
AppUDID.objects.filter(app_id=app_obj, sign_status__gte=3).update(sign_status=3) AppUDID.objects.filter(app_id=app_obj, sign_status__gte=3).update(sign_status=3)
if app_obj.change_auto_sign: if app_obj.change_auto_sign:
@ -40,7 +41,7 @@ def run_resign_task_callback(sender, **kwargs):
@receiver(delete_app_signal) @receiver(delete_app_signal)
def delete_app_callback(sender, **kwargs): 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: if app_obj:
count = APPToDeveloper.objects.filter(app_id=app_obj).count() count = APPToDeveloper.objects.filter(app_id=app_obj).count()
if app_obj.issupersign or count > 0: if app_obj.issupersign or count > 0:
@ -83,3 +84,36 @@ def xsign_app_download_url_callback(sender, **kwargs):
return "", "" return "", ""
else: else:
return "", "" 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')
Loading…
Cancel
Save