Best-effort extract the document URL from different Feishu response shapes.
(doc_info: Dict[str, Any])
| 453 | |
| 454 | |
| 455 | def extract_doc_url(doc_info: Dict[str, Any]) -> Optional[str]: |
| 456 | """Best-effort extract the document URL from different Feishu response shapes.""" |
| 457 | if not isinstance(doc_info, dict): |
| 458 | return None |
| 459 | |
| 460 | def _valid_url(candidate: Any) -> Optional[str]: |
| 461 | text = str(candidate or "").strip() |
| 462 | if text.startswith("http://") or text.startswith("https://"): |
| 463 | return text |
| 464 | return None |
| 465 | |
| 466 | for candidate in (doc_info.get("url"), doc_info.get("doc_url"), doc_info.get("link")): |
| 467 | valid = _valid_url(candidate) |
| 468 | if valid: |
| 469 | return valid |
| 470 | |
| 471 | data = doc_info.get("data") |
| 472 | if isinstance(data, dict): |
| 473 | for candidate in (data.get("url"), data.get("doc_url"), data.get("link")): |
| 474 | valid = _valid_url(candidate) |
| 475 | if valid: |
| 476 | return valid |
| 477 | |
| 478 | document = data.get("document") |
| 479 | if isinstance(document, dict): |
| 480 | for candidate in (document.get("url"), document.get("doc_url"), document.get("link")): |
| 481 | valid = _valid_url(candidate) |
| 482 | if valid: |
| 483 | return valid |
| 484 | |
| 485 | return None |
| 486 | |
| 487 | |
| 488 | def extract_doc_token(doc_info: Dict[str, Any]) -> Optional[str]: |
no test coverage detected