var express = require('express');
var router = express.Router();

// require feed parser and http
var FeedParser = require('feedparser');
var http = require('http');
var mongoose = require( 'mongoose' );
var Feeds     = mongoose.model( 'Feeds' );
var Posts     = mongoose.model( 'Posts' );

/* GET feed listing. */
router.get('/', function(req, res) {

    if(req.connection.remoteAddress == "127.0.0.1"){

        Feeds.find(function (err, feeds) {
            if (err) return res.send(500, {
                error: err
            });

            // each feeds post
            feeds.forEach(function(items){
                http.get(items.feedUrl, function(respond) {

                    //前一天
                    var d = new Date();
                    d.setDate(d.getDate() - 1);

                    respond.pipe(new FeedParser({}))
                        .on('error', function(error){
                            console.log(error);
                        })
                        .on('readable', function(){
                            var stream = this, item;
                            while (item = stream.read()){
                                // Each 'readable' event will contain 1 article
                                if(item.pubDate > d){
                                    // save posts
                                    new Posts({
                                        title    : item.title,
                                        url      : item.link,
                                        desc  : item.description,
                                        feedId: items.id,
                                        postTime: item.pubDate
                                    }).save(function(e){console.log(e)});
                                }
                            }
                        })
                });
            });
            return res.send("done");
        });
    } else {
        res.send(500, {
            error: "禁止访问"
        });
    }
});

module.exports = router;

@@ -182,17 +182,16 @@
 require(
- 
 'mongoos
@@ -192,17 +192,16 @@
 ongoose'
- 
 );%0Avar F
@@ -205,20 +205,16 @@
 r Feeds 
-    
 = mongoo
@@ -226,17 +226,15 @@
 del(
- 
 'Feeds'
- 
 );%0Av
@@ -242,20 +242,16 @@
 r Posts 
-    
 = mongoo
@@ -263,17 +263,15 @@
 del(
- 
 'Posts'
- 
 );%0A%0A
@@ -318,16 +318,17 @@
 function
+ 
 (req, re
@@ -339,16 +339,17 @@
 %0A%0A    if
+ 
 (req.con
@@ -385,16 +385,17 @@
 .0.0.1%22)
+ 
 %7B%0A%0A     
@@ -516,24 +516,115 @@
        %7D);%0A%0A
+            //%E5%89%8D%E4%B8%80%E5%A4%A9%0A            var d = new Date();%0A            d.setDate(d.getDate() - 1);%0A%0A
             
@@ -680,15 +680,17 @@
 tion
+ 
 (items)
+ 
 %7B%0A  
@@ -735,16 +735,17 @@
 function
+ 
 (respond
@@ -753,123 +753,8 @@
  %7B%0A%0A
-                    //%E5%89%8D%E4%B8%80%E5%A4%A9%0A                    var d = new Date();%0A                    d.setDate(d.getDate() - 1);%0A%0A
     
@@ -847,23 +847,25 @@
 function
+ 
 (error)
+ 
 %7B%0A      
@@ -981,18 +981,20 @@
 function
+ 
 ()
+ 
 %7B%0A      
@@ -1096,16 +1096,17 @@
 .read())
+ 
 %7B%0A      
@@ -1213,16 +1213,17 @@
       if
+ 
 (item.pu
@@ -1232,16 +1232,17 @@
 ate %3E d)
+ 
 %7B%0A      
@@ -1378,20 +1378,16 @@
    title
-    
 : item.t
@@ -1435,22 +1435,16 @@
      url
-      
 : item.l
@@ -1492,18 +1492,16 @@
     desc
-  
 : item.d
@@ -1689,26 +1689,114 @@
 tion
+ 
 (e)
-%7Bconsole.log(e)
+ %7B%0A                                            console.log(e)%0A                                        
 %7D);%0A

update rss fetch time