diff --git a/backend/app/clash_assets/clash.yaml b/backend/app/clash_assets/clash.yaml new file mode 100644 index 0000000..ed51fd3 --- /dev/null +++ b/backend/app/clash_assets/clash.yaml @@ -0,0 +1,396 @@ +port: 7890 +socks-port: 7891 +allow-lan: false +mode: rule +log-level: info +geodata-mode: true +geo-auto-update: true +geodata-loader: standard +geo-update-interval: 24 +geox-url: + geoip: https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat + geosite: >- + https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat + mmdb: >- + https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/country.mmdb + asn: >- + https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb +rule-providers: + geolocation-cn: + type: http + format: mrs + behavior: domain + url: >- + https://gh.sageer.me/https://github.com/MetaCubeX/meta-rules-dat/raw/refs/heads/meta/geo/geosite/geolocation-cn.mrs + path: ./ruleset/geolocation-cn.mrs + interval: 86400 + geolocation-!cn: + type: http + format: mrs + behavior: domain + url: >- + https://gh.sageer.me/https://github.com/MetaCubeX/meta-rules-dat/raw/refs/heads/meta/geo/geosite/geolocation-!cn.mrs + path: ./ruleset/geolocation-!cn.mrs + interval: 86400 + private: + type: http + format: mrs + behavior: ipcidr + url: >- + https://gh.sageer.me/https://github.com/MetaCubeX/meta-rules-dat/raw/refs/heads/meta/geo/geoip/private.mrs + path: ./ruleset/private.mrs + interval: 86400 + cn: + type: http + format: mrs + behavior: domain + url: >- + https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/cn.yaml + path: ./ruleset/cn.mrs + interval: 86400 +dns: + enable: true + ipv6: false + respect-rules: true + enhanced-mode: fake-ip + nameserver: + - https://120.53.53.53/dns-query + - https://223.5.5.5/dns-query + proxy-server-nameserver: + - https://120.53.53.53/dns-query + - https://223.5.5.5/dns-query + nameserver-policy: + geosite:cn,private: + - https://120.53.53.53/dns-query + - https://223.5.5.5/dns-query + geosite:geolocation-!cn: + - https://dns.cloudflare.com/dns-query + - https://dns.google/dns-query +proxies: + # 落地代理 + - name: proxycheap + # 前置代理 + dialer-proxy: dialer + type: socks5 + server: 45.134.95.113 + port: 46415 + username: n1YshpjaUaFG4Us + password: ugEbEVuC3pFwuUI + + - name: socks5 + type: socks5 + server: 45.134.95.113 + port: 46415 + username: n1YshpjaUaFG4Us + password: ugEbEVuC3pFwuUI + + - name: "242af835-singbox_hysteria" + type: hysteria2 + server: 107.173.7.226 + port: 34814 + ports: 30000-31000 + password: 1f28cd23-d223-4eaa-a786-4a010d674cbc + sni: hy2.nomadro.com + skip-cert-verify: true + alpn: + - h3 + up: "1000 Mbps" + down: "1000 Mbps" + + - name: hackrobot-singbox_tuic + type: tuic + server: 107.173.7.226 + port: 33935 + ports: 32000-40000 + uuid: 1f28cd23-d223-4eaa-a786-4a010d674cbc + password: 1f28cd23-d223-4eaa-a786-4a010d674cbc + alpn: + - h3 + udp-relay-mode: native + congestion-controller: bbr + disable-sni: false + reduce-rtt: true + request-timeout: 8000 + heartbeat-interval: 10000 + tls: true + sni: hy2.nomadro.com + skip-cert-verify: true + fast-open: true + max-open-streams: 20 + max-udp-relay-packet-size: 1500 + udp: true + + - name: "VLESS_Reality_Vision" + type: vless + server: 107.173.7.226 + port: 21730 + uuid: 1f28cd23-d223-4eaa-a786-4a010d674cbc + flow: xtls-rprx-vision + encryption: none + network: tcp + tls: true + servername: hy2.nomadro.com + alpn: + - h2 + - http/1.1 + client-fingerprint: chrome + skip-cert-verify: true + reality-opts: + public-key: ppipIkuEvHMBaMMg42C1lsRX_igSZPlDDZDBVY1UdzM + short-id: 6ba85179e30d4fc2 + server-names: + - hy2.nomadro.com + flow: xtls-rprx-vision + smux: + enabled: false + + - name: "242af835-singbox_hysteria2" + type: hysteria2 + server: 23.94.99.206 + port: 32941 + ports: 30000-31000 + password: fda6eb84-7b47-473f-abcb-82a5addece55 + sni: web3.nomadro.com + skip-cert-verify: true + alpn: + - h3 + up: "1000 Mbps" + down: "1000 Mbps" + + - name: hackrobot-singbox_tuic2 + type: tuic + server: 23.94.99.206 + port: 10831 + ports: 32000-33000 + uuid: fda6eb84-7b47-473f-abcb-82a5addece55 + password: fda6eb84-7b47-473f-abcb-82a5addece55 + alpn: + - h3 + udp-relay-mode: native + congestion-controller: bbr + disable-sni: false + reduce-rtt: true + request-timeout: 8000 + heartbeat-interval: 10000 + tls: true + sni: web3.nomadro.com + skip-cert-verify: true + fast-open: true + max-open-streams: 20 + max-udp-relay-packet-size: 1500 + udp: true + + - name: "VLESS_Reality_Vision2" + type: vless + server: 23.94.99.206 + port: 35925 + uuid: fda6eb84-7b47-473f-abcb-82a5addece55 + flow: xtls-rprx-vision + encryption: none + network: tcp + tls: true + servername: web3.nomadro.com + alpn: + - h2 + - http/1.1 + client-fingerprint: chrome + skip-cert-verify: true + reality-opts: + public-key: JhJEy3-xC5sux3iBJ1Ryc8jO5F6CKsZsQjzG0BSN_g0 + short-id: 6ba85179e30d4fc2 + server-names: + - web3.nomadro.com + flow: xtls-rprx-vision + smux: + enabled: false + + - name: 1d2da142-singbox_hysteria5 + type: hysteria2 + server: specials.nomadro.live + port: 21825 + ports: 30000-31000 + password: ebf95e6f-4d90-459b-a353-8e5075bd8bd3 + sni: specials.nomadro.live + skip-cert-verify: false + alpn: + - h3 + up: "100 Mbps" + down: "1000 Mbps" + + - name: 1d2da142-VLESS_Reality_Vision5 + type: vless + server: 107.173.30.245 + port: 22785 + uuid: ebf95e6f-4d90-459b-a353-8e5075bd8bd3 + encryption: none + network: tcp + tls: true + flow: xtls-rprx-vision + servername: d1.awsstatic.com + client-fingerprint: chrome + skip-cert-verify: false + reality-opts: + public-key: AU9uNmxIqypg_K8TxesJPDxWUSSJLhN6xySIGTuhL0I + short-id: 6ba85179e30d4fc2 + server-name: d1.awsstatic.com + alpn: + - h2 + - http/1.1 + smux: + enabled: false + + - name: 1d2da142-singbox_tuic5 + type: tuic + server: specials.nomadro.live + port: 16113 + ports: 32000-33000 + uuid: ebf95e6f-4d90-459b-a353-8e5075bd8bd3 + password: ebf95e6f-4d90-459b-a353-8e5075bd8bd3 + alpn: + - h3 + udp-relay-mode: native + congestion-controller: bbr + disable-sni: false + reduce-rtt: true + request-timeout: 8000 + heartbeat-interval: 10000 + skip-cert-verify: false + udp: true + + - name: e3ea3b30-singbox_hysteria_vultr + type: hysteria2 + server: vultr.nomadro.live + port: 35297 + ports: 30000-31000 + password: e3ea3b30-6cc6-447a-a820-ea06d48a9735 + sni: vultr.nomadro.live + skip-cert-verify: false + alpn: + - h3 + up: "100 Mbps" + down: "1000 Mbps" + + - name: e3ea3b30-VLESS_Reality_Vision_vultr + type: vless + server: 45.32.89.58 + port: 37664 + uuid: e3ea3b30-6cc6-447a-a820-ea06d48a9735 + encryption: none + network: tcp + tls: true + flow: xtls-rprx-vision + servername: academy.nvidia.com + client-fingerprint: chrome + skip-cert-verify: false + reality-opts: + public-key: meUnIscdA43p_JzUwzgBXVSFvACCjYzzd0LT9AZbaDk + short-id: 6ba85179e30d4fc2 + server-name: academy.nvidia.com + alpn: + - h2 + - http/1.1 + smux: + enabled: false + + - name: e3ea3b30-singbox_tuic_vultr + type: tuic + server: vultr.nomadro.live + port: 26032 + uuid: e3ea3b30-6cc6-447a-a820-ea06d48a9735 + password: e3ea3b30-6cc6-447a-a820-ea06d48a9735 + alpn: + - h3 + udp-relay-mode: native + congestion-controller: bbr + disable-sni: false + reduce-rtt: true + request-timeout: 8000 + heartbeat-interval: 10000 + skip-cert-verify: false + udp: true + +proxy-groups: + - type: select + name: 🚀 节点选择 + proxies: + - DIRECT + - REJECT + - ⚡ 自动选择 + - proxycheap + - 242af835-singbox_hysteria + - hackrobot-singbox_tuic + - VLESS_Reality_Vision + - 242af835-singbox_hysteria2 + - hackrobot-singbox_tuic2 + - VLESS_Reality_Vision2 + - 1d2da142-singbox_hysteria5 + - 1d2da142-VLESS_Reality_Vision5 + - 1d2da142-singbox_tuic5 + - e3ea3b30-singbox_hysteria_vultr + - e3ea3b30-VLESS_Reality_Vision_vultr + - e3ea3b30-singbox_tuic_vultr + - name: dialer + type: select + proxies: + - 242af835-singbox_hysteria + - hackrobot-singbox_tuic + - VLESS_Reality_Vision + - 242af835-singbox_hysteria2 + - hackrobot-singbox_tuic2 + - VLESS_Reality_Vision2 + - 1d2da142-singbox_hysteria5 + - 1d2da142-VLESS_Reality_Vision5 + - 1d2da142-singbox_tuic5 + - e3ea3b30-singbox_hysteria_vultr + - e3ea3b30-VLESS_Reality_Vision_vultr + - e3ea3b30-singbox_tuic_vultr + - name: ⚡ 自动选择 + type: url-test + proxies: + - 1d2da142-singbox_tuic5 + - 1d2da142-singbox_hysteria5 + - 1d2da142-VLESS_Reality_Vision5 + - e3ea3b30-singbox_hysteria_vultr + - e3ea3b30-VLESS_Reality_Vision_vultr + - e3ea3b30-singbox_tuic_vultr + url: https://www.gstatic.com/generate_204 + interval: 300 + lazy: false + - type: select + name: 🏠 私有网络 + proxies: + - 🚀 节点选择 + - DIRECT + - REJECT + - ⚡ 自动选择 + - 242af835-singbox_hysteria2 + - type: select + name: 🔒 国内服务 + proxies: + - 🚀 节点选择 + - DIRECT + - REJECT + - ⚡ 自动选择 + - 242af835-singbox_hysteria2 + - type: select + name: 🌐 非中国 + proxies: + - 🚀 节点选择 + - DIRECT + - REJECT + - ⚡ 自动选择 + - 242af835-singbox_hysteria2 + - type: select + name: 🐟 漏网之鱼 + proxies: + - 🚀 节点选择 + - DIRECT + - REJECT + - ⚡ 自动选择 + - 242af835-singbox_hysteria2 +rules: + - RULE-SET,geolocation-cn,🔒 国内服务 + - RULE-SET,geolocation-!cn,🌐 非中国 + - RULE-SET,private,🏠 私有网络,no-resolve + - RULE-SET,cn,🔒 国内服务,no-resolve + - MATCH,🐟 漏网之鱼 diff --git a/backend/app/clash_dl.py b/backend/app/clash_dl.py new file mode 100644 index 0000000..a7061af --- /dev/null +++ b/backend/app/clash_dl.py @@ -0,0 +1,249 @@ +# -*- coding: utf-8 -*- +"""Clash Verge Rev installer + clash.yaml hosted on S3.""" +from __future__ import annotations + +import json +import re +import tempfile +import time +from pathlib import Path +from typing import Any + +import httpx + +from . import s3_storage +from .config import settings + +CLASH_VERGE_KEY = "downloads/clash/Clash.Verge_x64-setup.exe" +CLASH_VERGE_META_KEY = "downloads/clash/Clash.Verge_x64-setup.json" +CLASH_YAML_KEY = "downloads/clash/clash.yaml" +CLASH_SOURCE_REPO = "clash-verge-rev/clash-verge-rev" + +ASSETS_DIR = Path(__file__).resolve().parent / "clash_assets" +LOCAL_YAML = ASSETS_DIR / "clash.yaml" + + +def _fmt_size(n: int) -> str: + if n <= 0: + return "—" + units = ["B", "KB", "MB", "GB"] + v = float(n) + for u in units: + if v < 1024 or u == units[-1]: + return f"{v:.0f} {u}" if u == "B" else f"{v:.1f} {u}" + v /= 1024.0 + return f"{n} B" + + +def _item( + *, + id: str, + title: str, + kind: str, + key: str, + filename: str, + description: str = "", + version: str = "", + install_hint: str = "", +) -> dict[str, Any]: + head = s3_storage.head_object(key) if s3_storage.s3_enabled() else None + available = bool(head and head.get("size", 0) > 0) + url = (head or {}).get("url") or (s3_storage.public_url_for_key(key) if s3_storage.s3_enabled() else "") + size = int((head or {}).get("size") or 0) + updated = float((head or {}).get("last_modified") or 0) + return { + "id": id, + "title": title, + "kind": kind, + "key": key, + "filename": filename, + "description": description, + "version": version, + "install_hint": install_hint, + "url": url, + "size": size, + "size_label": _fmt_size(size), + "updated_at": updated, + "available": available, + "etag": (head or {}).get("etag") or "", + } + + +def _read_meta() -> dict[str, Any]: + if not s3_storage.s3_enabled(): + return {} + try: + client = s3_storage._client() # noqa: SLF001 + obj = client.get_object(Bucket=settings.s3_bucket, Key=CLASH_VERGE_META_KEY) + return json.loads(obj["Body"].read().decode("utf-8")) + except Exception: + return {} + + +def _github_latest_x64_setup() -> dict[str, Any]: + api = f"https://api.github.com/repos/{CLASH_SOURCE_REPO}/releases/latest" + headers = { + "Accept": "application/vnd.github+json", + "User-Agent": "douyinWEB-clash-sync", + } + with httpx.Client(timeout=60.0, follow_redirects=True, trust_env=False, headers=headers) as client: + resp = client.get(api) + resp.raise_for_status() + data = resp.json() + tag = str(data.get("tag_name") or "").strip() + assets = data.get("assets") or [] + # Prefer standard x64-setup.exe (not fixed_webview2 which is huge) + preferred = None + for a in assets: + name = str(a.get("name") or "") + if re.search(r"x64-setup\.exe$", name, re.I) and "fixed_webview2" not in name.lower(): + preferred = a + break + if not preferred: + for a in assets: + name = str(a.get("name") or "") + if "x64" in name.lower() and name.lower().endswith(".exe") and "sig" not in name.lower(): + preferred = a + break + if not preferred: + raise ValueError("GitHub release 中未找到 Windows x64 setup.exe") + url = str(preferred.get("browser_download_url") or "").strip() + if not url: + raise ValueError("缺少 browser_download_url") + return { + "tag": tag, + "name": str(preferred.get("name") or ""), + "url": url, + "size": int(preferred.get("size") or 0), + } + + +def catalog() -> dict[str, Any]: + meta = _read_meta() + ver = str(meta.get("version") or meta.get("tag") or "") + items = [ + _item( + id="clash-verge-win64", + title="Clash Verge Rev(Windows x64 安装包)", + kind="installer", + key=CLASH_VERGE_KEY, + filename="Clash.Verge_x64-setup.exe", + description="来自 GitHub clash-verge-rev 正式版 x64-setup,托管到本站 S3。", + version=ver, + install_hint="下载后双击安装 → 打开 Clash Verge → 配置文件 → 导入下方 clash.yaml。", + ), + _item( + id="clash-yaml", + title="clash.yaml 配置文件", + kind="config", + key=CLASH_YAML_KEY, + filename="clash.yaml", + description="本站维护的 mihomo/Clash Meta 规则配置(含节点与分流)。", + version="", + install_hint="下载后在 Clash Verge 中「导入」或放入配置目录后启用。", + ), + ] + return { + "s3_enabled": s3_storage.s3_enabled(), + "public_base": (settings.s3_public_base or settings.s3_endpoint or "").rstrip("/"), + "bucket": settings.s3_bucket, + "source_repo": f"https://github.com/{CLASH_SOURCE_REPO}", + "items": items, + "meta": meta, + } + + +def publish_clash_yaml() -> dict[str, Any]: + if not s3_storage.s3_enabled(): + raise ValueError("S3 未启用") + if not LOCAL_YAML.is_file(): + raise ValueError(f"本地配置不存在: {LOCAL_YAML}") + data = LOCAL_YAML.read_bytes() + if not data.strip(): + raise ValueError("clash.yaml 为空") + url = s3_storage.upload_bytes(data, CLASH_YAML_KEY, content_type="text/yaml; charset=utf-8") + if not url: + raise ValueError("上传 clash.yaml 失败") + return {"ok": True, "url": url, "key": CLASH_YAML_KEY, "size": len(data)} + + +def sync_clash_verge_installer(*, force: bool = False) -> dict[str, Any]: + """Fetch latest Clash Verge Rev Windows x64 setup from GitHub → S3.""" + if not s3_storage.s3_enabled(): + raise ValueError("S3 未启用") + release = _github_latest_x64_setup() + tag = str(release.get("tag") or "") + existing = s3_storage.head_object(CLASH_VERGE_KEY) + meta = _read_meta() + if ( + existing + and int(existing.get("size") or 0) > 5_000_000 + and not force + and str(meta.get("tag") or "") == tag + ): + return { + "ok": True, + "skipped": True, + "reason": "already_present", + "tag": tag, + "url": existing.get("url"), + "size": existing.get("size"), + } + + src = str(release["url"]) + with tempfile.NamedTemporaryFile(suffix=".exe", delete=False) as tmp: + tmp_path = Path(tmp.name) + try: + headers = {"User-Agent": "douyinWEB-clash-sync", "Accept": "application/octet-stream"} + with httpx.Client(timeout=600.0, follow_redirects=True, trust_env=False, headers=headers) as client: + with client.stream("GET", src) as resp: + resp.raise_for_status() + with tmp_path.open("wb") as f: + for chunk in resp.iter_bytes(1024 * 256): + f.write(chunk) + size = tmp_path.stat().st_size + if size < 5_000_000: + raise ValueError(f"安装包异常过小({size} bytes)") + url = s3_storage.upload_file( + tmp_path, + CLASH_VERGE_KEY, + content_type="application/vnd.microsoft.portable-executable", + ) + if not url: + raise ValueError("上传 S3 失败") + meta_body = { + "tag": tag, + "version": tag.lstrip("v"), + "source_name": release.get("name"), + "source_url": src, + "size": size, + "synced_at": time.time(), + "key": CLASH_VERGE_KEY, + "url": url, + } + s3_storage.upload_bytes( + json.dumps(meta_body, ensure_ascii=False, indent=2).encode("utf-8"), + CLASH_VERGE_META_KEY, + content_type="application/json", + ) + yaml_res = publish_clash_yaml() + return { + "ok": True, + "skipped": False, + "tag": tag, + "url": url, + "size": size, + "key": CLASH_VERGE_KEY, + "yaml": yaml_res, + } + finally: + try: + tmp_path.unlink(missing_ok=True) + except Exception: + pass + + +def local_yaml_text() -> str: + if not LOCAL_YAML.is_file(): + raise FileNotFoundError("clash.yaml 不存在") + return LOCAL_YAML.read_text(encoding="utf-8") diff --git a/backend/app/main.py b/backend/app/main.py index 681b59f..509bea1 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -21,7 +21,7 @@ if sys.platform == "win32": from fastapi import FastAPI, HTTPException, Query, Request, WebSocket, WebSocketDisconnect from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, StreamingResponse +from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, Response, StreamingResponse from fastapi.staticfiles import StaticFiles import httpx @@ -2436,6 +2436,58 @@ async def downloads_catalog() -> dict[str, Any]: return await _db(downloads_mod.catalog) +@app.get("/api/clash") +async def clash_catalog() -> dict[str, Any]: + from . import clash_dl + + return await _db(clash_dl.catalog) + + +@app.post("/api/clash/sync") +async def clash_sync(force: bool = Query(False)) -> dict[str, Any]: + """Pull latest Clash Verge Rev Win x64 from GitHub and publish clash.yaml to S3.""" + from . import clash_dl + + try: + installer = await asyncio.to_thread(clash_dl.sync_clash_verge_installer, force=force) + if installer.get("skipped"): + yaml_res = await asyncio.to_thread(clash_dl.publish_clash_yaml) + installer = {**installer, "yaml": yaml_res} + return installer + except ValueError as exc: + raise HTTPException(400, str(exc)) from exc + except Exception as exc: + raise HTTPException(500, f"同步失败: {exc}") from exc + + +@app.post("/api/clash/publish-yaml") +async def clash_publish_yaml() -> dict[str, Any]: + from . import clash_dl + + try: + return await asyncio.to_thread(clash_dl.publish_clash_yaml) + except ValueError as exc: + raise HTTPException(400, str(exc)) from exc + except Exception as exc: + raise HTTPException(500, f"上传失败: {exc}") from exc + + +@app.get("/api/clash/config.yaml") +async def clash_config_yaml() -> Response: + """Serve local clash.yaml for browser download (also mirrored on S3).""" + from . import clash_dl + + try: + text = await asyncio.to_thread(clash_dl.local_yaml_text) + except FileNotFoundError as exc: + raise HTTPException(404, str(exc)) from exc + return Response( + content=text, + media_type="text/yaml; charset=utf-8", + headers={"Content-Disposition": 'attachment; filename="clash.yaml"'}, + ) + + @app.post("/api/downloads/sync-chrome") async def downloads_sync_chrome(force: bool = Query(False)) -> dict[str, Any]: from . import downloads as downloads_mod diff --git a/frontend/src/app/clash/page.tsx b/frontend/src/app/clash/page.tsx new file mode 100644 index 0000000..f1125cd --- /dev/null +++ b/frontend/src/app/clash/page.tsx @@ -0,0 +1,224 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import { Download, ExternalLink, FileCode2, Loader2, RefreshCw } from "lucide-react"; + +import { Shell } from "@/components/Shell"; +import { useToast } from "@/components/Toast"; +import { fetchJson, fmtTs } from "@/lib/api"; + +type Item = { + id: string; + title: string; + kind: string; + filename: string; + description?: string; + version?: string; + install_hint?: string; + url: string; + size: number; + size_label?: string; + updated_at?: number; + available?: boolean; +}; + +type Catalog = { + s3_enabled?: boolean; + public_base?: string; + source_repo?: string; + items?: Item[]; + meta?: { tag?: string; version?: string; synced_at?: number }; +}; + +export default function ClashPage() { + const toast = useToast(); + const [data, setData] = useState(null); + const [loading, setLoading] = useState(true); + const [busy, setBusy] = useState(""); + + const load = useCallback(async () => { + setLoading(true); + try { + const r = await fetchJson("/api/clash"); + setData(r); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setLoading(false); + } + }, [toast]); + + useEffect(() => { + void load(); + }, [load]); + + async function syncAll(force = false) { + setBusy(force ? "force" : "sync"); + try { + const r = await fetchJson(`/api/clash/sync?force=${force ? "true" : "false"}`, { method: "POST" }); + if (r?.skipped) toast.push(`安装包已是最新 ${r.tag || ""},已刷新 yaml`, "ok"); + else toast.push(`已同步 Clash Verge ${r.tag || ""} 到 S3`, "ok"); + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + async function publishYaml() { + setBusy("yaml"); + try { + await fetchJson("/api/clash/publish-yaml", { method: "POST" }); + toast.push("clash.yaml 已上传到 S3", "ok"); + await load(); + } catch (e) { + toast.push((e as Error).message, "err"); + } finally { + setBusy(""); + } + } + + const installer = data?.items?.find((i) => i.id === "clash-verge-win64"); + const yaml = data?.items?.find((i) => i.id === "clash-yaml"); + + return ( + +
+
+
+
+
Clash
+

