diff --git a/nodejs/models/danmaku.js b/nodejs/models/danmaku.js index 5cfd079..6b0512b 100644 --- a/nodejs/models/danmaku.js +++ b/nodejs/models/danmaku.js @@ -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); diff --git a/nodejs/routes/post.js b/nodejs/routes/post.js index 8486478..dd3dd8f 100644 --- a/nodejs/routes/post.js +++ b/nodejs/routes/post.js @@ -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) {