支持MPO多镜头JPG照片上传

This commit is contained in:
2026-11-19 15:14:14 +08:00
parent d82e9dc407
commit 21e7881344
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ def convert_photo(raw):
with warnings.catch_warnings():
warnings.simplefilter('error', Image.DecompressionBombError)
with Image.open(io.BytesIO(raw)) as image:
if image.format not in ('JPEG', 'PNG', 'WEBP'):
if image.format not in ('JPEG', 'MPO', 'PNG', 'WEBP'):
raise ValueError('仅支持JPG、PNG、WebP照片')
image = ImageOps.exif_transpose(image).convert('RGB')
output = io.BytesIO(); image.save(output, 'JPEG', quality=90)
+10
View File
@@ -41,6 +41,16 @@ class DirectCenterPhotoTests(ApiTestCase):
self.assertEqual(stored.format,'JPEG')
self.assertEqual(stored.size,(4021,237))
async def test_mpo_multi_picture_jpg_converts_as_jpeg(self):
owner=await register(self.client,'mpophoto');headers=auth(owner['token'])
image=Image.new('RGB',(32,32),'blue')
raw=io.BytesIO();image.save(raw,'MPO')
result=await self.client.post('/api/center/photos',headers=headers,content=raw.getvalue())
self.assertEqual(result.status_code,200,result.text)
photo=await self.client.get('/api/center/photos/'+result.json()['id'],headers=headers)
with Image.open(io.BytesIO(photo.content)) as stored:
self.assertEqual(stored.format,'JPEG'); self.assertEqual(stored.size,(32,32))
async def test_photo_only_creation_supplement_and_edit_preserve_all_members_photos(self):
owner=await register(self.client,'directowner');member=await register(self.client,'directmember')
c=self.client;oh=auth(owner['token']);mh=auth(member['token'])