优化网络请求

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

View File

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

View File

@ -14,6 +14,7 @@ const {
} = require('electron') } = require('electron')
const path = require('path') const path = require('path')
const fs = require('iofs') const fs = require('iofs')
const fetch = require('node-fetch')
const { createMainWindow, createFloatWindow } = require('./tools/window') const { createMainWindow, createFloatWindow } = require('./tools/window')
const createMenu = require('./tools/menu') const createMenu = require('./tools/menu')
@ -35,29 +36,6 @@ const ROOT = __dirname
var timer 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() { function ring() {
var n = 5 var n = 5
var t = setInterval(() => { var t = setInterval(() => {
@ -120,9 +98,14 @@ app.once('ready', () => {
ipcMain.on('app', (ev, conn) => { ipcMain.on('app', (ev, conn) => {
switch (conn.type) { switch (conn.type) {
case 'fetch': case 'fetch':
fetch(conn.data).then(r => { fetch(conn.data, {
ev.returnValue = r 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 break
case 'notify': case 'notify':