Commit 8d53fc7

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-08-07 04:53:54
fix(wget): send original html file instead of markdown
1 parent 64919df
Changed files (3)
src/others/download_external.py
@@ -6,7 +6,7 @@ from loguru import logger
 from pyrogram.client import Client
 from pyrogram.types import Message
 
-from config import MAX_FILE_BYTES, PREFIX
+from config import MAX_FILE_BYTES, PREFIX, PROXY
 from llm.utils import convert_md
 from messages.parser import parse_msg
 from messages.progress import modify_progress
@@ -57,10 +57,10 @@ async def download_url_in_message(client: Client, message: Message, extra_prefix
     success = False
     path = Path("non-exist")
     try:
-        path = await download_file(url, workers_proxy=True, **kwargs)
+        path = await download_file(url, proxy=PROXY.DOWNLOAD, **kwargs)
         path = Path(path)
         suffix = path.suffix
-        if (mime := guess_mime(path)) and mime != "text/plain":
+        if (mime := guess_mime(path)) and not mime.startswith("text"):
             suffix = "." + mime.split("/")[-1]
         if path.suffix != suffix:
             path.rename(path.with_suffix(suffix))
@@ -82,9 +82,7 @@ async def download_url_in_message(client: Client, message: Message, extra_prefix
                 markdown_path.write_text(markdown)
                 if telegraph_url := await publish_telegraph(title="全文内容", texts=markdown, author=info["full_name"], url=url):
                     caption += f"\n⚡️[即时预览]({telegraph_url})"
-                success = await client.send_document(target_chat, markdown_path.as_posix(), caption=caption, reply_parameters=reply_parameters)
-            else:
-                success = await client.send_document(target_chat, path.as_posix(), caption=caption, reply_parameters=reply_parameters)
+            success = await client.send_document(target_chat, path.as_posix(), caption=caption, reply_parameters=reply_parameters)
         else:
             await modify_progress(text=f"❌文件大小: {readable_size(path=path)} 超出限制\nTelegram只允许上传小于{round(MAX_FILE_BYTES / 1024 / 1024)}MB的文件", force_update=True, **kwargs)
     except Exception as e:
src/config.py
@@ -162,7 +162,6 @@ class TOKEN:
 
 class PROXY:  # format: socks5://127.0.0.1:7890
     TELEGRAM = os.getenv("TELEGRAM_PROXY", None)  # Telegram
-    WORKERS = os.getenv("WORKERS_PROXY", "")  # https://github.com/netnr/workers
     IMG = os.getenv("IMG_PROXY", "")  # https://caravaggio.ramielcreations.com/docs/install
     XHS = os.getenv("XHS_PROXY", None)  # Banned VPS IP, need residential proxy
     GPT = os.getenv("GPT_PROXY", None)
src/networking.py
@@ -7,7 +7,7 @@ import json
 import re
 from pathlib import Path
 from typing import Any
-from urllib.parse import parse_qs, quote_plus, urlparse
+from urllib.parse import parse_qs, urlparse
 
 import anyio
 from httpx import AsyncClient, AsyncHTTPTransport, HTTPStatusError, Request, RequestError, Response
@@ -131,7 +131,6 @@ async def download_file(
     suffix: str = "",
     skip_exist: bool = False,
     proxy: str | None = None,
-    workers_proxy: bool = False,
     headers: dict | None = None,
     stream: bool = False,
     **kwargs,
@@ -144,7 +143,6 @@ async def download_file(
         suffix (str, optional): The suffix to append to the file name. Defaults to auto detect.
         skip_exist (bool, optional): Skip downloading if the file already exists. Defaults to False.
         proxy (str, optional): The proxy to use for the request.
-        workers_proxy (bool, optional): Use workers proxy. Defaults to False.
         headers (dict, optional): The headers to use for the request.
         stream (bool, optional): Stream the download. Defaults to False.
 
@@ -162,8 +160,6 @@ async def download_file(
     if path.is_file() and skip_exist:
         logger.info(f"File already exists, skipping download: {path}")
         return path.as_posix()
-    if workers_proxy and PROXY.WORKERS:
-        link = PROXY.WORKERS + quote_plus(link)
     path.parent.mkdir(parents=True, exist_ok=True)
     proxy = proxy or PROXY.DOWNLOAD
     logger.trace(f"Downloading {link} to {path} with proxy={proxy}")