var restify = require('restify');

var pool = require('./utils/db-pooling.js');

var port = 8792;

var version = '2.0';

var server = restify.createServer({
    name: 'ds_api',
    version: 'v2.0.0'
});

server.use(restify.bodyParser());

// pool.query('SELECT NOW()', function(err, rows, fields) {
//   if (err) throw err;
//
//   console.log('The solution is: ', rows);
// });

server.get('/getVideosByType/:videoId/:count/:type/:userId', function(req, res, next) {

    var sql = 'select  *  from `tb_video` v ORDER BY id DESC LIMIT 10'

    pool.query(sql, function(err, rows, fields) {
        if (err) throw err;

        console.log('The solution is: ', rows);

        res.setHeader('content-type', 'application/json');
        res.send(200, rows);
        return next();
    });
});



server.listen(port, function() {
    console.log('%s listening at %s', server.name, server.url);
});

@@ -107,16 +107,17 @@
 sion = '
+v
 2.0';%0A%0Av
@@ -385,17 +385,36 @@
 ver.get(
-'
+version+'/rest/video
 /getVide
@@ -490,47 +490,664 @@
     
-var sql = 'select  *  from %60tb_video%60 v
+res.setHeader('content-type', 'application/json;charset=utf-8');%0A%0A    var sql = 'select distinct v.title, v.id, v.url as videoUrl, v.pic, v.type, v.createTime as pushTime, (select count(*) from %60tb_user_video%60 tub WHERE tub.%60status%60 = 1 AND tub.userId = ? AND tub.videoId = v.id) as isCollectStatus from %60tb_video%60 v where v.title != %22%22 '%0A%0A    var values = %5BNumber(req.params.userId)%5D;%0A%0A    if (Number(req.params.videoId) != 0) %7B%0A%0A        sql += ' AND id %3C ? '%0A        values.push(Number(req.params.videoId))%0A    %7D%0A%0A    if (Number(req.params.type) != 0) %7B%0A%0A        sql += ' AND type = ? ' %0A%0A        values.push(Number(req.params.type))%0A%0A    %7D%0A%0A    sql += '
  ORD
@@ -1170,13 +1170,137 @@
 MIT 
-10
+? 
 '%0A%0A
+    values.push(Number(req.params.count))%0A%0A    console.log(%22q sql =%3E %22 + sql);%0A%0A    console.log(%22q values =%3E %22 + values);%0A %0A
     
@@ -1314,16 +1314,23 @@
 ery(sql,
+values,
  functio
@@ -1372,21 +1372,14 @@
 err)
- throw err;%0A%0A
+%7B%0A    
     
@@ -1398,95 +1398,418 @@
 log(
-'The solution is: ', rows);%0A%0A        res.setHeader('content-type', 'application/json');
+err);%0A            throw err;%0A        %7D %0A %0A        for (var i = 0; i %3C rows.length; i++) %7B%0A            rows%5Bi%5D%5B%22id%22%5D = rows%5Bi%5D%5B%22id%22%5D+ '';%0A            rows%5Bi%5D%5B%22title%22%5D =  new Buffer(rows%5Bi%5D%5B%22title%22%5D, 'base64').toString();%0A        %7D%0A%0A        var resultJson = %7B%0A%0A            message : '%E8%8E%B7%E5%8F%96 '+ rows.length + '%E6%9D%A1%E6%95%B0%E6%8D%AE',%0A            statusCode : 200,%0A            content : rows,%0A            request : req.url%0A%0A        %7D; %0A
 %0A   
@@ -1828,19 +1828,25 @@
 d(200, r
-ows
+esultJson
 );%0A     

add getVideosByType api