super_signature
nineven 5 years ago
parent ff81f62d95
commit 7821d10929
  1. 4
      fir_client/src/restful/index.js
  2. 14
      fir_ser/api/utils/TokenManager.py
  3. 4
      fir_ser/api/utils/middlewares.py
  4. 2
      fir_ser/api/utils/serializer.py
  5. 2
      fir_ser/api/utils/storage/aliyunApi.py
  6. 4
      fir_ser/api/utils/storage/caches.py
  7. 7
      fir_ser/api/utils/storage/localApi.py
  8. 2
      fir_ser/api/utils/storage/qiniuApi.py
  9. 6
      fir_ser/api/utils/storage/storage.py
  10. 29
      fir_ser/api/views/download.py
  11. 9
      fir_ser/api/views/receiveudids.py
  12. 2
      fir_ser/fir_ser/settings.py

@ -88,14 +88,14 @@ function ErrorMsg(error) {
} }
if (error.response && error.response.status === 403) { if (error.response && error.response.status === 403) {
router.push({name: 'FirLogin'}); router.push({name: 'FirLogin'});
} }else{
if (error.message === 'Network Error') { if (error.message === 'Network Error') {
alert('网络连接失败'); alert('网络连接失败');
} else { } else {
alert(error) alert(error)
} }
} }
}
function getData(methods = true, url, params = {}, callBack, load, isCode = false) { function getData(methods = true, url, params = {}, callBack, load, isCode = false) {

@ -21,20 +21,20 @@ class DownloadToken(object):
def make_token(self, release_id, time_limit=60, key='', force_new=False): def make_token(self, release_id, time_limit=60, key='', force_new=False):
token_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get("make_token_key"), release_id]) token_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get("make_token_key"), release_id])
make_token_key = cache.get(token_key) token = cache.get(token_key)
if make_token_key and not force_new: if token and not force_new:
return make_token_key return token
else: else:
random_str = uuid.uuid1().__str__().split("-")[0:-1] random_str = uuid.uuid1().__str__().split("-")[0:-1]
user_ran_str = uuid.uuid5(uuid.NAMESPACE_DNS, release_id).__str__().split("-") user_ran_str = uuid.uuid5(uuid.NAMESPACE_DNS, release_id).__str__().split("-")
user_ran_str.extend(random_str) user_ran_str.extend(random_str)
new_str = "".join(user_ran_str) token = "".join(user_ran_str)
cache.set(new_str, { cache.set(token, {
"atime": time.time() + time_limit, "atime": time.time() + time_limit,
"data": release_id "data": release_id
}, time_limit) }, time_limit)
cache.set(token_key, new_str, time_limit - 1) cache.set(token_key, token, time_limit - 1)
return new_str return token
def verify_token(self, token, release_id): def verify_token(self, token, release_id):
try: try:

@ -8,9 +8,11 @@ class CorsMiddleWare(MiddlewareMixin):
response["Access-Control-Allow-Methods"] = "GET,POST,DELETE,PUT" response["Access-Control-Allow-Methods"] = "GET,POST,DELETE,PUT"
response["Access-Control-Allow-Headers"] = "Content-Type,AUTHORIZATION" response["Access-Control-Allow-Headers"] = "Content-Type,AUTHORIZATION"
try:
response["Access-Control-Allow-Origin"] = request.META.get("HTTP_ORIGIN") response["Access-Control-Allow-Origin"] = request.META.get("HTTP_ORIGIN")
response["Access-Control-Allow-Credentials"] = 'true' response["Access-Control-Allow-Credentials"] = 'true'
response["Cache-Control"] = "no-cache" response["Cache-Control"] = "no-cache"
except Exception as e:
print(e)
return response return response

@ -170,7 +170,7 @@ class AppReleaseSerializer(serializers.ModelSerializer):
def get_download_token(self, obj): def get_download_token(self, obj):
download_token = token_obj.make_token(obj.release_id, 300) download_token = token_obj.make_token(obj.release_id, 600)
return download_token return download_token

@ -110,7 +110,7 @@ class AliYunOss(object):
auth = oss2.StsAuth(self.token.access_key_id, self.token.access_key_secret, self.token.security_token) auth = oss2.StsAuth(self.token.access_key_id, self.token.access_key_secret, self.token.security_token)
self.bucket = oss2.Bucket(auth, uri + url, self.bucket_name, is_cname=is_cname) self.bucket = oss2.Bucket(auth, uri + url, self.bucket_name, is_cname=is_cname)
def get_download_url(self, name, expires=1800, ftype=None, force_new=False): def get_download_url(self, name, expires=1800, force_new=False):
# self.get_auth_bucket(name,expires) # self.get_auth_bucket(name,expires)
private_url = self.bucket.sign_url('GET', name, expires) private_url = self.bucket.sign_url('GET', name, expires)
return private_url return private_url

