From 2a92fa385ba1400d6bb918bad39805b866c4d62e Mon Sep 17 00:00:00 2001 From: unknown <1371033826@qq.com> Date: Wed, 14 May 2025 11:13:36 +0800 Subject: [PATCH] fix-offline-baidu-host-resolve-bug --- mixio.js | 64 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/mixio.js b/mixio.js index 6f3a910..b4e75c3 100644 --- a/mixio.js +++ b/mixio.js @@ -1868,19 +1868,25 @@ var mixioServer = async function() { if (globalWeather[req.query.dsc_code] && globalWeather[req.query.dsc_code].time && (new Date().getTime() - globalWeather[req.query.dsc_code].time) < 600000) { res.send(globalWeather[req.query.dsc_code].data) } else { - http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) { - var html = '' - req2.on('data', function(data) { - html += data; - }); - req2.on('end', function() { - globalWeather[req.query.dsc_code] = { - time: new Date().getTime(), - data: html - } - res.send(html) - }); - }) + try { + http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) { + var html = '' + req2.on('data', function(data) { + html += data; + }); + req2.on('end', function() { + globalWeather[req.query.dsc_code] = { + time: new Date().getTime(), + data: html + } + res.send(html) + }); + }).on('error', function(e) { + res.send('-1') + }) + } catch (e) { + res.send('-1') + } } } else res.send('-1') @@ -1891,19 +1897,25 @@ var mixioServer = async function() { if (globalWeather[req.query.dsc_code] && globalWeather[req.query.dsc_code].time && (new Date().getTime() - globalWeather[req.query.dsc_code].time) < 600000) { res.send(globalWeather[req.query.dsc_code].data) } else { - http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) { - var html = '' - req2.on('data', function(data) { - html += data; - }); - req2.on('end', function() { - globalWeather[req.query.dsc_code] = { - time: new Date().getTime(), - data: html - } - res.send(html) - }); - }) + try { + http.get('http://api.map.baidu.com/weather/v1/?district_id=' + req.query.dsc_code + '&data_type=now&ak=' + configs["BAIDU_MAP_SERVER_AK"], function(req2, res2) { + var html = '' + req2.on('data', function(data) { + html += data; + }); + req2.on('end', function() { + globalWeather[req.query.dsc_code] = { + time: new Date().getTime(), + data: html + } + res.send(html) + }); + }).on('error', function(e) { + res.send('-1') + }) + } catch (e) { + res.send('-1') + } } } else res.send('-1')