删除 - 去除新闻请求时的输出

This commit is contained in:
suwings 2018-04-18 11:29:25 +08:00
parent e286467f93
commit e78d01aefa

View File

@ -1,14 +1,13 @@
const fs = require('fs'); const fs = require('fs');
const http = require('http'); const http = require('http');
//最新动态信息获取模块,如果你不需要这个功能,你可以将这里的全部代码删除!
//地址 与 备用地址 //地址 与 备用地址
let newsUrl1 = 'http://www.suwings.top/mcserver/?_=' + Date.parse(new Date()); let newsUrl1 = 'http://www.suwings.top/mcserver/?_=' + Date.parse(new Date());
let newsUrl2 = 'http://mcservermanager.oss-cn-beijing.aliyuncs.com/news.json?_= ' + Date.parse(new Date()); let newsUrl2 = 'http://mcservermanager.oss-cn-beijing.aliyuncs.com/news.json?_= ' + Date.parse(new Date());
let requestNewsUrl = newsUrl1; let requestNewsUrl = newsUrl1;
let requestNewsCount = 1; let requestNewsCount = 1;
function requestNewsError() { function requestNewsError() {
@ -16,47 +15,31 @@ function requestNewsError() {
//尝试第二次链接 //尝试第二次链接
requestNewsUrl = newsUrl2; requestNewsUrl = newsUrl2;
requestNewsCount++; requestNewsCount++;
requestNews() requestNews();
MCSERVER.infoLog('Exception'.red, '第一次发起请求失败,启动备用服务器链接', true);
return; return;
} }
MCSERVER.infoLog('Exception'.red, '读取最新动态失败', true);
} }
//get 请求外网 //get 请求外网
function requestNews() { function requestNews() {
let req = http.get(requestNewsUrl, function (req, res) {
let req = http.get(requestNewsUrl, function(req, res) {
MCSERVER.log('版本管理机制准备');
var html = ''; var html = '';
req.on('data', (data) => html += data); req.on('data', (data) => html += data);
req.on('end', () => { req.on('end', () => {
MCSERVER.log('正在获取版本动态...');
//判断是否是正确的 //判断是否是正确的
try { try {
JSON.parse(html); JSON.parse(html);
fs.writeFile('./public/news.json', html, function(err) { fs.writeFile('./public/news.json', html, function (err) {
if (err) { if (err) {
console.error('更新最新资讯写入失败');
return; return;
} }
MCSERVER.log('保存最新版本动态完成')
MCSERVER.infoLog('Done','Module 集合与 AppListen 已全部执行')
}); });
} catch (err) { } catch (err) {
// MCSERVER.log('')
console.error(err)
requestNewsError(); requestNewsError();
} }
}); });
}); });
req.on("error", function(err) { req.on("error", function (err) {
console.error(err)
requestNewsError(); requestNewsError();
}); });
} }