@ -37,7 +37,7 @@ def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='',
developerid=SuperSign_obj.developerid).first() developerid=SuperSign_obj.developerid).first()
if APPToDeveloper_obj: if APPToDeveloper_obj:
return local_storage.get_download_url( return local_storage.get_download_url(
APPToDeveloper_obj.binary_file + "." + filename.split(".")[-1], limit, download_url_type) APPToDeveloper_obj.binary_file + "." + download_url_type, limit)
else: else:
return "" return ""
else: else:
@ -45,7 +45,7 @@ def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='',
else: else:
return "" return ""
return local_storage.get_download_url(filename, limit, download_url_type) return local_storage.get_download_url(filename.split(".")[0]+ "." + download_url_type, limit)
down_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get('download_url_key'), filename]) down_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get('download_url_key'), filename])
download_val = cache.get(down_key) download_val = cache.get(down_key)
if download_val: if download_val:

@ -20,15 +20,14 @@ class LocalStorage(object):
dtoken = DownloadToken() dtoken = DownloadToken()
return dtoken.make_token(name, expires) return dtoken.make_token(name, expires)
def get_download_url(self, name, expires=1800, ftype=None, force_new=False): def get_download_url(self, name, expires=600, force_new=False):
dtoken = DownloadToken() dtoken = DownloadToken()
base_url = '/'.join([self.domain_name, 'download', name]) base_url = '/'.join([self.domain_name, 'download', name])
uri = 'http://' uri = 'http://'
if self.is_https: if self.is_https:
uri = 'https://' uri = 'https://'
download_url = uri + base_url + "?token=" + dtoken.make_token(name, expires, force_new=force_new) download_url = "%s%s?%s=%s" % (
if ftype: uri, base_url, settings.DATA_DOWNLOAD_KEY, dtoken.make_token(name, expires, force_new=force_new))
download_url = download_url + '&ftype=' + ftype
return download_url return download_url
def del_file(self, name): def del_file(self, name):

@ -33,7 +33,7 @@ class QiNiuOss(object):
# print(token) # print(token)
return token return token
def get_download_url(self, name, expires=1800, ftype=None, force_new=False): def get_download_url(self, name, expires=1800, force_new=False):
# 有两种方式构造base_url的形式 # 有两种方式构造base_url的形式
uri = 'http://' uri = 'http://'
if self.is_https: if self.is_https:

@ -4,7 +4,7 @@
# author: liuyu # author: liuyu
# date: 2020/3/23 # date: 2020/3/23
from api.models import AppStorage, UserInfo from api.models import UserInfo
from .aliyunApi import AliYunOss from .aliyunApi import AliYunOss
from .qiniuApi import QiNiuOss from .qiniuApi import QiNiuOss
from .localApi import LocalStorage from .localApi import LocalStorage
@ -24,7 +24,7 @@ class Storage(object):
if self.storage: if self.storage:
return self.storage.get_upload_token(filename, expires) return self.storage.get_upload_token(filename, expires)
def get_download_url(self, filename, expires=900, ftype=None, key='', force_new=False): def get_download_url(self, filename, expires=900, key='', force_new=False):
if self.storage: if self.storage:
now = time.time() now = time.time()
down_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get('download_url_key'), filename]) down_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get('download_url_key'), filename])
@ -33,7 +33,7 @@ class Storage(object):
if download_val.get("time") > now - 60: if download_val.get("time") > now - 60:
return download_val.get("download_url") return download_val.get("download_url")
download_url = self.storage.get_download_url(filename, expires, ftype, force_new=False) download_url = self.storage.get_download_url(filename, expires,force_new=True)
cache.set(down_key, {"download_url": download_url, "time": now + expires}, expires) cache.set(down_key, {"download_url": download_url, "time": now + expires}, expires)
return download_url return download_url

