fix: webtorrent 在 Vercel 的报错改为真实原因 + 路由显式 nodejs 运行时
This commit is contained in:
@@ -3,6 +3,9 @@ import { tryMongo } from '../../../utils/mongo'
|
|||||||
import { getTorrent, markResolved } from '../../../utils/store'
|
import { getTorrent, markResolved } from '../../../utils/store'
|
||||||
import { fetchMetadataFromMagnet } from '../../../utils/torrent'
|
import { fetchMetadataFromMagnet } from '../../../utils/torrent'
|
||||||
|
|
||||||
|
// webtorrent 依赖 Node 运行时(需要 dgram / 原生模块),必须显式跑在 nodejs 而非 edge
|
||||||
|
export const runtime = 'nodejs'
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const infoHash = String(getRouterParam(event, 'infohash') || '').toLowerCase()
|
const infoHash = String(getRouterParam(event, 'infohash') || '').toLowerCase()
|
||||||
if (!/^[a-f0-9]{40}$/.test(infoHash)) {
|
if (!/^[a-f0-9]{40}$/.test(infoHash)) {
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ export async function loadWebTorrent(): Promise<any> {
|
|||||||
webTorrentMod = mod?.default || mod
|
webTorrentMod = mod?.default || mod
|
||||||
return webTorrentMod
|
return webTorrentMod
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error('未安装 webtorrent 依赖,无法通过磁力链在线获取文件清单(仅能显示 infoHash)')
|
throw new Error('无法在当前运行环境加载 webtorrent(需要支持 UDP 的 Node 运行时;Vercel / 其他 Serverless 通常不可用),仅能显示 infoHash')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user