feat: 整页拍 + 点选出错题(scanflow + 工作台界面)
This commit is contained in:
+29
-1
@@ -24,7 +24,7 @@ from urllib.parse import parse_qs, urlparse
|
||||
|
||||
from . import db as dbm
|
||||
from . import qr
|
||||
from . import services as svc
|
||||
from . import scanflow, services as svc
|
||||
from .services import ApiError
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
@@ -265,6 +265,34 @@ def post_paper(ctx: Ctx, **kw):
|
||||
int(ctx.body.get("image_count") or 1))
|
||||
|
||||
|
||||
def _decode_image(ctx: Ctx) -> bytes:
|
||||
raw = str(ctx.body.get("image_b64") or "")
|
||||
if "," in raw[:80] and raw.lstrip().startswith("data:"):
|
||||
raw = raw.split(",", 1)[1]
|
||||
try:
|
||||
return base64.b64decode(raw, validate=False)
|
||||
except Exception: # noqa: BLE001
|
||||
raise svc.ApiError(400, "BAD_IMAGE", "图片不是合法的 base64")
|
||||
|
||||
|
||||
@route("POST", "/api/papers/scan/detect", auth="parent")
|
||||
def post_scan_detect(ctx: Ctx, **kw):
|
||||
"""整页拍 → 切块 → 返回每块的框,让家长在图上点「哪几道错了」。"""
|
||||
image = _decode_image(ctx)
|
||||
return scanflow.detect(image, str(ctx.body.get("filename") or "page.jpg"))
|
||||
|
||||
|
||||
@route("POST", "/api/papers/scan/import", auth="parent")
|
||||
def post_scan_import(ctx: Ctx, **kw):
|
||||
"""家长勾完 → 只把选中的块裁出来单独识别并入库。"""
|
||||
picks = ctx.body.get("picks") or []
|
||||
if not isinstance(picks, list):
|
||||
raise svc.ApiError(400, "BAD_PICKS", "picks 要是数组")
|
||||
return svc.import_scan_picks(
|
||||
ctx.conn, ctx.gid, str(ctx.body.get("child_id") or ""),
|
||||
str(ctx.body.get("subject") or "math"), str(ctx.body.get("draft_id") or ""), picks)
|
||||
|
||||
|
||||
@route("POST", "/api/papers/ocr", auth="parent")
|
||||
def post_paper_ocr(ctx: Ctx, **kw):
|
||||
"""真拍照:图片 base64 → OCR → 切题 → 入库。OCR 不可用时按参数退回演示题库。"""
|
||||
|
||||
Reference in New Issue
Block a user