Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmv authored and yangmv committed Jan 15, 2019
1 parent 7c80648 commit 51af821
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
Binary file modified apps/assets/cores/__pycache__/server.cpython-36.pyc
Binary file not shown.
Binary file modified apps/assets/views/__pycache__/server.cpython-36.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions apps/assets/views/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def get(self, request ,format=None):
# 从OSS获取
oss_obj = initOSS_obj()
if oss_obj:
data = oss_obj.getObj(log.record_name)
record_date = log.start_time.strftime('%Y%m%d')
data = oss_obj.getObj(log.record_name,record_date)
ret['data'] = data
else:
# 从Mysql获取
Expand Down Expand Up @@ -260,12 +261,12 @@ def get(self, request ,format=None):
ret = dict(status=False,msg=None,data=None)
if sid:
# username = request.query_params.get('username')
# username = 'yangmingwei' if username == 'yangmv' else username
# 改用后端验证登录用户信息
auth_key = request.COOKIES.get('auth_key', None)
if not auth_key:return Response('未登陆',status=401)
user_info = jwt.decode(auth_key, verify=False)
username = user_info['data']['username'] if 'data' in user_info else 'guest'
username = 'yangmingwei' if username == 'yangmv' else username
rule_obj = models.ServerAuthRule.objects.filter(user__contains=username)
for rule in rule_obj:
server_obj = rule.server.filter(id=sid)
Expand Down
7 changes: 7 additions & 0 deletions deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ spec:
# postStart:
# exec:
# command: ['/bin/sh', '-c', 'sed -i "s/s_hostname/$(hostname)/" /data1/www/templates/app.html']
resources:
limits:
cpu: 0.5
memory: 512Mi
requests:
cpu: 0.3
memory: 256Mi
ports:
- name: http
containerPort: 80
Expand Down
Binary file modified libs/Aliyun/__pycache__/oss.cpython-36.pyc
Binary file not shown.
13 changes: 7 additions & 6 deletions libs/Aliyun/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import oss2
import datetime
import shortuuid
import json

class OSSApi():
def __init__(self,key,secret,region,bucket_name,base_dir):
Expand Down Expand Up @@ -42,20 +43,20 @@ def setObj(self,data):
except Exception as e:
print(e)

def getObj(self,filename):
def getObj(self,filename,record_date):
'''获取str对象'''
try:
object_stream = self.bucket.get_object('%s/%s/%s'%(self.base_dir,self.date,filename))
object_stream = self.bucket.get_object('%s/%s/%s'%(self.base_dir,record_date,filename))
#print('[Success] Get obj success!')
return object_stream.read().decode()
except oss2.exceptions.NoSuchKey as e:
print('[Error] 文件不存在!')
return json.dumps({'0.0029790401458740234':'[Error] OSS录像文件不存在!'})
except oss2.exceptions.ServerError as e:
print('[Error] 服务器拒绝, 请检查[KEY][SECRET][存储桶]是否正确!')
return json.dumps({'0.0029790401458740234':'[Error] 请检查[KEY][SECRET][存储桶]是否正确!'})
except oss2.exceptions.AccessDenied as e:
print('[Error] 操作拒绝,请检查key是否有权限上传!')
return json.dumps({'0.0029790401458740234':'[Error] 操作拒绝,请检查key是否有权限上传!'})
except Exception as e:
print(e)
return json.dumps({'0.0029790401458740234':'[Error]--->%s'%e})

if __name__ == '__main__':
oss_config = {
Expand Down

0 comments on commit 51af821

Please sign in to comment.