lines-num-new">
12
from rest_framework import viewsets
|
|
|
|
@@ -32,6 +30,7 @@ from utils.redis.rkeys import (GROUP_LAST_PHOTO_PK, GROUP_PHOTO_WATCHER_SET, GRO
|
|
32
|
30
|
from utils.redis.rorder import get_lensman_order_record
|
|
33
|
31
|
from utils.redis.rprice import get_lensman_price_fixed
|
|
34
|
32
|
from utils.sql.raw import PAI2_HOME_API
|
|
|
33
|
+from utils.storage_utils import file_save
|
|
35
|
34
|
from utils.thumbnail_utils import make_thumbnail
|
|
36
|
35
|
from utils.time_utils import origin_expired_stamps
|
|
37
|
36
|
from utils.url_utils import img_url, share_url
|
|
|
|
@@ -135,12 +134,7 @@ def group_update_api(request):
|
|
135
|
134
|
group.group_desc = group_desc
|
|
136
|
135
|
# 群组头像更新
|
|
137
|
136
|
if group_avatar:
|
|
138
|
|
- _, extension = os.path.splitext(group_avatar.name)
|
|
139
|
|
- group_avatar_path = 'group/{uuid}_{extension}'.format(uuid=shortuuid.uuid(), extension=extension)
|
|
140
|
|
- if default_storage.exists(group_avatar_path):
|
|
141
|
|
- default_storage.delete(group_avatar_path)
|
|
142
|
|
- default_storage.save(group_avatar_path, group_avatar)
|
|
143
|
|
- group.group_avatar = group_avatar_path
|
|
|
137
|
+ group.group_avatar = file_save(group_avatar, prefix='group', ext='jpeg')[0]
|
|
144
|
138
|
group.save()
|
|
145
|
139
|
|
|
146
|
140
|
# Redis 群组数据缓存更新
|
|
|
|
@@ -260,18 +254,10 @@ def flyimg_upload_api(request):
|
|
260
|
254
|
return response(GroupUserStatusCode.GROUP_USER_NOT_FOUND)
|
|
261
|
255
|
|
|
262
|
256
|
if photo:
|
|
263
|
|
- photo_path = 'fly/{uuid}{extension}'.format(uuid=shortuuid.uuid(), extension=os.path.splitext(photo.name)[1] or 'jpeg')
|
|
|
257
|
+ photo_path, ext = file_save(photo, prefix='fly', ext='jpeg')
|
|
264
|
258
|
photo_thumbnail_path = photo_path.replace('.', '_thumbnail.')
|
|
265
|
259
|
photo_thumbnail2_path = photo_path.replace('.', '_thumbnail2.')
|
|
266
|
260
|
|
|
267
|
|
- if default_storage.exists(photo_path):
|
|
268
|
|
- default_storage.delete(photo_path)
|
|
269
|
|
- default_storage.save(photo_path, photo)
|
|
270
|
|
-
|
|
271
|
|
- # if default_storage.exists(photo_thumbnail_path):
|
|
272
|
|
- # default_storage.delete(photo_thumbnail_path)
|
|
273
|
|
- # default_storage.save(photo_thumbnail_path, photo)
|
|
274
|
|
-
|
|
275
|
261
|
# 群组照片缩略图生成
|
|
276
|
262
|
# 双列: 540, 40-50K
|
|
277
|
263
|
photo_w, photo_h, photo_thumbnail_w, photo_thumbnail_h = make_thumbnail(
|
|
|
|
@@ -5,7 +5,6 @@ import os
|
|
5
|
5
|
import shortuuid
|
|
6
|
6
|
from curtail_uuid import CurtailUUID
|
|
7
|
7
|
from django.conf import settings
|
|
8
|
|
-from django.core.files.storage import default_storage
|
|
9
|
8
|
from django.db import transaction
|
|
10
|
9
|
from django.shortcuts import render
|
|
11
|
10
|
from django_q.tasks import async
|
|
|
|
@@ -24,6 +23,7 @@ from utils.redis.rgroup import get_group_info, set_group_info, set_group_users_i
|
|
24
|
23
|
from utils.redis.rkeys import (GROUP_LAST_PHOTO_PK, GROUP_USERS_DELETED_SET, GROUP_USERS_PASSED_SET,
|
|
25
|
24
|
GROUP_USERS_QUIT_SET, GROUP_USERS_REFUSED_SET, UUID_LIST)
|
|
26
|
25
|
from utils.redis.ruuid import generate_uuids, update_uuids
|
|
|
26
|
+from utils.storage_utils import file_save
|
|
27
|
27
|
from utils.thumbnail_utils import make_thumbnail
|
|
28
|
28
|
from utils.watermark_utils import watermark_wrap
|
|
29
|
29
|
|
|
|
|
@@ -93,18 +93,9 @@ def upload_photo(request):
|
|
93
|
93
|
except LensmanInfo.DoesNotExist:
|
|
94
|
94
|
return response(LensmanStatusCode.LENSMAN_NOT_FOUND)
|
|
95
|
95
|
|
|
96
|
|
- # photo_id = curtailUUID(PhotosInfo, 'photo_id')
|
|
|
96
|
+ m_photo_path, ext = file_save(photo, prefix='photo', ext='jpeg')
|
|
97
|
97
|
|
|
98
|
|
- _, extension = os.path.splitext(photo.name)
|
|
99
|
|
- extension = extension or 'jpeg'
|
|
100
|
|
-
|
|
101
|
|
- m_photo_path = 'photo/{uuid}{extension}'.format(uuid=shortuuid.uuid(), extension=extension)
|
|
102
|
|
-
|
|
103
|
|
- if default_storage.exists(m_photo_path):
|
|
104
|
|
- default_storage.delete(m_photo_path)
|
|
105
|
|
- default_storage.save(m_photo_path, photo)
|
|
106
|
|
-
|
|
107
|
|
- p_photo_path = 'photo/{uuid}{extension}'.format(uuid=shortuuid.uuid(), extension=extension)
|
|
|
98
|
+ p_photo_path = 'photo/{}{}'.format(shortuuid.uuid(), ext)
|
|
108
|
99
|
watermark_wrap(
|
|
109
|
100
|
os.path.join(settings.MEDIA_ROOT, m_photo_path).replace('\\', '/'),
|
|
110
|
101
|
settings.WATERMARK_LOGO,
|
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+# -*- coding: utf-8 -*-
|
|
|
2
|
+
|
|
|
3
|
+import os
|
|
|
4
|
+
|
|
|
5
|
+import shortuuid
|
|
|
6
|
+from django.core.files.storage import default_storage
|
|
|
7
|
+
|
|
|
8
|
+
|
|
|
9
|
+def file_save(file_, prefix='img', ext='jpeg'):
|
|
|
10
|
+ ext = os.path.splitext(file_.name)[-1] or ext
|
|
|
11
|
+ path = '{}/{}{}'.format(prefix, shortuuid.uuid(), ext)
|
|
|
12
|
+ if default_storage.exists(path):
|
|
|
13
|
+ default_storage.delete(path)
|
|
|
14
|
+ default_storage.save(path, file_)
|
|
|
15
|
+ return path, ext
|