Parse the text of a single ``.lnk`` file. Mirrors the C++ ``fl::parse_lnk_with_metadata()`` logic in ``src/fl/stl/url.h``: - Comment lines (``#...``) and blank lines are skipped. - First non-comment line is the primary URL. - Subsequent ``key=value`` lines are recorded as metad
(content: str)
| 84 | |
| 85 | |
| 86 | def _parse_lnk_content(content: str) -> AssetEntry | None: |
| 87 | """Parse the text of a single ``.lnk`` file. |
| 88 | |
| 89 | Mirrors the C++ ``fl::parse_lnk_with_metadata()`` logic in |
| 90 | ``src/fl/stl/url.h``: |
| 91 | |
| 92 | - Comment lines (``#...``) and blank lines are skipped. |
| 93 | - First non-comment line is the primary URL. |
| 94 | - Subsequent ``key=value`` lines are recorded as metadata. Recognized |
| 95 | keys: ``sha256``, ``fallback``. Unknown keys are silently ignored. |
| 96 | |
| 97 | Returns ``None`` if no URL was found. |
| 98 | """ |
| 99 | primary_url: str | None = None |
| 100 | sha256: str | None = None |
| 101 | fallback: str | None = None |
| 102 | |
| 103 | for raw_line in content.splitlines(): |
| 104 | line = raw_line.strip() |
| 105 | if not line or line.startswith("#"): |
| 106 | continue |
| 107 | |
| 108 | if primary_url is None: |
| 109 | primary_url = line |
| 110 | continue |
| 111 | |
| 112 | if "=" not in line: |
| 113 | # Unknown non-kv line — forward-compat, ignore. |
| 114 | continue |
| 115 | |
| 116 | key, _, value = line.partition("=") |
| 117 | key = key.strip() |
| 118 | value = value.strip() |
| 119 | if key == "sha256": |
| 120 | sha256 = value |
| 121 | elif key == "fallback": |
| 122 | fallback = value |
| 123 | # else: unknown metadata key, ignore. |
| 124 | |
| 125 | if primary_url is None: |
| 126 | return None |
| 127 | |
| 128 | return AssetEntry(url=primary_url, sha256=sha256, fallback=fallback) |
| 129 | |
| 130 | |
| 131 | # ----------------------------------------------------------------------------- |