From 52dfa409ebe0b9ff2467b08c130b60e5cd9950c1 Mon Sep 17 00:00:00 2001 From: ice-a Date: Fri, 16 Oct 2026 19:22:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20webtorrent=20=E5=9C=A8=20Vercel=20?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99=E6=94=B9=E4=B8=BA=E7=9C=9F=E5=AE=9E?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=20+=20=E8=B7=AF=E7=94=B1=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=20nodejs=20=E8=BF=90=E8=A1=8C=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/torrent/[infohash]/resolve.post.ts | 3 +++ server/utils/torrent.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/api/torrent/[infohash]/resolve.post.ts b/server/api/torrent/[infohash]/resolve.post.ts index d09b421..a1d30b6 100644 --- a/server/api/torrent/[infohash]/resolve.post.ts +++ b/server/api/torrent/[infohash]/resolve.post.ts @@ -3,6 +3,9 @@ import { tryMongo } from '../../../utils/mongo' import { getTorrent, markResolved } from '../../../utils/store' import { fetchMetadataFromMagnet } from '../../../utils/torrent' +// webtorrent 依赖 Node 运行时(需要 dgram / 原生模块),必须显式跑在 nodejs 而非 edge +export const runtime = 'nodejs' + export default defineEventHandler(async (event) => { const infoHash = String(getRouterParam(event, 'infohash') || '').toLowerCase() if (!/^[a-f0-9]{40}$/.test(infoHash)) { diff --git a/server/utils/torrent.ts b/server/utils/torrent.ts index de32f25..7331699 100644 --- a/server/utils/torrent.ts +++ b/server/utils/torrent.ts @@ -170,7 +170,7 @@ export async function loadWebTorrent(): Promise { webTorrentMod = mod?.default || mod return webTorrentMod } catch { - throw new Error('未安装 webtorrent 依赖,无法通过磁力链在线获取文件清单(仅能显示 infoHash)') + throw new Error('无法在当前运行环境加载 webtorrent(需要支持 UDP 的 Node 运行时;Vercel / 其他 Serverless 通常不可用),仅能显示 infoHash') } }