整理缓存错误,避免将底层命令异常直接暴露给用户。
(self, error: Exception)
| 262 | return f"{url_hash}{ext}" |
| 263 | |
| 264 | def _normalize_cache_error(self, error: Exception) -> str: |
| 265 | """整理缓存错误,避免将底层命令异常直接暴露给用户。""" |
| 266 | if isinstance(error, FileNotFoundError): |
| 267 | missing_name = Path(getattr(error, "filename", "") or "curl").name or "curl" |
| 268 | return f"本机未安装 {missing_name}" |
| 269 | |
| 270 | message = str(error or "").strip() |
| 271 | if not message: |
| 272 | return "未知错误" |
| 273 | |
| 274 | if message.startswith("Failed to cache file:"): |
| 275 | message = message.split(":", 1)[1].strip() or "未知错误" |
| 276 | |
| 277 | return message |
| 278 | |
| 279 | async def download_and_cache(self, url: str, media_type: str) -> str: |
| 280 | """ |