Clash Verge Rev 下载

+

+ Windows x64 安装包托管在本站 S3;配置文件一键下载导入。来源: + + clash-verge-rev + + +

+
+
+ + +
+
+
+ + {loading && !data ? ( +
+ 加载中… +
+ ) : ( +
+
+
+
+

{installer?.title || "Clash Verge Rev"}

+

{installer?.description}

+
+ {installer?.version ? v{installer.version} : null} + {installer?.size_label || "—"} + {installer?.updated_at ? 更新 {fmtTs(installer.updated_at)} : null} + {installer?.available ? "S3 可用" : "尚未上传"} +
+ {installer?.install_hint ? ( +

{installer.install_hint}

+ ) : null} +
+ + + 下载安装包 + +
+
+ +
+
+
+

+ + {yaml?.title || "clash.yaml"} +

+

{yaml?.description}

+
+ {yaml?.size_label || "—"} + {yaml?.updated_at ? 更新 {fmtTs(yaml.updated_at)} : null} + {yaml?.available ? "S3 可用" : "尚未上传"} +
+ {yaml?.install_hint ? ( +

{yaml.install_hint}

+ ) : null} +
+
+ + + + 下载 clash.yaml + + {yaml?.available ? ( + + S3 直链 + + ) : null} +
+
+
+ +
+ 安装步骤:1)下载并安装 Clash Verge Rev → 2)下载 clash.yaml 并导入 → 3)开启系统代理 / TUN(按需)。 + 节点与规则以配置文件为准。 +
+
+ )} +
+
+ ); +} diff --git a/frontend/src/components/Shell.tsx b/frontend/src/components/Shell.tsx index d64900b..37564d6 100644 --- a/frontend/src/components/Shell.tsx +++ b/frontend/src/components/Shell.tsx @@ -29,6 +29,7 @@ const NAV = [ { href: "/shorts", label: "Shorts", emoji: "📱" }, { href: "/tiktok", label: "TikTok", emoji: "🎵" }, { href: "/x", label: "X", emoji: "𝕏" }, + { href: "/clash", label: "Clash", emoji: "🧿" }, { href: "/downloads", label: "下载", emoji: "⬇️" }, { href: "/blacklist", label: "黑名单", emoji: "🚫" }, { href: "/settings", label: "设置", emoji: "⚙️" }, diff --git a/scripts/_publish_clash.py b/scripts/_publish_clash.py new file mode 100644 index 0000000..b4fcb26 --- /dev/null +++ b/scripts/_publish_clash.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +"""Publish Clash Verge + clash.yaml to S3. Run on server with S3 env.""" +from __future__ import annotations + +import os +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "backend")) +os.chdir(ROOT / "backend") + + +def main() -> int: + from app import clash_dl + + force = "--force" in sys.argv + print("sync installer force=", force) + r = clash_dl.sync_clash_verge_installer(force=force) + print(r) + if r.get("skipped"): + y = clash_dl.publish_clash_yaml() + print("yaml", y) + print("catalog", clash_dl.catalog()) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())