优化网络请求

master
宇天 2021-05-17 14:42:01 +08:00
parent 65238a97d6
commit 2ec418479b
3 changed files with 18 additions and 28 deletions

View File

@ -1,6 +1,6 @@
{
"name": "io.yutent.gaystat",
"version": "2.1.3",
"version": "2.2.0",
"description": "搞基数据",
"main": "src/main.js",
"scripts": {
@ -26,7 +26,7 @@
"version": "11.0.4",
"mirror": "https://npm.taobao.org/mirrors/electron/"
},
"files": ["src/**/*", "node_modules/iofs/*"],
"files": ["src/**/*", "node_modules/iofs/*", "node_modules/node-fetch/*"],
"mac": {
"category": "public.app-category.developer-tools",
"target": "dmg",
@ -39,6 +39,7 @@
"electron-builder": "^22.1.0"
},
"dependencies": {
"iofs": "^1.3.2"
"iofs": "^1.5.2",
"node-fetch": "^2.6.1"
}
}

View File

@ -144,6 +144,7 @@ Anot({
'fetch',
`https://fundgz.1234567.com.cn/js/${id}.js`
)
return getJsonp(res)
},
@ -201,6 +202,11 @@ Anot({
let info = this.getGayStat(it.code)
let time, needUpdate
if (!info) {
console.log(it)
continue
}
it.cm = +info.gsz
it.cp = +info.gszzl

View File

@ -14,6 +14,7 @@ const {
} = require('electron')
const path = require('path')
const fs = require('iofs')
const fetch = require('node-fetch')
const { createMainWindow, createFloatWindow } = require('./tools/window')
const createMenu = require('./tools/menu')
@ -35,29 +36,6 @@ const ROOT = __dirname
var timer
function fetch(url) {
return new Promise((y, n) => {
var conn = net.request(url)
var r = []
conn.on('response', res => {
res.on('data', c => {
r.push(c)
})
res.on('end', _ => {
y(Buffer.concat(r).toString())
})
})
conn.on('error', e => {
n(e)
})
conn.end()
})
}
function ring() {
var n = 5
var t = setInterval(() => {
@ -120,9 +98,14 @@ app.once('ready', () => {
ipcMain.on('app', (ev, conn) => {
switch (conn.type) {
case 'fetch':
fetch(conn.data).then(r => {
ev.returnValue = r
fetch(conn.data, {
headers: {
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
}
})
.then(r => r.text())
.then(r => (ev.returnValue = r))
break
case 'notify':