Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'v2.1'
Browse files Browse the repository at this point in the history
merge v2.1 to master
  • Loading branch information
Dotos committed Jul 7, 2017
2 parents 9c739b9 + 9fb3133 commit 3c3a464
Show file tree
Hide file tree
Showing 64 changed files with 2,249 additions and 9,420 deletions.
26 changes: 0 additions & 26 deletions Dockerfile

This file was deleted.

138 changes: 85 additions & 53 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var bodyParser = require('body-parser');
var session = require('express-session');
var request = require('superagent');
var index = require('./routes/index');
var photo = require('./routes/photo');
var weibo = require('./routes/weibo');
var ranking = require('./routes/ranking');
var v1 = require('./routes/v1');

// 定时器
Expand All @@ -19,6 +21,7 @@ var bingUtils = require('./utils/bingUtils');
var mailUtils = require('./utils/mailUtils');
var qiniuUtils = require('./utils/qiniuUtils');
var weiboUtils = require('./utils/weiboUtils');
var config = require('./configs/config');

var app = express();
app.disable('x-powered-by');
Expand Down Expand Up @@ -48,34 +51,34 @@ app.use(logger('combined', {
}));

// 每天 00:00,00:10,00:20 检测bing数据
schedule.scheduleJob('0 0,5,10,20,25,30 0 * * *', function() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var now = year + '' + (month < 10 ? '0' + month : month) + '' + (day < 10 ? '0' + day : day);
// 查询是否已经抓取并插入数据库,如果已插入就不重复抓取
dbUtils.get('bing', {
body: {
enddate: now
}
}, function(rows) {
if (rows.length === 0) {
bingUtils.fetchPicture({}, function(data) {
dbUtils.set('bing', data, function(rows) {
data.id = rows.insertId || 0;
mailUtils.send({
message: '从Bing抓取成功',
title: '从Bing抓取成功',
stack: JSON.stringify(data, '', 4)
});
})
});
}
});
});
// schedule.scheduleJob('0 0,5,10,20,25,30 0 * * *', function() {
// var date = new Date();
// var year = date.getFullYear();
// var month = date.getMonth() + 1;
// var day = date.getDate();
// var now = year + '' + (month < 10 ? '0' + month : month) + '' + (day < 10 ? '0' + day : day);
// // 查询是否已经抓取并插入数据库,如果已插入就不重复抓取
// dbUtils.get('bing', {
// body: {
// enddate: now
// }
// }, function(rows) {
// if (rows.length === 0) {
// bingUtils.fetchPicture({}, function(data) {
// dbUtils.set('bing', data, function(rows) {
// data.id = rows.insertId || 0;
// mailUtils.send({
// message: '从Bing抓取成功',
// title: '从Bing抓取成功',
// stack: JSON.stringify(data, '', 4)
// });
// })
// });
// }
// });
// });
// 每天 08:30,12:30,15:30,18:30,21:30 定时发送微博
schedule.scheduleJob('0 30 8,12,15,18,21 * * *', function() {
schedule.scheduleJob('*/30 8-21 * * *', function() {
weiboUtils.update(function(data) {
if (data && data.id) {
mailUtils.send({
Expand All @@ -94,47 +97,74 @@ schedule.scheduleJob('0 30 8,12,15,18,21 * * *', function() {
});

// 每隔五分钟检查数据库中是否存在未上传到骑牛的图片,如果存在则上传图片到骑牛
schedule.scheduleJob('0 1,6,11,16,21,26,31 0 * * *', function() {
dbUtils.get('bing', 'ISNULL(qiniu_url) || qiniu_url=""', function(rows) {
if (rows.length > 0) {
var data = rows[0];
var url = data.url;
qiniuUtils.fetchToQiniu(url, function() {
var _temp = url.substr(url.lastIndexOf('/') + 1, url.length);
var qiniu_url = _temp.substr(0, _temp.lastIndexOf('_'));
dbUtils.update('bing', {
body: {
qiniu_url: qiniu_url
},
condition: {
id: data.id
}
}, function(rs) {
// nsole.log(rs);
});
});
}
});
})
// schedule.scheduleJob('*/1 * * * *', function() {
// dbUtils.get('bing', 'ISNULL(qiniu_url) || qiniu_url=""', function(rows) {
// if (rows.length > 0) {
// var data = rows[0];
// var url = data.url;
// qiniuUtils.fetchToQiniu(url, function() {
// var _temp = url.substr(url.lastIndexOf('/') + 1, url.length);
// var qiniu_url = _temp.substr(0, _temp.lastIndexOf('_'));
// dbUtils.update('bing', {
// body: {
// qiniu_url: qiniu_url
// },
// condition: {
// id: data.id
// }
// }, function(rs) {
// // nsole.log(rs);
// });
// });
// }
// });
// })

/**
* 处理OPTIONS请求
*/
app.use(function(req, res, next) {
console.log('-----------------------------')
console.log(req.headers['host'])
console.log(req.headers['referer'])
console.log('-----------------------------')
if (config.disabled.indexOf(req.headers['host']) > -1) {
res.sendStatus(400)
}
//
if (req.method === 'OPTIONS') {
res.sendStatus(200);
} else next();
});

// var images = [
// 'MangroveRoots_ZH-CN10720576635',
// 'IzmirFaceWall_ZH-CN8661261728',
// 'CapeSebastian_ZH-CN9469145123',
// 'FireEscapes_ZH-CN9251582421',
// 'LaurelMoss_ZH-CN9578543974'
// ];

// var resolutions = require('./configs/config').resolutions;
// for (var i in images) {
// var name = images[i];
// var link = `http://images.ioliu.cn/bing/${name}_1920x1080.jpg`;
// qiniuUtils.specialFetchToQiniu(link);
// }

app.use('/', index);
app.use('/photo', photo);
app.use('/weibo', weibo);
app.use('/ranking', ranking);
app.use('/v1', v1);

app.get('/about.html', function(req, res, next) {
res.render('about');
});
/**
* Robots.txt
*/
app.use('/robots.txt', function(req, res, next) {
app.get('/robots.txt', function(req, res, next) {
res.header('content-type', 'text/plain');
res.send('User-Agent: * \nAllow: /');
});
Expand All @@ -153,9 +183,11 @@ app.get('/test', function(req, res, next) {

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('啊( ⊙ o ⊙ ),你发现了新大陆 ∑(っ °Д °;)っ');
err.status = 404;
next(err);
// var err = new Error('啊( ⊙ o ⊙ ),你发现了新大陆 ∑(っ °Д °;)っ');
// err.status = 404;
// next(err);

res.redirect('/');
});
// error handlers
// development error handler
Expand Down
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var http = require('http');
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '1001');
var port = normalizePort(process.env.PORT || '999');
app.set('port', port);

/**
Expand Down
23 changes: 20 additions & 3 deletions configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ module.exports = {
},
mysql_dev: {
host: process.env.mysql_host,
database: process.env.mysql_database,
user: process.env.mysql_user,
password: process.env.mysql_password,
port: '3306',
database: process.env.mysql_database,
connectionLimit: 10,
supportBigNumbers: true,
multipleStatements: true,
insecureAuth: true
},
disabled: [process.env.disabled.split(',')],
/**
* 已知分辨率
*/
Expand All @@ -26,17 +27,33 @@ module.exports = {
'1920x1080',
'1366x768',
'1280x768',
'1080x1920',
'1024x768',
'800x600',
'800x480',
'768x1366',
'768x1280',
'768x1024',
'720x1280',
'640x480',
'640x360',
'480x800',
'400x240',
'320x240',
'240x320'
]
'320x180',
'240x400',
'240x320',
'240x240',
'200x200',
'150x150'
],

global_link: function() {
return Math.random() > 0.5 ? 'https://static.ioliu.cn' : 'https://bing-images.bitmoe.cn';
},
global_http: function() {
return Math.random() > 0.5 ? 'http://static.ioliu.cn' : 'http://bing-images.bitmoe.cn';
}


}
35 changes: 35 additions & 0 deletions db/bing.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for bing
-- ----------------------------
DROP TABLE IF EXISTS `bing`;
CREATE TABLE `bing` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) DEFAULT NULL,
`attribute` varchar(100) DEFAULT NULL,
`description` varchar(500) DEFAULT NULL,
`copyright` varchar(500) NOT NULL DEFAULT '0',
`copyrightlink` varchar(500) NOT NULL DEFAULT '0',
`startdate` varchar(50) NOT NULL DEFAULT '0',
`enddate` varchar(50) NOT NULL DEFAULT '0',
`fullstartdate` varchar(50) NOT NULL DEFAULT '0',
`url` varchar(500) NOT NULL DEFAULT '0',
`urlbase` varchar(500) NOT NULL DEFAULT '0',
`hsh` varchar(500) NOT NULL DEFAULT '0',
`qiniu_url` varchar(100) DEFAULT NULL,
`longitude` varchar(500) DEFAULT NULL COMMENT '经度',
`latitude` varchar(500) DEFAULT NULL COMMENT '纬度',
`city` varchar(500) DEFAULT NULL COMMENT '城市',
`country` varchar(255) DEFAULT NULL COMMENT '国家',
`continent` varchar(255) DEFAULT NULL COMMENT '洲/大陆',
`thumbnail_pic` varchar(255) DEFAULT NULL COMMENT '缩略图',
`bmiddle_pic` varchar(255) DEFAULT NULL COMMENT '中等大小图',
`original_pic` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '原图',
`weibo` int(1) unsigned zerofill NOT NULL DEFAULT '0' COMMENT '是否发送微博,默认0',
`likes` int(11) unsigned DEFAULT '0' COMMENT '喜欢量',
`views` int(11) unsigned DEFAULT '0' COMMENT '展现量',
`downloads` int(11) unsigned DEFAULT '0' COMMENT '下载量',
PRIMARY KEY (`id`),
KEY `id-title-attribute-qiniu_url` (`id`,`title`,`attribute`,`qiniu_url`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
15 changes: 15 additions & 0 deletions db/bing_session.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for bing_session
-- ----------------------------
DROP TABLE IF EXISTS `bing_session`;
CREATE TABLE `bing_session` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`token` varchar(255) NOT NULL,
`expires_in` int(200) NOT NULL COMMENT '过期时间',
`insertdate` int(200) NOT NULL COMMENT '插入时间',
`uid` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Loading

0 comments on commit 3c3a464

Please sign in to comment.