优化签名包下载逻辑

xsign
MMXX 3 years ago
parent 98fe1d5f61
commit 77d97fd1d2
  1. 4
      fir_ser/api/base_views.py
  2. 2
      fir_ser/api/utils/modelutils.py
  3. 33
      fir_ser/api/utils/signalutils.py
  4. 7
      fir_ser/api/utils/utils.py
  5. 4
      fir_ser/api/views/apps.py
  6. 6
      fir_ser/api/views/download.py
  7. 4
      fir_ser/api/views/uploads.py
  8. 5
      fir_ser/common/core/signals.py
  9. 6
      fir_ser/common/utils/download.py
  10. 16
      fir_ser/xsign/utils/modelutils.py
  11. 14
      fir_ser/xsign/utils/signals.py
  12. 8
      fir_ser/xsign/utils/supersignutils.py
  13. 17
      fir_ser/xsign/views/supersign.py

@ -8,10 +8,10 @@ import logging
from api.models import AppReleaseInfo, UserInfo, AppScreenShot, AppStorage
from api.utils.response import BaseResponse
from api.utils.signalutils import run_delete_app_signal
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.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)
run_delete_app_signal(app_obj)
storage = Storage(user_obj)
has_combo = app_obj.has_combo

@ -96,6 +96,8 @@ def get_min_default_domain_cname_obj(is_system=True):
def get_filename_form_file(filename):
file_id_list = filename.split('.')
if file_id_list[-1] in ['ipa', 'apk']:
# app_release_obj = APPToDeveloper.objects.filter(binary_file='.'.join(file_id_list[0:-1])).first()
# if not app_release_obj:
app_release_obj = AppReleaseInfo.objects.filter(release_id='.'.join(file_id_list[0:-1])).first()
if app_release_obj:
app_obj = app_release_obj.app_id

@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# project: 3月
# author: NinEveN
# date: 2022/3/3
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, xsign_app_release_obj_signal
def run_signal_resign_utils(app_obj):
return run_resign_task_signal.send(sender=None, app_obj=app_obj)
def run_delete_app_signal(app_obj):
return delete_app_signal.send(None, app_pk=app_obj)
def run_xsign_app_download_url(app_obj, udid, download_url_type, limit):
return xsign_app_download_url_signal.send(None, app_pk=app_obj.get('pk'), udid=udid,
download_url_type=download_url_type, limit=limit)[0][1]
def run_xsign_migrate_data(app_release_obj, user_obj, new_storage_obj, clean_old_data):
return 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)
def run_xsign_clean_data(app_release_obj, storage_obj):
return xsign_clean_data_signal.send(None, app_release_obj=app_release_obj, storage_obj=storage_obj)
def run_get_xsign_binary_file(binary_file):
return xsign_app_release_obj_signal.send(None, binary_file=binary_file)[0][1]

@ -12,9 +12,9 @@ from django.core.cache import cache
from api.models import UserInfo, AppReleaseInfo, AppScreenShot, Token, UserAdDisplayInfo
from api.utils.modelutils import get_app_d_count_by_app_id
from api.utils.signalutils import run_xsign_migrate_data, run_xsign_clean_data
from common.base.baseutils import get_real_ip_address
from common.cache.storage import UserTokenCache
from common.core.signals import xsign_migrate_data_signal, xsign_clean_data_signal
from common.libs.storage.localApi import LocalStorage
from common.utils.caches import consume_user_download_times
from common.utils.storage import Storage
@ -157,8 +157,7 @@ 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)
# 迁移超级签数据
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)
run_xsign_migrate_data(app_release_obj, user_obj, 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)
@ -176,7 +175,7 @@ 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)
xsign_clean_data_signal.send(None, app_release_obj=app_release_obj, storage_obj=storage_obj)
run_xsign_clean_data(app_release_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

@ -16,10 +16,10 @@ from api.models import Apps, AppReleaseInfo, UserInfo, AppScreenShot
from api.utils.modelutils import get_user_domain_name, get_app_domain_name
from api.utils.response import BaseResponse
from api.utils.serializer import AppsSerializer, AppReleaseSerializer, AppsListSerializer, AppsQrListSerializer
from api.utils.signalutils import run_delete_app_signal
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.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)
run_delete_app_signal(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)

@ -16,6 +16,7 @@ from api.utils.modelutils import get_filename_form_file, check_app_domain_name_a
ad_random_weight, get_app_download_uri
from api.utils.response import BaseResponse
from api.utils.serializer import AppsShortSerializer, AppAdInfoSerializer
from api.utils.signalutils import run_get_xsign_binary_file
from common.base.baseutils import get_origin_domain_name, format_get_uri, make_random_uuid, make_resigned
from common.core.decorators import cache_response # 本来使用的是 drf-extensions==0.7.0 但是还未支持该版本Django
from common.core.response import mobileprovision_file_response, file_response, ApiResponse
@ -76,8 +77,11 @@ class DownloadView(APIView):
file_path = os.path.join(settings.MEDIA_ROOT, filename)
try:
if os.path.isfile(file_path):
status, x_filename = run_get_xsign_binary_file(filename)
if not status:
x_filename = get_filename_form_file(filename)
return FileResponse(open(file_path, 'rb'), as_attachment=True,
filename=get_filename_form_file(filename))
filename=x_filename)
except Exception as e:
logger.error(f"read {file_path} failed Exception:{e}")

@ -14,10 +14,10 @@ from api.models import Apps, AppReleaseInfo, UserInfo, AppScreenShot, Certificat
from api.utils.apputils import get_random_short, save_app_infos
from api.utils.modelutils import get_app_download_uri, check_bundle_id_legal
from api.utils.response import BaseResponse
from api.utils.signalutils import run_signal_resign_utils
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.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_obj=app_obj)
run_signal_resign_utils(app_obj)
else:
storage.delete_file(app_tmp_filename)
storage.delete_file(png_tmp_filename)

