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') } }