@ -31,8 +31,8 @@ class DownloadView(APIView):
def get(self, request, filename): def get(self, request, filename):
res = BaseResponse() res = BaseResponse()
downtoken = request.query_params.get("token", None) downtoken = request.query_params.get(settings.DATA_DOWNLOAD_KEY, None)
ftype = request.query_params.get("ftype", None) ftype = filename.split(".")[-1]
if not downtoken: if not downtoken:
res.code = 1004 res.code = 1004
res.msg = "缺失token" res.msg = "缺失token"
@ -40,17 +40,6 @@ class DownloadView(APIView):
dtoken = DownloadToken() dtoken = DownloadToken()
if dtoken.verify_token(downtoken, filename): if dtoken.verify_token(downtoken, filename):
if not ftype:
file_path = os.path.join(settings.MEDIA_ROOT, filename)
try:
response = FileResponse(open(file_path, 'rb'))
except Exception as e:
print(e)
response = FileResponse()
response['content_type'] = "application/octet-stream"
response['Content-Disposition'] = 'attachment; filename=' + filename
return response
else:
if ftype == 'plist': if ftype == 'plist':
release_id = filename.split('.')[0] release_id = filename.split('.')[0]
apptodev_obj = APPToDeveloper.objects.filter(binary_file=release_id).first() apptodev_obj = APPToDeveloper.objects.filter(binary_file=release_id).first()
@ -63,7 +52,7 @@ class DownloadView(APIView):
bundle_id = release_obj.app_id.bundle_id bundle_id = release_obj.app_id.bundle_id
app_version = release_obj.app_version app_version = release_obj.app_version
name = release_obj.app_id.name name = release_obj.app_id.name
ios_plist_bytes = make_resigned(storage.get_download_url(filename), ios_plist_bytes = make_resigned(storage.get_download_url(filename.split('.')[0]+".ipa"),
storage.get_download_url(release_obj.icon_url), bundle_id, storage.get_download_url(release_obj.icon_url), bundle_id,
app_version, name) app_version, name)
response = FileResponse(ios_plist_bytes) response = FileResponse(ios_plist_bytes)
@ -82,6 +71,16 @@ class DownloadView(APIView):
response['Content-Disposition'] = 'attachment; filename=' + make_random_uuid() + '.mobileconfig' response['Content-Disposition'] = 'attachment; filename=' + make_random_uuid() + '.mobileconfig'
return response return response
res.msg = "mobileconifg release_id error" res.msg = "mobileconifg release_id error"
else:
file_path = os.path.join(settings.MEDIA_ROOT, filename)
try:
response = FileResponse(open(file_path, 'rb'))
except Exception as e:
print(e)
response = FileResponse()
response['content_type'] = "application/octet-stream"
response['Content-Disposition'] = 'attachment; filename=' + filename
return response
res.code = 1004 res.code = 1004
res.msg = "token校验失败" res.msg = "token校验失败"
@ -166,7 +165,7 @@ class InstallView(APIView):
udid=udid) udid=udid)
res.data = {"download_url": download_url} res.data = {"download_url": download_url}
if download_url != "" and not download_url.endswith("mobileconifg"): if download_url != "" and "mobileconifg" not in download_url:
set_app_download_by_cache(app_id) set_app_download_by_cache(app_id)
return Response(res.dict) return Response(res.dict)
else: else:

@ -15,6 +15,7 @@ class IosUDIDView(View):
def post(self, request, short): def post(self, request, short):
stream_f = str(request.body) stream_f = str(request.body)
format_udid_info = udid_bytes_to_dict(stream_f) format_udid_info = udid_bytes_to_dict(stream_f)
server_domain = get_redirect_server_domain(request)
try: try:
app_info = Apps.objects.filter(short=short).first() app_info = Apps.objects.filter(short=short).first()
@ -25,11 +26,11 @@ class IosUDIDView(View):
ios_obj = IosUtils(format_udid_info, app_info.user_id, app_info) ios_obj = IosUtils(format_udid_info, app_info.user_id, app_info)
ios_obj.resign() ios_obj.resign()
else: else:
return Http404 return HttpResponsePermanentRedirect(
"%s/%s" % (server_domain, short))
else: else:
return Http404 return HttpResponsePermanentRedirect(
"%s/%s" % (server_domain, short))
except Exception as e: except Exception as e:
print(e) print(e)
server_domain = get_redirect_server_domain(request)
return HttpResponsePermanentRedirect("%s/%s?udid=%s" % (server_domain, short, format_udid_info.get("udid"))) return HttpResponsePermanentRedirect("%s/%s?udid=%s" % (server_domain, short, format_udid_info.get("udid")))

@ -236,6 +236,8 @@ CACHE_KEY_TEMPLATE = {
'developer_auth_code_key': 'developer_auth_code', 'developer_auth_code_key': 'developer_auth_code',
} }
DATA_DOWNLOAD_KEY="d_token"
SYNC_CACHE_TO_DATABASE = { SYNC_CACHE_TO_DATABASE = {
'download_times': 10 # 下载次数同步时间 'download_times': 10 # 下载次数同步时间
} }

Loading…
Cancel
Save