After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 280 KiB |
After Width: | Height: | Size: 213 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 168 KiB |
After Width: | Height: | Size: 80 KiB |
@ -0,0 +1,49 @@ |
|||||||
|
#!/usr/bin/env python |
||||||
|
# -*- coding:utf-8 -*- |
||||||
|
# project: 3月 |
||||||
|
# author: liuyu |
||||||
|
# date: 2020/3/18 |
||||||
|
|
||||||
|
from qiniu import Auth |
||||||
|
from qiniu import BucketManager |
||||||
|
|
||||||
|
class QiNiu(object): |
||||||
|
def __init__(self): |
||||||
|
access_key="mTqfvkLVSTVb2_1ERjDlFS_WAHLSkpDxYr4e4fiJ" |
||||||
|
secret_key="0G9fXfgmi8h1-bmEsABYkE6apf8IuwKpj3hYLynv" |
||||||
|
self.bucket_name = 'fir-storage' |
||||||
|
self.download_domain = 'fly-cdn.dvcloud.xin' |
||||||
|
self.qiniu_obj = Auth(access_key,secret_key) |
||||||
|
|
||||||
|
def get_qiniu_upload_token(self,name): |
||||||
|
# 生成上传 Token,可以指定过期时间等 |
||||||
|
# 上传策略示例 |
||||||
|
# https://developer.qiniu.com/kodo/manual/1206/put-policy |
||||||
|
policy = { |
||||||
|
# 'callbackUrl':'https://requestb.in/1c7q2d31', |
||||||
|
# 'callbackBody':'filename=$(fname)&filesize=$(fsize)' |
||||||
|
# 'persistentOps':'imageView2/1/w/200/h/200' |
||||||
|
} |
||||||
|
# 3600为token过期时间,秒为单位。3600等于一小时 |
||||||
|
token = self.qiniu_obj.upload_token(self.bucket_name, name, 3600, policy) |
||||||
|
# print(token) |
||||||
|
return token |
||||||
|
|
||||||
|
def get_qiniu_download_token(self,name): |
||||||
|
#有两种方式构造base_url的形式 |
||||||
|
base_url = 'http://%s/%s' % (self.download_domain, name) |
||||||
|
#或者直接输入url的方式下载 |
||||||
|
#可以设置token过期时间 |
||||||
|
private_url = self.qiniu_obj.private_download_url(base_url, expires=3600) |
||||||
|
print(private_url) |
||||||
|
return private_url |
||||||
|
|
||||||
|
def del_qiniu_file(self,name): |
||||||
|
# 初始化BucketManager |
||||||
|
bucket = BucketManager(self.qiniu_obj) |
||||||
|
# 你要测试的空间, 并且这个key在你空间中存在 |
||||||
|
# 删除bucket_name 中的文件 key |
||||||
|
ret, info = bucket.delete(self.bucket_name, name) |
||||||
|
print(info) |
||||||
|
return ret |
||||||
|
|
@ -0,0 +1,78 @@ |
|||||||
|
#!/usr/bin/env python |
||||||
|
# -*- coding:utf-8 -*- |
||||||
|
# project: 3月 |
||||||
|
# author: liuyu |
||||||
|
# date: 2020/3/6 |
||||||
|
from rest_framework.views import APIView |
||||||
|
from api.utils.response import BaseResponse |
||||||
|
from api.utils.auth import ExpiringTokenAuthentication |
||||||
|
from api.utils.randomstrings import make_from_user_uuid |
||||||
|
from rest_framework.response import Response |
||||||
|
from fir_ser import settings |
||||||
|
from api.utils.app.analyze import AnalyzeUtil, get_random_short,SaveAppInfos |
||||||
|
import os |
||||||
|
from api.utils.qiniu.tools import QiNiu |
||||||
|
from api.models import Apps |
||||||
|
from api.utils.randomstrings import make_app_uuid |
||||||
|
|
||||||
|
|
||||||
|
class QiNiuUploadView(APIView): |
||||||
|
|
||||||
|
authentication_classes = [ExpiringTokenAuthentication, ] |
||||||
|
def post(self, request): |
||||||
|
res = BaseResponse() |
||||||
|
# 1.接受 bundelid ,返回随机应用名称和短连接 |
||||||
|
bundleid = request.data.get("bundleid", None) |
||||||
|
app_type = request.data.get("type", None) |
||||||
|
|
||||||
|
if bundleid and app_type: |
||||||
|
ap = 'apk' |
||||||
|
if app_type == 'iOS': |
||||||
|
ap='ipa' |
||||||
|
app_uuid = make_app_uuid(request.user, bundleid + ap) |
||||||
|
release_id = make_from_user_uuid(request.user) |
||||||
|
png_id = make_from_user_uuid(request.user) |
||||||
|
app_obj = Apps.objects.filter(app_id=app_uuid).first() |
||||||
|
print(app_obj) |
||||||
|
if app_obj: |
||||||
|
short = app_obj.short |
||||||
|
else: |
||||||
|
short = get_random_short() |
||||||
|
if app_type == 'iOS': |
||||||
|
upload_key = release_id+'.ipa' |
||||||
|
else: |
||||||
|
upload_key = release_id+'.apk' |
||||||
|
png_key = png_id+'.png' |
||||||
|
qiniu = QiNiu() |
||||||
|
res.data = {"app_uuid": app_uuid, "short": short, |
||||||
|
"domain_name": request.user.domain_name, |
||||||
|
"upload_token":qiniu.get_qiniu_upload_token(upload_key), |
||||||
|
"upload_key":upload_key, |
||||||
|
"png_token":qiniu.get_qiniu_upload_token(png_key), |
||||||
|
"png_key":png_key} |
||||||
|
else: |
||||||
|
res.code = 1003 |
||||||
|
|
||||||
|
return Response(res.dict) |
||||||
|
|
||||||
|
def put(self,request): |
||||||
|
res = BaseResponse() |
||||||
|
print(request.data) |
||||||
|
data=request.data |
||||||
|
appinfo={ |
||||||
|
"labelname":data.get("appname"), |
||||||
|
"version":data.get("buildversion"), |
||||||
|
"versioncode":data.get("version"), |
||||||
|
"release_type":data.get("release_type"), |
||||||
|
"miniOSversion":data.get("miniosversion"), |
||||||
|
"changelog":data.get("changelog",'') |
||||||
|
} |
||||||
|
|
||||||
|
try: |
||||||
|
SaveAppInfos(data.get("upload_key"), request.user, appinfo, |
||||||
|
data.get("bundleid"), data.get("png_key"), data.get("short"), data.get('filesize')) |
||||||
|
except Exception as e: |
||||||
|
print(e) |
||||||
|
res.code = 10003 |
||||||
|
return Response(res.dict) |
||||||
|
|