fetch 是祖宗之法

This commit is contained in:
🌌 2024-10-30 00:00:11 +08:00
parent e37b545aff
commit 4286c6c0aa
2 changed files with 7 additions and 12 deletions

View File

@ -2,8 +2,8 @@ import { Common } from '#miao'
import { MysApi, Player, Character } from '#miao.models' import { MysApi, Player, Character } from '#miao.models'
import moment from 'moment' import moment from 'moment'
import lodash from 'lodash' import lodash from 'lodash'
import axios from 'axios'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import fetch from 'node-fetch'
const ProfileStat = { const ProfileStat = {
async stat (e) { async stat (e) {
@ -120,8 +120,7 @@ const ProfileStat = {
const request_url = 'https://homdgcat.wiki/gi/CH/maze.js' const request_url = 'https://homdgcat.wiki/gi/CH/maze.js'
let resData = false let resData = false
try { try {
const response = await axios.get(request_url, {timeout: 5000}) resData = await (await fetch(request_url)).text()
resData = response.data
} catch (error) { } catch (error) {
logger.error('请求失败:', error) logger.error('请求失败:', error)
return false // 直接返回以停止后续逻辑 return false // 直接返回以停止后续逻辑
@ -180,8 +179,7 @@ const ProfileStat = {
const request_url = 'https://wiki.biligame.com/ys/%E5%B9%BB%E6%83%B3%E7%9C%9F%E5%A2%83%E5%89%A7%E8%AF%97' const request_url = 'https://wiki.biligame.com/ys/%E5%B9%BB%E6%83%B3%E7%9C%9F%E5%A2%83%E5%89%A7%E8%AF%97'
try { try {
// 发送 GET 请求 // 发送 GET 请求
const response = await axios.get(request_url, {timeout: 5000}); const html = await (await fetch(request_url)).text()
const html = response.data;
// 加载 HTML // 加载 HTML
const $ = cheerio.load(html); const $ = cheerio.load(html);
@ -209,8 +207,7 @@ const ProfileStat = {
const request_url = `https://wiki.biligame.com/${links[mazeId]}` const request_url = `https://wiki.biligame.com/${links[mazeId]}`
// 发送 GET 请求 // 发送 GET 请求
const response = await axios.get(request_url, {timeout: 5000}); const html = await (await fetch(request_url)).text()
const html = response.data;
// 加载 HTML // 加载 HTML
const $ = cheerio.load(html); const $ = cheerio.load(html);

View File

@ -4,14 +4,12 @@
"author": "Yoimiya-Kokomi", "author": "Yoimiya-Kokomi",
"description": "miao-plugin", "description": "miao-plugin",
"type": "module", "type": "module",
"scripts": { "scripts": {},
},
"dependencies": { "dependencies": {
"image-size": "^1.0.2", "image-size": "^1.1.1"
"axios": "^1.7.7"
}, },
"devDependencies": { "devDependencies": {
"cheerio": "1.0.0-rc.12", "cheerio": "1.0.0",
"request": "^2.88.2" "request": "^2.88.2"
}, },
"imports": { "imports": {