Refactor credit parse to use remote HTML paths
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from typing import Optional
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import urlopen
|
||||
|
||||
from fastapi import APIRouter, File, Form, UploadFile
|
||||
from fastapi import APIRouter, Form
|
||||
|
||||
from services.credit_debug_service import CreditDebugService
|
||||
from services.credit_html_identity_service import CreditHtmlIdentityService
|
||||
@@ -12,26 +14,30 @@ debug_service = CreditDebugService("config/credit_response_examples.json")
|
||||
identity_service = CreditHtmlIdentityService()
|
||||
|
||||
|
||||
@router.post("/xfeature-mngs/conversation/htmlEval")
|
||||
@router.post("/api/service/interface/invokeService/xfeature")
|
||||
async def html_eval(
|
||||
serialNum: Optional[str] = Form(None),
|
||||
orgCode: Optional[str] = Form(None),
|
||||
runType: Optional[str] = Form(None),
|
||||
remotePath: Optional[str] = Form(None),
|
||||
model: Optional[str] = Form(None),
|
||||
hType: Optional[str] = Form(None),
|
||||
file: Optional[UploadFile] = File(None),
|
||||
):
|
||||
error_response = debug_service.validate_request(
|
||||
serial_num=serialNum,
|
||||
org_code=orgCode,
|
||||
run_type=runType,
|
||||
remote_path=remotePath,
|
||||
model=model,
|
||||
h_type=hType,
|
||||
file_present=file is not None,
|
||||
)
|
||||
if error_response:
|
||||
return error_response
|
||||
|
||||
html_content = await file.read()
|
||||
html_content = fetch_remote_html(remotePath)
|
||||
subject_identity = identity_service.extract_identity(html_content)
|
||||
payload = payload_service.generate_payload(
|
||||
model=model,
|
||||
h_type=hType,
|
||||
filename=file.filename or "credit.html",
|
||||
h_type="PERSON",
|
||||
filename=remote_filename(remotePath),
|
||||
subject_identity=subject_identity,
|
||||
)
|
||||
return debug_service.build_success_response(payload)
|
||||
@@ -40,3 +46,14 @@ async def html_eval(
|
||||
@router.get("/credit/health")
|
||||
async def credit_health():
|
||||
return {"status": "healthy", "service": "credit-mock"}
|
||||
|
||||
|
||||
def fetch_remote_html(remote_path: str) -> bytes:
|
||||
with urlopen(remote_path, timeout=5) as response:
|
||||
return response.read()
|
||||
|
||||
|
||||
def remote_filename(remote_path: str) -> str:
|
||||
path = urlparse(remote_path).path
|
||||
filename = path.rsplit("/", 1)[-1]
|
||||
return filename or "credit.html"
|
||||
|
||||
Reference in New Issue
Block a user