llm-api/wiki_router.py aktualisiert
All checks were successful
Deploy Trainer_LLM to llm-node / deploy (push) Successful in 2s
All checks were successful
Deploy Trainer_LLM to llm-node / deploy (push) Successful in 2s
This commit is contained in:
parent
5c9c8951c1
commit
d9abcb3ef4
|
|
@ -118,42 +118,66 @@ def health() -> Dict[str, str]:
|
||||||
|
|
||||||
@router.post("/login", response_model=WikiLoginResponse)
|
@router.post("/login", response_model=WikiLoginResponse)
|
||||||
def login(data: WikiLoginRequest):
|
def login(data: WikiLoginRequest):
|
||||||
# Token holen
|
# 1) Token holen
|
||||||
try:
|
try:
|
||||||
token_resp = wiki_session.get(
|
tok = wiki_session.get(
|
||||||
WIKI_API_URL,
|
WIKI_API_URL,
|
||||||
params={"action":"query","meta":"tokens","type":"login","format":"json"},
|
params={"action":"query","meta":"tokens","type":"login","format":"json"},
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
token_resp.raise_for_status()
|
tok.raise_for_status()
|
||||||
token = token_resp.json().get("query", {}).get("tokens", {}).get("logintoken")
|
logintoken = tok.json().get("query", {}).get("tokens", {}).get("logintoken")
|
||||||
|
if not logintoken:
|
||||||
|
raise HTTPException(status_code=502, detail="Kein Login-Token erhalten")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=502, detail=f"Token-Error: {e}")
|
raise HTTPException(status_code=502, detail=f"Token-Error: {e}")
|
||||||
if not token:
|
|
||||||
raise HTTPException(status_code=502, detail="Kein Login-Token erhalten")
|
|
||||||
|
|
||||||
# clientlogin
|
# 2) Versuch: clientlogin (mit loginreturnurl!)
|
||||||
try:
|
try:
|
||||||
login_resp = wiki_session.post(
|
cl = wiki_session.post(
|
||||||
WIKI_API_URL,
|
WIKI_API_URL,
|
||||||
data={
|
data={
|
||||||
"action": "clientlogin",
|
"action": "clientlogin",
|
||||||
"format": "json",
|
"format": "json",
|
||||||
"username": data.username,
|
"username": data.username,
|
||||||
"password": data.password,
|
"password": data.password,
|
||||||
"logintoken": token,
|
"logintoken": logintoken,
|
||||||
|
"loginreturnurl": "https://example.org/" # notwendig bei manchen Setups
|
||||||
},
|
},
|
||||||
timeout=15,
|
timeout=15,
|
||||||
)
|
)
|
||||||
login_resp.raise_for_status()
|
cl.raise_for_status()
|
||||||
status = login_resp.json().get("clientlogin", {}).get("status")
|
clj = cl.json().get("clientlogin", {})
|
||||||
if status != "PASS":
|
if clj.get("status") == "PASS":
|
||||||
raise HTTPException(status_code=401, detail=f"Login fehlgeschlagen: {status}")
|
return WikiLoginResponse(status="success")
|
||||||
|
# Falls UI/FAIL/etc.: weiter mit Legacy
|
||||||
|
except Exception as e:
|
||||||
|
# nicht sofort fehlschlagen – Legacy probieren
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 3) Fallback: action=login (Legacy)
|
||||||
|
try:
|
||||||
|
lg = wiki_session.post(
|
||||||
|
WIKI_API_URL,
|
||||||
|
data={
|
||||||
|
"action": "login",
|
||||||
|
"format": "json",
|
||||||
|
"lgname": data.username,
|
||||||
|
"lgpassword": data.password,
|
||||||
|
"lgtoken": logintoken,
|
||||||
|
},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
lg.raise_for_status()
|
||||||
|
res = lg.json().get("login", {}).get("result")
|
||||||
|
if res == "Success":
|
||||||
|
return WikiLoginResponse(status="success")
|
||||||
|
raise HTTPException(status_code=401, detail=f"Login fehlgeschlagen (legacy): {res}")
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=502, detail=f"Login-Error: {e}")
|
raise HTTPException(status_code=502, detail=f"Login-Error (legacy): {e}")
|
||||||
return WikiLoginResponse(status="success")
|
|
||||||
|
|
||||||
@router.get("/semantic/pages")
|
@router.get("/semantic/pages")
|
||||||
def semantic_pages(category: str = Query(..., description="Kategorie ohne 'Category:'")) -> Dict[str, Any]:
|
def semantic_pages(category: str = Query(..., description="Kategorie ohne 'Category:'")) -> Dict[str, Any]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user