fix: webtorrent 在 Vercel 的报错改为真实原因 + 路由显式 nodejs 运行时

This commit is contained in:
ice-a
2026-10-16 19:22:23 +08:00
parent 2c781164f0
commit 52dfa409eb
2 changed files with 4 additions and 1 deletions
@@ -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)) {
+1 -1
View File
@@ -170,7 +170,7 @@ export async function loadWebTorrent(): Promise<any> {
webTorrentMod = mod?.default || mod
return webTorrentMod
} catch {
throw new Error('未安装 webtorrent 依赖,无法通过磁力链在线获取文件清单(仅能显示 infoHash)')
throw new Error('无法在当前运行环境加载 webtorrent(需要支持 UDP 的 Node 运行时;Vercel / 其他 Serverless 通常不可用),仅能显示 infoHash')
}
}