diff --git a/CENTER.md b/CENTER.md index e0cfff6..f4edde7 100644 --- a/CENTER.md +++ b/CENTER.md @@ -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 原样保留,可在活动卡片或详情中下载。活动墙可按普通 / 一楼活动筛选;一楼入口可按主题和起止日期筛选。照片和材料包沿用活动可见范围,仅上传人及该活动有权查看者可访问。编辑时不选新包会保留原材料,选择新包会替换关联材料。历史照片记录继续显示、可编辑,无须重新提交。 diff --git a/dist/index.html b/dist/index.html index 825d566..6476a20 100644 --- a/dist/index.html +++ b/dist/index.html @@ -309,7 +309,7 @@ - + diff --git a/dist/js/app.js b/dist/js/app.js index dc0a573..84f3978 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -808,7 +808,7 @@ - +
diff --git a/server/center.py b/server/center.py index 22363c8..f746675 100644 --- a/server/center.py +++ b/server/center.py @@ -56,8 +56,8 @@ def now_ms(): return int(time.time() * 1000) async def validate_photos(db, ids, owner_id, existing=()): - if not 1 <= len(ids) <= 5 or len(set(ids)) != len(ids): - raise HTTPException(422, '一楼活动须上传1至5张照片,照片不能重复') + if not ids or len(set(ids)) != len(ids): + raise HTTPException(422, '一楼活动须至少上传1张照片,照片不能重复') 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): 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'} with zipfile.ZipFile(io.BytesIO(raw)) as archive: 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: 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包含不安全路径或链接') @@ -108,7 +108,6 @@ def convert_package(raw): if path.suffix.lower() in {'.jpg','.jpeg','.png','.webp'}: if entry.file_size>8*1024*1024:raise ValueError('包内单张照片不超过8MB') 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活动照片') 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(): raw.extend(chunk) 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)) 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=[] try: package=folder/(key+'.zip');paths.append(package);await asyncio.to_thread(package.write_bytes,bytes(raw)) diff --git a/server/main.py b/server/main.py index 07ce80c..e88a11e 100644 --- a/server/main.py +++ b/server/main.py @@ -481,7 +481,7 @@ class ChangeEmailIn(NewEmailIn): class ActivityIn(BaseModel): material_id: Optional[str] = Field(default=None, max_length=32) 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) start_at: int = Field(gt=0) location: str = Field(default="", max_length=120) @@ -501,7 +501,7 @@ class ActivityIn(BaseModel): class ActivityPatch(BaseModel): material_id: Optional[str] = Field(default=None, max_length=32) 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) start_at: Optional[int] = Field(default=None, gt=0) location: Optional[str] = Field(default=None, max_length=120) diff --git a/tests/test_center_export.py b/tests/test_center_export.py index 698e80f..15fdef4 100644 --- a/tests/test_center_export.py +++ b/tests/test_center_export.py @@ -20,6 +20,33 @@ def package(entries=None): 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): for path in ['/api/center/data','/api/center/schema','/api/center/export']: self.assertEqual((await self.client.get(path)).status_code,401)