浏览代码

ip为港澳台返回美洲域名,去掉sts日志

locky 1 年之前
父节点
当前提交
c7232ef761
共有 2 个文件被更改,包括 35 次插入23 次删除
  1. 1 3
      Controller/CloudStorage.py
  2. 34 20
      Controller/DeviceConfirmRegion.py

+ 1 - 3
Controller/CloudStorage.py

@@ -417,7 +417,7 @@ class CloudStorageView(View):
         uid = uid_obj.UID
         channel = uid_obj.channel
         now_time = int(time.time())
-        LOGGER.info('请求获取sts:{}'.format(uid))
+
         try:
             uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time, channel=channel).values(
                 "bucket__mold",
@@ -458,7 +458,6 @@ class CloudStorageView(View):
                 end_time = int(sts_crd_qs[0]["addTime"]) + 5000
                 if end_time > now_time:
                     res = json.loads(sts_crd_qs[0]["data"])
-                    LOGGER.info('请求获取sts响应1:{}'.format(uid))
                     return JsonResponse(status=200, data=res)
 
             storage = '{uid}/vod{channel}/'.format(uid=uid, channel=channel)
@@ -517,7 +516,6 @@ class CloudStorageView(View):
             else:
                 StsCrdModel.objects.create(uid=uid, channel=channel, data=json.dumps(res, default=str),
                                            addTime=now_time, type=1)
-            LOGGER.info('请求获取sts响应2:{}'.format(uid))
             return JsonResponse(status=200, data=res)
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))

+ 34 - 20
Controller/DeviceConfirmRegion.py

@@ -26,22 +26,30 @@ class ConfirmRegion(View):
             device_domain_qs = DeviceDomainModel.objects.filter(ip=ip)
 
             # 获取国家编码
-            ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code')
+            ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code', 'region')
             if ip_addr_qs.exists():
                 country_code = ip_addr_qs[0]['country_code']
+                region = ip_addr_qs[0]['region']
             else:
                 ip_qs = IPQuery(ip)
                 country_code = ip_qs.country_id
+                region = ip_qs.region
 
             if country_code:
-                country_qs = CountryModel.objects.filter(country_code=country_code).\
-                    values('region__api', 'region__push_api')
-                if country_qs.exists():
-                    api = country_qs[0]['region__api']
-                    push_api = country_qs[0]['region__push_api']
-
-                    if not device_domain_qs.exists():
-                        DeviceDomainModel.objects.create(ip=ip, country_name=country_code, api=api)
+                # 港澳台返回美洲域名
+                if country_code == 'CN' and region in ['香港', '澳门', '台湾']:
+                    api, push_api, region_id, push_region = get_default_api()
+                else:
+                    country_qs = CountryModel.objects.filter(country_code=country_code).\
+                        values('region__api', 'region__push_api')
+                    if country_qs.exists():
+                        api = country_qs[0]['region__api']
+                        push_api = country_qs[0]['region__push_api']
+
+                        if not device_domain_qs.exists():
+                            DeviceDomainModel.objects.create(ip=ip, country_name=country_code, api=api)
+                    else:
+                        api, push_api, region_id, push_region = get_default_api()
 
                     push_region = get_push_region(api)
                     res = {
@@ -90,26 +98,32 @@ class ConfirmRegionV2(View):
             data_dict['ip'] = ip
 
             # 获取国家编码
-            ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code')
+            ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code', 'region')
             if ip_addr_qs.exists():
                 country_code = ip_addr_qs[0]['country_code']
+                region = ip_addr_qs[0]['region']
             else:
                 ip_qs = IPQuery(ip)
                 country_code = ip_qs.country_id
+                region = ip_qs.region
 
             if country_code:
                 data_dict['country_code'] = country_code
-                country_qs = CountryModel.objects.filter(country_code=country_code).\
-                    values('region__api', 'region__push_api', 'region__id')
-                if country_qs.exists():
-                    api = country_qs[0]['region__api']
-                    push_api = country_qs[0]['region__push_api']
-                    region_id = country_qs[0]['region__id']
-                    push_region = get_push_region(api)
-                else:
-                    # 返回美洲域名
-                    data_dict['country_code'] = 'NA'
+                # 港澳台返回美洲域名
+                if country_code == 'CN' and region in ['香港', '澳门', '台湾']:
                     api, push_api, region_id, push_region = get_default_api()
+                else:
+                    country_qs = CountryModel.objects.filter(country_code=country_code).\
+                        values('region__api', 'region__push_api', 'region__id')
+                    if country_qs.exists():
+                        api = country_qs[0]['region__api']
+                        push_api = country_qs[0]['region__push_api']
+                        region_id = country_qs[0]['region__id']
+                        push_region = get_push_region(api)
+                    else:
+                        # 返回美洲域名
+                        data_dict['country_code'] = 'NA'
+                        api, push_api, region_id, push_region = get_default_api()
             else:
                 # 返回美洲域名
                 data_dict['country_code'] = 'NA'