From 9b7590146a69c8eac49a6cb743c2bdc0b9e49ffe Mon Sep 17 00:00:00 2001 From: youngS Date: Wed, 20 Oct 2021 14:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E9=A1=B5?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_client/src/components/FirDownload.vue | 18 ++---------------- fir_client/src/components/ShortDownload.vue | 18 ++---------------- fir_ser/api/utils/baseutils.py | 10 ++++++++++ fir_ser/api/views/download.py | 10 ++++++++-- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/fir_client/src/components/FirDownload.vue b/fir_client/src/components/FirDownload.vue index f657f63..6078fe8 100644 --- a/fir_client/src/components/FirDownload.vue +++ b/fir_client/src/components/FirDownload.vue @@ -487,19 +487,6 @@ }) } }, - auto_redirect_url(domain_name) { - if (domain_name) { - let nurl = location.href.split("//")[1].split("/"); - const user_hostname = domain_name.split("//"); - if (nurl[0] === user_hostname[1]) { - return true; - } else { - nurl[0] = user_hostname[1]; - window.location.href = user_hostname[0] + "//" + nurl.join("/"); - return false; - } - } - }, getDownloadTokenFun() { let params = { "short": this.$route.params.short, @@ -515,9 +502,6 @@ } getShortAppinfo(data => { if (data.code === 1000) { - if (!this.auto_redirect_url(data.domain_name)) { - return; - } if (data.ad && data.ad.ad_uri) { this.ad_info = data.ad; } @@ -628,6 +612,8 @@ } } else if (data.code === 1002) { window.location.href = location.href.replace(location.search, ''); + }else if (data.code === 302 && data.data) { + window.location.href = data.data; } else { if (data.msg) { document.title = data.msg; diff --git a/fir_client/src/components/ShortDownload.vue b/fir_client/src/components/ShortDownload.vue index 4741e99..beb43b2 100644 --- a/fir_client/src/components/ShortDownload.vue +++ b/fir_client/src/components/ShortDownload.vue @@ -476,19 +476,6 @@ }) } }, - auto_redirect_url(domain_name) { - if (domain_name) { - let nurl = location.href.split("//")[1].split("/"); - const user_hostname = domain_name.split("//"); - if (nurl[0] === user_hostname[1]) { - return true; - } else { - nurl[0] = user_hostname[1]; - window.location.href = user_hostname[0] + "//" + nurl.join("/"); - return false; - } - } - }, getDownloadTokenFun() { let params = { "short": this.$route.params.short, @@ -504,9 +491,6 @@ } getShortAppinfo(data => { if (data.code === 1000) { - if (!this.auto_redirect_url(data.domain_name)) { - return; - } if (data.ad && data.ad.ad_uri) { this.ad_info = data.ad; } @@ -613,6 +597,8 @@ } } else if (data.code === 1002) { window.location.href = location.href.replace(location.search, ''); + }else if (data.code === 302 && data.data) { + window.location.href = data.data; } else { this.iserror = true; this.wrong = true; diff --git a/fir_ser/api/utils/baseutils.py b/fir_ser/api/utils/baseutils.py index 35231fb..b1957ab 100644 --- a/fir_ser/api/utils/baseutils.py +++ b/fir_ser/api/utils/baseutils.py @@ -276,3 +276,13 @@ def ad_random_weight(user_obj): ret = ad_info break return ret + + +def format_get_uri(domain, short, data): + uri = '' + for k, v in data.items(): + if v: + uri += f'&{k}={v}' + if uri: + uri = '?' + uri[1:] + return f'{domain}/{short}{uri}' diff --git a/fir_ser/api/views/download.py b/fir_ser/api/views/download.py index 175965c..4fca11a 100644 --- a/fir_ser/api/views/download.py +++ b/fir_ser/api/views/download.py @@ -23,7 +23,7 @@ from api.models import Apps, AppReleaseInfo, APPToDeveloper, APPSuperSignUsedInf from django.http import FileResponse import logging from api.utils.baseutils import get_profile_full_path, get_app_domain_name, get_filename_form_file, \ - check_app_domain_name_access, get_real_ip_address, get_origin_domain_name, ad_random_weight + check_app_domain_name_access, get_real_ip_address, get_origin_domain_name, ad_random_weight, format_get_uri from api.utils.throttle import VisitShortThrottle, InstallShortThrottle, InstallThrottle1, InstallThrottle2 logger = logging.getLogger(__name__) @@ -153,10 +153,16 @@ class ShortDownloadView(APIView): if res.code != 1000: return Response(res.dict) domain_name = get_redirect_server_domain(request, user_obj, get_app_domain_name(app_obj)) + origin_domain_name = get_origin_domain_name(request) + if domain_name.split('//')[-1].split('/')[0] != origin_domain_name: + res.code = 302 + res.data = format_get_uri(domain_name, short, {'release_id': release_id, 'udid': udid}) + return Response(res.dict) + if user_obj and user_obj.role and user_obj.role == 3: ... else: - if not check_app_domain_name_access(app_obj, get_origin_domain_name(request), user_obj, + if not check_app_domain_name_access(app_obj, origin_domain_name, user_obj, domain_name.split('//')[-1]): res.code = 1004 res.msg = "访问域名不合法"