|
@@ -10,22 +10,27 @@ from app.configs import config
|
|
|
class AgentApi(Resource):
|
|
|
|
|
|
def get(self, path):
|
|
|
- token = request.args.get('token', None)
|
|
|
- if token is None:
|
|
|
- abort(418)
|
|
|
+ args = request.args
|
|
|
+ try:
|
|
|
+ token = args.pop('token')
|
|
|
+
|
|
|
+ # token 在配置里则不验证,48小时删除配置里的token
|
|
|
+ validate_token_rep = requests.get('http://%s/oauth/api/user/validateToken' % config.OAUTH_HOST,
|
|
|
+ headers={'token': token}).json()
|
|
|
+ if validate_token_rep.get('code') != 200:
|
|
|
+ return validate_token_rep
|
|
|
+
|
|
|
+ # 请求nginx
|
|
|
+ nginx_rep = requests.get('http://%s/%s' % (config.NGINX_HOST, path), params=args if len(args) > 0 else None)
|
|
|
|
|
|
- # 验证token
|
|
|
- validate_token_rep = requests.get('http://%s/oauth/api/user/validateToken' % config.OAUTH_HOST,
|
|
|
- headers={'token': token}).json()
|
|
|
- if validate_token_rep.get('code') != 200:
|
|
|
- return validate_token_rep
|
|
|
- # 请求nginx
|
|
|
- nginx_rep = requests.get('http://%s/%s' % (config.NGINX_HOST, path))
|
|
|
- response = make_response(nginx_rep.content)
|
|
|
- filename = path.split('/')[-1]
|
|
|
- mime_type = mimetypes.guess_type(filename)[0]
|
|
|
- if mime_type is None:
|
|
|
- mime_type = 'application/octet-stream'
|
|
|
- response.headers['Content-Type'] = mime_type
|
|
|
- response.headers['Content-Disposition'] = 'attachment; filename={}'.format(filename.encode().decode('latin-1'))
|
|
|
- return response
|
|
|
+ response = make_response(nginx_rep.content)
|
|
|
+ filename = path.split('/')[-1]
|
|
|
+ mime_type = mimetypes.guess_type(filename)[0]
|
|
|
+ if mime_type is None:
|
|
|
+ mime_type = 'application/octet-stream'
|
|
|
+ response.headers['Content-Type'] = mime_type
|
|
|
+ response.headers['Content-Disposition'] = 'attachment; filename={}'.format(filename.encode().decode('latin-1'))
|
|
|
+ return response
|
|
|
+
|
|
|
+ except KeyError:
|
|
|
+ abort(418)
|