取消ZIP材料包照片数量限制,保留文件大小校验
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## 活动记录
|
## 活动记录
|
||||||
|
|
||||||
在一楼页面创建活动时默认选择“赋能中心一楼活动记录”,地点默认填“赋能中心一楼”。此类记录必须填写主题、时间,并提交一个 ZIP 材料包,最大 30MB。ZIP 内须含 1–5 张 JPG、PNG 或 WebP 照片,每张最大 8MB、2400 万像素;可附 PDF、Word、Excel、PowerPoint、TXT、CSV 或 Markdown 材料,单个文档最大 20MB。支持文件夹,最多 100 项,展开后总大小不超过 100MB;不支持加密 ZIP、链接、不安全路径及可执行文件。
|
在一楼页面创建活动时默认选择“赋能中心一楼活动记录”,地点默认填“赋能中心一楼”。此类记录必须填写主题、时间,并提交一个 ZIP 材料包,最大 30MB。ZIP 内须至少含 1 张 JPG、PNG 或 WebP 照片,照片数量不限,每张最大 8MB、2400 万像素;可附 PDF、Word、Excel、PowerPoint、TXT、CSV 或 Markdown 材料,单个文档最大 20MB。支持文件夹,展开后总大小不超过 100MB;不支持加密 ZIP、链接、不安全路径及可执行文件。ZIP 上传不再按照片数量计算每日限额。
|
||||||
|
|
||||||
页面会从包内提取照片,转换为 JPEG、缩小到最长边 2400px 并移除预览照片的 EXIF 信息;原始 ZIP 原样保留,可在活动卡片或详情中下载。活动墙可按普通 / 一楼活动筛选;一楼入口可按主题和起止日期筛选。照片和材料包沿用活动可见范围,仅上传人及该活动有权查看者可访问。编辑时不选新包会保留原材料,选择新包会替换关联材料。历史照片记录继续显示、可编辑,无须重新提交。
|
页面会从包内提取照片,转换为 JPEG、缩小到最长边 2400px 并移除预览照片的 EXIF 信息;原始 ZIP 原样保留,可在活动卡片或详情中下载。活动墙可按普通 / 一楼活动筛选;一楼入口可按主题和起止日期筛选。照片和材料包沿用活动可见范围,仅上传人及该活动有权查看者可访问。编辑时不选新包会保留原材料,选择新包会替换关联材料。历史照片记录继续显示、可编辑,无须重新提交。
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -309,7 +309,7 @@
|
|||||||
|
|
||||||
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
||||||
|
|
||||||
<script src="/js/app.js?v=25"></script>
|
<script src="/js/app.js?v=26"></script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Vendored
+1
-1
@@ -808,7 +808,7 @@
|
|||||||
<label>地点<input name="location" maxlength="120" value="${esc(existing?.location || "")}" placeholder="如:3 号会议室" /></label>
|
<label>地点<input name="location" maxlength="120" value="${esc(existing?.location || "")}" placeholder="如:3 号会议室" /></label>
|
||||||
</div>
|
</div>
|
||||||
<label>备注 <span class="hint-inline">(选填)</span><textarea name="description" rows="3" maxlength="2000" placeholder="做什么、带什么、注意事项…">${esc(existing?.description || "")}</textarea></label>
|
<label>备注 <span class="hint-inline">(选填)</span><textarea name="description" rows="3" maxlength="2000" placeholder="做什么、带什么、注意事项…">${esc(existing?.description || "")}</textarea></label>
|
||||||
<div id="act-photo-fields" class="hidden"><label>活动材料 ZIP(必填)<input name="materials" type="file" accept=".zip,application/zip" /></label><p class="muted">最大30MB,包内须含1–5张活动照片,可附PDF、Office或文本材料。编辑时不选新包会保留原材料。</p><p id="act-material-name" class="muted"></p><div id="act-photo-preview" class="activity-photos">${(existing?.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div></div>
|
<div id="act-photo-fields" class="hidden"><label>活动材料 ZIP(必填)<input name="materials" type="file" accept=".zip,application/zip" /></label><p class="muted">最大30MB,包内须至少含1张活动照片,照片数量不限,可附PDF、Office或文本材料。编辑时不选新包会保留原材料。</p><p id="act-material-name" class="muted"></p><div id="act-photo-preview" class="activity-photos">${(existing?.photo_ids || []).map(id => `<img data-photo="${esc(id)}" alt="活动照片" />`).join('')}</div></div>
|
||||||
<label class="checkline"><input type="checkbox" name="visibility" ${!existing || existing.visibility === "public" ? "checked" : ""} /> 公开活动(所有人可见;不勾选则仅参加者可见)</label>
|
<label class="checkline"><input type="checkbox" name="visibility" ${!existing || existing.visibility === "public" ? "checked" : ""} /> 公开活动(所有人可见;不勾选则仅参加者可见)</label>
|
||||||
<div class="form-error" id="act-error"></div>
|
<div class="form-error" id="act-error"></div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
+3
-7
@@ -56,8 +56,8 @@ def now_ms(): return int(time.time() * 1000)
|
|||||||
|
|
||||||
|
|
||||||
async def validate_photos(db, ids, owner_id, existing=()):
|
async def validate_photos(db, ids, owner_id, existing=()):
|
||||||
if not 1 <= len(ids) <= 5 or len(set(ids)) != len(ids):
|
if not ids or len(set(ids)) != len(ids):
|
||||||
raise HTTPException(422, '一楼活动须上传1至5张照片,照片不能重复')
|
raise HTTPException(422, '一楼活动须至少上传1张照片,照片不能重复')
|
||||||
rows = (await db.execute(select(center_photos).where(center_photos.c.id.in_(ids)))).mappings().all()
|
rows = (await db.execute(select(center_photos).where(center_photos.c.id.in_(ids)))).mappings().all()
|
||||||
if len(rows) != len(ids) or any(r['owner_id'] != owner_id and r['id'] not in existing for r in rows):
|
if len(rows) != len(ids) or any(r['owner_id'] != owner_id and r['id'] not in existing for r in rows):
|
||||||
raise HTTPException(403, '照片不存在或不属于当前账号')
|
raise HTTPException(403, '照片不存在或不属于当前账号')
|
||||||
@@ -94,7 +94,7 @@ def convert_package(raw):
|
|||||||
allowed={'.jpg','.jpeg','.png','.webp','.pdf','.doc','.docx','.xls','.xlsx','.ppt','.pptx','.txt','.csv','.md'}
|
allowed={'.jpg','.jpeg','.png','.webp','.pdf','.doc','.docx','.xls','.xlsx','.ppt','.pptx','.txt','.csv','.md'}
|
||||||
with zipfile.ZipFile(io.BytesIO(raw)) as archive:
|
with zipfile.ZipFile(io.BytesIO(raw)) as archive:
|
||||||
entries=archive.infolist()
|
entries=archive.infolist()
|
||||||
if len(entries)>100 or sum(e.file_size for e in entries)>100*1024*1024:raise ValueError('ZIP最多100项,展开后不超过100MB')
|
if sum(e.file_size for e in entries)>100*1024*1024:raise ValueError('ZIP展开后不超过100MB')
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
name=entry.filename.replace('\\','/');path=PurePosixPath(name)
|
name=entry.filename.replace('\\','/');path=PurePosixPath(name)
|
||||||
if path.is_absolute() or '..' in path.parts or ':' in name or '\x00' in name or ((entry.external_attr>>16)&0o170000)==0o120000:raise ValueError('ZIP包含不安全路径或链接')
|
if path.is_absolute() or '..' in path.parts or ':' in name or '\x00' in name or ((entry.external_attr>>16)&0o170000)==0o120000:raise ValueError('ZIP包含不安全路径或链接')
|
||||||
@@ -108,7 +108,6 @@ def convert_package(raw):
|
|||||||
if path.suffix.lower() in {'.jpg','.jpeg','.png','.webp'}:
|
if path.suffix.lower() in {'.jpg','.jpeg','.png','.webp'}:
|
||||||
if entry.file_size>8*1024*1024:raise ValueError('包内单张照片不超过8MB')
|
if entry.file_size>8*1024*1024:raise ValueError('包内单张照片不超过8MB')
|
||||||
photos.append(convert_photo(archive.read(entry)))
|
photos.append(convert_photo(archive.read(entry)))
|
||||||
if len(photos)>5:raise ValueError('ZIP内最多5张活动照片')
|
|
||||||
if not photos:raise ValueError('ZIP内至少需要1张JPG、PNG或WebP活动照片')
|
if not photos:raise ValueError('ZIP内至少需要1张JPG、PNG或WebP活动照片')
|
||||||
return photos
|
return photos
|
||||||
|
|
||||||
@@ -123,11 +122,8 @@ def install(app, get_db, current_user, photo_root, visible_clause, approver_emai
|
|||||||
async for chunk in request.stream():
|
async for chunk in request.stream():
|
||||||
raw.extend(chunk)
|
raw.extend(chunk)
|
||||||
if len(raw)>30*1024*1024:raise HTTPException(413,'ZIP材料包最大30MB')
|
if len(raw)>30*1024*1024:raise HTTPException(413,'ZIP材料包最大30MB')
|
||||||
count=(await db.execute(select(func.count()).select_from(center_photos).where(center_photos.c.owner_id==viewer['id'],center_photos.c.created_at>now_ms()-86400000))).scalar()
|
|
||||||
if count>=100:raise HTTPException(429,'今日照片上传已达上限')
|
|
||||||
try:photos=await asyncio.to_thread(convert_package,bytes(raw))
|
try:photos=await asyncio.to_thread(convert_package,bytes(raw))
|
||||||
except Exception as exc:raise HTTPException(422,str(exc) if isinstance(exc,ValueError) else 'ZIP材料包无效或损坏') from exc
|
except Exception as exc:raise HTTPException(422,str(exc) if isinstance(exc,ValueError) else 'ZIP材料包无效或损坏') from exc
|
||||||
if count+len(photos)>100:raise HTTPException(429,'材料包中的照片超过今日上传上限')
|
|
||||||
key=uuid.uuid4().hex;folder=photo_root();folder.mkdir(parents=True,exist_ok=True);paths=[];ids=[]
|
key=uuid.uuid4().hex;folder=photo_root();folder.mkdir(parents=True,exist_ok=True);paths=[];ids=[]
|
||||||
try:
|
try:
|
||||||
package=folder/(key+'.zip');paths.append(package);await asyncio.to_thread(package.write_bytes,bytes(raw))
|
package=folder/(key+'.zip');paths.append(package);await asyncio.to_thread(package.write_bytes,bytes(raw))
|
||||||
|
|||||||
+2
-2
@@ -481,7 +481,7 @@ class ChangeEmailIn(NewEmailIn):
|
|||||||
class ActivityIn(BaseModel):
|
class ActivityIn(BaseModel):
|
||||||
material_id: Optional[str] = Field(default=None, max_length=32)
|
material_id: Optional[str] = Field(default=None, max_length=32)
|
||||||
record_type: Literal['normal', 'center'] = 'normal'
|
record_type: Literal['normal', 'center'] = 'normal'
|
||||||
photo_ids: list[str] = Field(default_factory=list, max_length=5)
|
photo_ids: list[str] = Field(default_factory=list)
|
||||||
title: str = Field(min_length=1, max_length=120)
|
title: str = Field(min_length=1, max_length=120)
|
||||||
start_at: int = Field(gt=0)
|
start_at: int = Field(gt=0)
|
||||||
location: str = Field(default="", max_length=120)
|
location: str = Field(default="", max_length=120)
|
||||||
@@ -501,7 +501,7 @@ class ActivityIn(BaseModel):
|
|||||||
class ActivityPatch(BaseModel):
|
class ActivityPatch(BaseModel):
|
||||||
material_id: Optional[str] = Field(default=None, max_length=32)
|
material_id: Optional[str] = Field(default=None, max_length=32)
|
||||||
record_type: Optional[Literal['normal', 'center']] = None
|
record_type: Optional[Literal['normal', 'center']] = None
|
||||||
photo_ids: Optional[list[str]] = Field(default=None, max_length=5)
|
photo_ids: Optional[list[str]] = None
|
||||||
title: Optional[str] = Field(default=None, max_length=120)
|
title: Optional[str] = Field(default=None, max_length=120)
|
||||||
start_at: Optional[int] = Field(default=None, gt=0)
|
start_at: Optional[int] = Field(default=None, gt=0)
|
||||||
location: Optional[str] = Field(default=None, max_length=120)
|
location: Optional[str] = Field(default=None, max_length=120)
|
||||||
|
|||||||
@@ -20,6 +20,33 @@ def package(entries=None):
|
|||||||
|
|
||||||
|
|
||||||
class CenterExportTests(ApiTestCase):
|
class CenterExportTests(ApiTestCase):
|
||||||
|
async def test_material_with_over_100_photos_can_be_created_edited_and_downloaded(self):
|
||||||
|
owner=await register(self.client,'manyphotos');headers=auth(owner['token'])
|
||||||
|
image=io.BytesIO();Image.new('RGB',(20,20),'blue').save(image,'PNG')
|
||||||
|
raw=package([(f'照片/{i}.png',image.getvalue()) for i in range(101)])
|
||||||
|
with tempfile.TemporaryDirectory() as directory,patch.object(self.m,'_db_path',Path(directory)/'test.db'):
|
||||||
|
response=await self.client.post('/api/center/materials',headers=headers,content=raw)
|
||||||
|
self.assertEqual(response.status_code,200,response.text)
|
||||||
|
material=response.json();self.assertEqual(len(material['photo_ids']),101)
|
||||||
|
response=await self.client.post('/api/activities',headers=headers,json={
|
||||||
|
'title':'多照片一楼活动','start_at':self.m.now_ms(),'record_type':'center',
|
||||||
|
'material_id':material['id'],'photo_ids':material['photo_ids'],
|
||||||
|
})
|
||||||
|
self.assertEqual(response.status_code,200,response.text)
|
||||||
|
activity=response.json()['activity'];self.assertEqual(len(activity['photo_ids']),101)
|
||||||
|
edited=await self.client.patch('/api/activities/'+activity['id'],headers=headers,json={
|
||||||
|
'description':'更新说明','photo_ids':material['photo_ids'],
|
||||||
|
})
|
||||||
|
self.assertEqual(edited.status_code,200,edited.text)
|
||||||
|
self.assertEqual(edited.json()['activity']['photo_ids'],material['photo_ids'])
|
||||||
|
downloaded=await self.client.get('/api/center/materials/'+material['id'],headers=headers)
|
||||||
|
self.assertEqual(downloaded.status_code,200);self.assertEqual(downloaded.content,raw)
|
||||||
|
last_photo=await self.client.get('/api/center/photos/'+material['photo_ids'][-1],headers=headers)
|
||||||
|
self.assertEqual(last_photo.status_code,200)
|
||||||
|
# 同一天已有超过100张照片,也可以继续提交ZIP材料。
|
||||||
|
second=await self.client.post('/api/center/materials',headers=headers,content=package())
|
||||||
|
self.assertEqual(second.status_code,200,second.text)
|
||||||
|
|
||||||
async def test_api_auth_export_all_and_contact_redaction(self):
|
async def test_api_auth_export_all_and_contact_redaction(self):
|
||||||
for path in ['/api/center/data','/api/center/schema','/api/center/export']:
|
for path in ['/api/center/data','/api/center/schema','/api/center/export']:
|
||||||
self.assertEqual((await self.client.get(path)).status_code,401)
|
self.assertEqual((await self.client.get(path)).status_code,401)
|
||||||
|
|||||||
Reference in New Issue
Block a user