record danmaku ip and referer

This commit is contained in:
DIYgod 2017-03-25 19:55:59 +08:00
parent 18acaad609
commit 3a798cfcd7
2 changed files with 8 additions and 5 deletions

View File

@ -7,7 +7,9 @@ var danmakuSchema = new mongoose.Schema({
time: Number,
text: String,
color: String,
type: String
type: String,
ip: String,
referer: String
});
var danmaku = mongoose.model('dan', danmakuSchema);

View File

@ -1,4 +1,3 @@
var url = require('url');
var fs = require('fs');
var logger = require('../tools/logger');
var danmaku = require('../models/danmaku');
@ -17,7 +16,7 @@ var postIP = [];
module.exports = function (req, res) {
var body = '';
var jsonStr;
var jsonStr = {};
var ip = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
@ -55,7 +54,7 @@ module.exports = function (req, res) {
try {
jsonStr = JSON.parse(body);
} catch (err) {
jsonStr = null;
jsonStr = {};
}
// check data
@ -96,7 +95,9 @@ module.exports = function (req, res) {
time: jsonStr.time,
text: htmlEncode(jsonStr.text),
color: htmlEncode(jsonStr.color),
type: htmlEncode(jsonStr.type)
type: htmlEncode(jsonStr.type),
ip: ip,
referer: req.headers.referer
});
dan.save(function (err, d) {
if (err) {