114- 115- 116:@router.post("/import") 117-async def import_commit(list_id: int = Form(...), file: UploadFile = File(...), 118- user: User = Depends(get_current_user), 119- db: AsyncSession = Depends(get_db), request: Request = None): 120- """Commit an import into the given list (same validation as preview).""" 121- rl = await db.get(RecipientList, list_id) 122- if not rl or rl.user_id != user.id: 123- raise HTTPException(404, "Recipient list not found") 124- content = await file.read() 125- if len(content) > settings.MAX_UPLOAD_MB * 1024 * 1024: 126- raise HTTPException(413, "File too large") 127- fname = (file.filename or "").lower() 128- if fname.endswith(".json"): 129- raise HTTPException(400, "JSON recipient files are not accepted. Use CSV or TXT.") 130- if not (fname.endswith(".csv") or fname.endswith(".txt")): 131- raise HTTPException(400, "Only .csv and .txt files are accepted") 132- 133- if fname.endswith(".txt"): 134- lines = recipient_service.parse_txt(content.decode("utf-8", errors="replace")) 135- records = [] 136- for ln in lines: 137- parts = [p.strip() for p in ln.split(",")] 138- rec = {"email": parts[0]} 139- if len(parts) > 1: 140- rec["first_name"] = parts[1] 141- if len(parts) > 2: