|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
# project: 4月
|
|
|
|
# author: NinEveN
|
|
|
|
# date: 2021/4/13
|
|
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
from api.utils.response import BaseResponse
|
|
|
|
from api.utils.auth import ExpiringTokenAuthentication
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from django.db.models import Sum
|
|
|
|
from api.utils.app.supersignutils import IosUtils, resign_by_app_obj
|
|
|
|
from api.utils.storage.storage import Storage
|
|
|
|
from api.utils.storage.caches import del_cache_response_by_short, get_app_today_download_times, del_cache_by_delete_app
|
|
|
|
from api.models import Apps, AppReleaseInfo, APPToDeveloper, AppIOSDeveloperInfo, UserInfo, AppScreenShot
|
|
|
|
from api.utils.serializer import AppsSerializer, AppReleaseSerializer
|
|
|
|
from rest_framework.pagination import PageNumberPagination
|
|
|
|
import logging
|
|
|
|
from fir_ser.settings import SERVER_DOMAIN
|
|
|
|
from api.utils.utils import delete_local_files, delete_app_screenshots_files
|
|
|
|
from api.utils.baseutils import is_valid_domain
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def app_delete(app_obj):
|
|
|
|
res = BaseResponse()
|
|
|
|
if not app_obj:
|
|
|
|
res.code = 1001
|
|
|
|
res.msg = "应用不存在"
|
|
|
|
return res
|
|
|
|
user_obj = app_obj.user_id
|
|
|
|
count = APPToDeveloper.objects.filter(app_id=app_obj).count()
|
|
|
|
if app_obj.issupersign or count > 0:
|
|
|
|
logger.info("app_id:%s is supersign ,delete this app need clean IOS developer" % (app_obj.app_id))
|
|
|
|
IosUtils.clean_app_by_user_obj(app_obj, user_obj)
|
|
|
|
|
|
|
|
storage = Storage(user_obj)
|
|
|
|
has_combo = app_obj.has_combo
|
|
|
|
if has_combo:
|
|
|
|
logger.info(
|
|
|
|
"app_id:%s has_combo ,delete this app need uncombo and clean del_cache_response_by_short" % (
|
|
|
|
app_obj.app_id))
|
|
|
|
has_combo.has_combo = None
|
|
|
|
del_cache_response_by_short(app_obj.app_id)
|
|
|
|
del_cache_by_delete_app(app_obj.app_id)
|
|
|
|
for app_release_obj in AppReleaseInfo.objects.filter(app_id=app_obj).all():
|
|
|
|
logger.info("delete app_id:%s need clean all release,release_id:%s" % (
|
|
|
|
app_obj.app_id, app_release_obj.release_id))
|
|
|
|
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)
|
|
|
|
storage.delete_file(app_release_obj.icon_url)
|
|
|
|
app_release_obj.delete()
|
|
|
|
delete_app_screenshots_files(storage, app_obj)
|
|
|
|
app_obj.delete()
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def app_screen_delete(screen_id, apps_obj, storage):
|
|
|
|
screen_obj = AppScreenShot.objects.filter(pk=screen_id, app_id=apps_obj).first()
|
|
|
|
if screen_obj:
|
|
|
|
storage.delete_file(screen_obj.screenshot_url)
|
|
|
|
screen_obj.delete()
|
|
|
|
del_cache_response_by_short(apps_obj.app_id)
|
|
|
|
|
|
|
|
|
|
|
|
def app_release_delete(app_obj, release_id, storage):
|
|
|
|
res = BaseResponse()
|
|
|
|
user_obj = app_obj.user_id
|
|
|
|
if app_obj:
|
|
|
|
apprelease_count = AppReleaseInfo.objects.filter(app_id=app_obj).values("release_id").count()
|
|
|
|
appreleaseobj = AppReleaseInfo.objects.filter(app_id=app_obj, release_id=release_id).first()
|
|
|
|
if not appreleaseobj.is_master:
|
|
|
|
logger.info("delete app release %s" % (appreleaseobj))
|
|
|
|
storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type)
|
|
|
|
delete_local_files(appreleaseobj.release_id, appreleaseobj.release_type)
|
|
|
|
storage.delete_file(appreleaseobj.icon_url)
|
|
|
|
|
|
|
|
appreleaseobj.delete()
|
|
|
|
elif appreleaseobj.is_master and apprelease_count < 2:
|
|
|
|
logger.info("delete app master release %s and clean app %s " % (appreleaseobj, app_obj))
|
|
|
|
count = APPToDeveloper.objects.filter(app_id=app_obj).count()
|
|
|
|
if app_obj.issupersign or count > 0:
|
|
|
|
logger.info("app_id:%s is supersign ,delete this app need clean IOS developer" % (app_obj.app_id))
|
|
|
|
IosUtils.clean_app_by_user_obj(app_obj, user_obj)
|
|
|
|
|
|
|
|
storage.delete_file(appreleaseobj.release_id, appreleaseobj.release_type)
|
|
|
|
delete_local_files(appreleaseobj.release_id, appreleaseobj.release_type)
|
|
|
|
storage.delete_file(appreleaseobj.icon_url)
|
|
|
|
del_cache_by_delete_app(app_obj.app_id)
|
|
|
|
|
|
|
|
appreleaseobj.delete()
|
|
|
|
delete_app_screenshots_files(storage, app_obj)
|
|
|
|
has_combo = app_obj.has_combo
|
|
|
|
if has_combo:
|
|
|
|
app_obj.has_combo.has_combo = None
|
|
|
|
app_obj.delete()
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
del_cache_response_by_short(app_obj.app_id)
|
|
|
|
|
|
|
|
return res
|