|
@@ -1,8 +1,12 @@
|
|
|
#!/usr/bin/env python
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+import logging
|
|
|
import os
|
|
|
import traceback
|
|
|
|
|
|
+import boto3
|
|
|
+import botocore
|
|
|
+from botocore import client
|
|
|
import simplejson as json
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
from django.http import HttpResponse
|
|
@@ -10,7 +14,7 @@ from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView, View
|
|
|
|
|
|
-from Ansjer.config import BASE_DIR
|
|
|
+from Ansjer.config import BASE_DIR, SERVER_TYPE, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, AVATAR_BUCKET
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
from Model.models import Role, Device_User, UserOauth2Model, UserExModel
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -192,6 +196,22 @@ class getAvatarView(TemplateView):
|
|
|
response = ResponseObject()
|
|
|
if filePath == '' or filePath == None:
|
|
|
return response.json(800)
|
|
|
+ if filePath == 'User/default.png':
|
|
|
+ try:
|
|
|
+ aws_s3_client = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=ACCESS_KEY_ID,
|
|
|
+ aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name=REGION_NAME,
|
|
|
+ )
|
|
|
+ get_object_response = aws_s3_client.get_object(Bucket=AVATAR_BUCKET, Key='default/default.png')
|
|
|
+ print(get_object_response['Body'].read())
|
|
|
+ return HttpResponse(get_object_response['Body'].read(), content_type="image/jpeg")
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
fullPath = os.path.join(BASE_DIR, "static", filePath).replace('\\', '/')
|
|
|
defaultPath = os.path.join(BASE_DIR, "static", "User/default.png").replace('\\', '/')
|
|
|
if os.path.isfile(fullPath):
|
|
@@ -202,16 +222,12 @@ class getAvatarView(TemplateView):
|
|
|
else:
|
|
|
return HttpResponse(Imagedata, content_type="image/jpeg")
|
|
|
else:
|
|
|
- print('----------------')
|
|
|
- print(defaultPath)
|
|
|
- print('----------------')
|
|
|
try:
|
|
|
Imagedata = open(defaultPath, 'rb').read()
|
|
|
except Exception as e:
|
|
|
return response.json(906, repr(e))
|
|
|
else:
|
|
|
return HttpResponse(Imagedata, content_type="image/jpeg")
|
|
|
- # return response.json(907)
|
|
|
|
|
|
|
|
|
@csrf_exempt
|