sycommon-python-lib 0.2.12a2__py3-none-any.whl → 0.2.12a3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ import asyncio
28
28
  import contextlib
29
29
  import json
30
30
  import os
31
+ import re
31
32
  import shutil
32
33
  import signal
33
34
  import subprocess
@@ -660,6 +661,38 @@ def setup_devchat_handler(app: FastAPI, config: Optional[dict] = None) -> FastAP
660
661
  "current": st.session_id}
661
662
  return {"sessions": [], "current": st.session_id}
662
663
 
664
+ @router.post("/upload")
665
+ async def upload(request: Request):
666
+ """附件上传(文件/图片):落 {projectRoot}/.devchat/uploads/,
667
+ 返回相对路径;消息文本引用路径,claude 用 Read 直接查看
668
+ (文本与图片多模态都支持)。与 Go 版同契约。"""
669
+ ident = await _identity(request)
670
+ if ident is None:
671
+ return JSONResponse({"detail": "未登录或无权访问 DevChat"}, status_code=401)
672
+ try:
673
+ form = await request.form()
674
+ up = form.get("file")
675
+ if up is None or not hasattr(up, "filename"):
676
+ return JSONResponse({"detail": "缺少 file 字段(multipart)"}, status_code=400)
677
+ data = await up.read()
678
+ if len(data) > 16 << 20:
679
+ return JSONResponse(
680
+ {"detail": f"文件过大({len(data) >> 20} MB),上限 16MB"},
681
+ status_code=413)
682
+ root = cfg.projectRoot or os.getcwd()
683
+ dir_path = os.path.join(root, ".devchat", "uploads")
684
+ os.makedirs(dir_path, exist_ok=True)
685
+ # 文件名清洗:取 base + 危险字符替换(路径穿越防御)。
686
+ safe = re.sub(r"[^\w.\-一-鿿]", "_",
687
+ os.path.basename(up.filename or "file")) or "file"
688
+ name = f"{time.time_ns()}-{safe[-80:]}"
689
+ with open(os.path.join(dir_path, name), "wb") as f:
690
+ f.write(data)
691
+ return {"path": f".devchat/uploads/{name}",
692
+ "name": up.filename, "size": len(data)}
693
+ except Exception as exc: # noqa: BLE001
694
+ return JSONResponse({"detail": f"上传失败: {exc}"}, status_code=500)
695
+
663
696
  @router.get("/status")
664
697
  async def status(request: Request):
665
698
  ident = await _identity(request)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sycommon-python-lib
3
- Version: 0.2.12a2
3
+ Version: 0.2.12a3
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -216,7 +216,7 @@ sycommon/database/token_usage_db_service.py,sha256=iYK51ZtGNpBA4nj2IhflltbftE5Fs
216
216
  sycommon/database/txnref.py,sha256=sOFp85PlanCA0oryVpHu53JbM0aSHAVkELWgEJKalLI,7755
217
217
  sycommon/devchat/__init__.py,sha256=Z2BgzDKrp_mR165d3a1kftP8lf1-WKz_5xuZMFXR-iw,2288
218
218
  sycommon/devchat/_page.py,sha256=JzTX7Wv_4-nJky7wg5E44yftSQYvC9L9_YsQzNnaWhI,406
219
- sycommon/devchat/handler.py,sha256=aH6disGCjguluH-9sUMi1O_rAtr6o79cl0YFoC2ArSQ,30242
219
+ sycommon/devchat/handler.py,sha256=ix_nU_8vllmt2wHhEMMFRwwrwraWSAGZ6f3gK7NHiBg,31957
220
220
  sycommon/devchat/store.py,sha256=leNJunuCjS8t4dTrCxYooBO8EQl69dtAyV-2HHlJ_uM,3957
221
221
  sycommon/devchat/tasks.py,sha256=hh4Gv04bkI_-MP-OCfKG09NEZXuURz-i2iAARTeEdZI,11688
222
222
  sycommon/health/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -401,8 +401,8 @@ sycommon/tools/usercache.py,sha256=Zu2oiXISUOojleEYCAS9t06ZzgWSNHCIhCjv4yTtkRw,4
401
401
  sycommon/xxljob/__init__.py,sha256=7eoBlQxv-B39IfRSCY2bkqdGYs1QRe1umAWd88VMEEM,86
402
402
  sycommon/xxljob/sharding.py,sha256=LJ0tle7qSUS32S5ntjzri1aOcPzwL5CFde3W4Rf1AUE,2560
403
403
  sycommon/xxljob/xxljob_service.py,sha256=1yifwIBNGsCIxLnQjHKiBlbsigc_zvPH-dMTZcNxe-Q,7649
404
- sycommon_python_lib-0.2.12a2.dist-info/METADATA,sha256=Ui57T4g2s8XDIsoQbo0AKWRCiNDPYfRIqdIUvit-l6E,8028
405
- sycommon_python_lib-0.2.12a2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
406
- sycommon_python_lib-0.2.12a2.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
407
- sycommon_python_lib-0.2.12a2.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
408
- sycommon_python_lib-0.2.12a2.dist-info/RECORD,,
404
+ sycommon_python_lib-0.2.12a3.dist-info/METADATA,sha256=rYJx3foOincQsDexTV4e2miEJ9dYwGVo7AwTLqs2ayA,8028
405
+ sycommon_python_lib-0.2.12a3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
406
+ sycommon_python_lib-0.2.12a3.dist-info/entry_points.txt,sha256=gsR4SssKxDWjRU8ggidzNcdMXDPRSKRS7UaGyNP84Qg,92
407
+ sycommon_python_lib-0.2.12a3.dist-info/top_level.txt,sha256=RgphKrg7nJyZ7irJqbxFr-5H2LUYTvI7ivoWZH2hcD0,29
408
+ sycommon_python_lib-0.2.12a3.dist-info/RECORD,,