@ -33,3 +33,8 @@ xsign_migrate_data_signal = Signal(providing_args=["app_release_obj", "user_obj"
清理超级签名数据
"""
xsign_clean_data_signal = Signal(providing_args=["app_release_obj", "storage_obj"])
"""
根据binary_file获取签名应用数据
"""
xsign_app_release_obj_signal = Signal(providing_args=["binary_file"])

@ -10,9 +10,9 @@ import time
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.signalutils import run_xsign_app_download_url
from common.base.baseutils import check_app_password, get_real_ip_address
from common.cache.storage import AppDownloadTodayTimesCache, AppDownloadTimesCache, DownloadUrlCache, AppInstanceCache
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
@ -29,9 +29,7 @@ def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='',
if app_obj.get('issupersign', None):
download_url_type = 'mobileconifg'
else:
result = xsign_app_download_url_signal.send(None, app_pk=app_obj.get('pk'), udid=udid,
download_url_type=download_url_type, limit=limit)
return result[0][1]
return run_xsign_app_download_url(app_obj, udid, download_url_type, limit)
supersign = Config.DEFAULT_MOBILEPROVISION.get("supersign")
mobileconifg = ""

@ -163,3 +163,19 @@ def get_app_sign_info(app_obj):
'private_developer_used_number': DeveloperDevicesID.objects.filter(app_id=app_obj,
developerid__appledevelopertoappuse__app_id=app_obj).distinct().count()
}
def get_filename_form_file(filename):
file_id_list = filename.split('.')
check = False
if file_id_list[-1] in ['ipa']:
app_to_obj = APPToDeveloper.objects.filter(binary_file='.'.join(file_id_list[0:-1])).first()
if app_to_obj:
app_obj = app_to_obj.app_id
if app_obj.type == 0:
f_type = '.apk'
else:
f_type = '.ipa'
filename = f"{app_obj.name}-sign-{app_obj.short}{f_type}"
check = True
return check, filename

@ -9,11 +9,12 @@ from django.dispatch import receiver
from api.models import AppReleaseInfo
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
xsign_migrate_data_signal, xsign_clean_data_signal, xsign_app_release_obj_signal
from common.core.sysconfig import Config
from common.libs.storage.localApi import LocalStorage
from xsign.models import AppUDID, APPToDeveloper, APPSuperSignUsedInfo
from xsign.tasks import run_resign_task
from xsign.utils.modelutils import get_filename_form_file
from xsign.utils.supersignutils import IosUtils
logger = logging.getLogger(__name__)
@ -115,5 +116,16 @@ def xsign_clean_data_signal_callback(sender, **kwargs):
storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type)
"""
根据binary_file获取签名应用数据
"""
@receiver(xsign_app_release_obj_signal)
def xsign_app_release_obj_signal_callback(sender, **kwargs):
binary_file = kwargs.get('binary_file')
return get_filename_form_file(binary_file)
def main():
logger.info('signal receiver init success')

@ -51,6 +51,14 @@ def check_org_file(user_obj, org_file):
def resign_by_app_id_and_developer(app_id, developer_id, developer_app_id, need_download_profile=True, force=True):
"""
:param app_id:
:param developer_id:
:param developer_app_id:
:param need_download_profile:
:param force: 检测到已经是最新签名了是否还继续强制签名 True 表示 强制 False 表示不强制默认强制继续签名
:return:
"""
app_obj = Apps.objects.filter(pk=app_id).first()
developer_obj = AppIOSDeveloperInfo.objects.filter(pk=developer_id).first()
if check_ipa_is_latest_sign(app_obj, developer_obj) and not force:

@ -23,6 +23,7 @@ from common.utils.download import get_app_download_url
from xsign.models import AppIOSDeveloperInfo, APPSuperSignUsedInfo, AppUDID, IosDeveloperPublicPoolBill, \
UDIDsyncDeveloper, AppleDeveloperToAppUse, DeveloperAppID, APPToDeveloper, DeveloperDevicesID, \
IosDeveloperBill
from xsign.tasks import run_resign_task_do
from xsign.utils.modelutils import get_user_public_used_sign_num, get_user_public_sign_num, check_uid_has_relevant, \
get_developer_devices
from xsign.utils.serializer import DeveloperSerializer, SuperSignUsedSerializer, DeviceUDIDSerializer, \
@ -339,6 +340,22 @@ class SuperSignUsedView(APIView):
app_to_dev_obj = APPToDeveloper.objects.filter(app_id=app_obj, developerid__issuer_id=developer_id).first()
if app_obj and app_to_dev_obj:
developer_app_id_obj = DeveloperAppID.objects.filter(app_id=app_obj,
developerid__issuer_id=developer_id).first()
appudid_obj = AppUDID.objects.filter(app_id=app_obj, udid__udid=device_udid,
udid__developerid__issuer_id=developer_id).last()
need_download_profile = True
if appudid_obj.sign_status in [3, 4]:
need_download_profile = False
c_task = run_resign_task_do.apply_async((app_obj.pk, app_to_dev_obj.developerid.pk,
developer_app_id_obj.aid, need_download_profile, False))
msg = c_task.get(propagate=False)
logger.info(f"app {app_obj} run_resign_task msg:{msg}")
if c_task.successful():
c_task.forget()
app_to_dev_obj = APPToDeveloper.objects.filter(app_id=app_obj,
developerid__issuer_id=developer_id).first()
res = get_app_download_url(request, res, app_obj.app_id, app_obj.short, app_obj.password,
app_to_dev_obj.binary_file, True, device_udid)

Loading…
Cancel
Save