@ -11,27 +11,28 @@ var user = require('./../user.js'),
( function ( Api ) {
Api . create _routes = function ( app ) {
app . get ( '/api/get_templates_listing' , function ( req , res ) {
app . namespace ( '/api' , function ( ) {
app . get ( '/get_templates_listing' , function ( req , res ) {
utils . walk ( path . join ( _ _dirname , '../../' , 'public/templates' ) , function ( err , data ) {
res . json ( data ) ;
} ) ;
} ) ;
app . get ( ' /api /config', function ( req , res , next ) {
app . get ( ' /config', function ( req , res , next ) {
var config = require ( '../../public/config.json' ) ;
config [ 'postDelay' ] = meta . config [ 'postDelay' ] ;
config [ 'minimumTitleLength' ] = meta . config [ 'minimumTitleLength' ] ;
config [ 'minimumPostLength' ] = meta . config [ 'minimumPostLength' ] ;
config [ 'imgurClientIDSet' ] = ! ! meta . config [ 'imgurClientID' ] ;
config [ 'minimumUsernameLength' ] = meta . config [ 'minimumUsernameLength' ] ;
config [ 'maximumUsernameLength' ] = meta . config [ 'maximumUsernameLength' ] ;
config [ 'minimumPasswordLength' ] = meta . config [ 'minimumPasswordLength' ] ;
config . postDelay = meta . config . postDelay ;
config . minimumTitleLength = meta . config . minimumTitleLength ;
config . minimumPostLength = meta . config . minimumPostLength ;
config . imgurClientIDSet = ! ! meta . config . imgurClientID ;
config . minimumUsernameLength = meta . config . minimumUsernameLength ;
config . maximumUsernameLength = meta . config . maximumUsernameLength ;
config . minimumPasswordLength = meta . config . minimumPasswordLength ;
res . json ( 200 , config ) ;
} ) ;
app . get ( '/ api/ home', function ( req , res ) {
app . get ( '/ home', function ( req , res ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
categories . getAllCategories ( function ( data ) {
data . categories = data . categories . filter ( function ( category ) {
@ -40,8 +41,8 @@ var user = require('./../user.js'),
function iterator ( category , callback ) {
categories . getRecentReplies ( category . cid , 2 , function ( posts ) {
category [ "posts" ] = posts ;
category [ "post_count" ] = posts . length > 2 ? 2 : posts . length ;
category . posts = posts ;
category . post _count = posts . length > 2 ? 2 : posts . length ;
callback ( null ) ;
} ) ;
}
@ -55,7 +56,7 @@ var user = require('./../user.js'),
} , uid ) ;
} ) ;
app . get ( ' /api /login', function ( req , res ) {
app . get ( ' /login', function ( req , res ) {
var data = { } ,
login _strategies = auth . get _login _strategies ( ) ,
num _strategies = login _strategies . length ;
@ -80,7 +81,7 @@ var user = require('./../user.js'),
res . json ( data ) ;
} ) ;
app . get ( ' /api /register', function ( req , res ) {
app . get ( ' /register', function ( req , res ) {
var data = { } ,
login _strategies = auth . get _login _strategies ( ) ,
num _strategies = login _strategies . length ;
@ -107,7 +108,7 @@ var user = require('./../user.js'),
res . json ( data ) ;
} ) ;
app . get ( ' /api /topic/:id/:slug?', function ( req , res , next ) {
app . get ( ' /topic/:id/:slug?', function ( req , res , next ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
topics . getTopicWithPosts ( req . params . id , uid , 0 , 10 , function ( err , data ) {
if ( ! err ) {
@ -119,7 +120,7 @@ var user = require('./../user.js'),
} ) ;
} ) ;
app . get ( ' /api /category/:id/:slug?', function ( req , res , next ) {
app . get ( ' /category/:id/:slug?', function ( req , res , next ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
categories . getCategoryById ( req . params . id , uid , function ( err , data ) {
if ( ! err )
@ -129,28 +130,28 @@ var user = require('./../user.js'),
} , req . params . id , uid ) ;
} ) ;
app . get ( ' /api /recent', function ( req , res ) {
app . get ( ' /recent', function ( req , res ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
topics . getLatestTopics ( uid , 0 , 19 , function ( data ) {
res . json ( data ) ;
} ) ;
} ) ;
app . get ( ' /api /unread', function ( req , res ) {
app . get ( ' /unread', function ( req , res ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
topics . getUnreadTopics ( uid , 0 , 19 , function ( data ) {
res . json ( data ) ;
} ) ;
} ) ;
app . get ( ' /api /unread/total', function ( req , res ) {
app . get ( ' /unread/total', function ( req , res ) {
var uid = ( req . user ) ? req . user . uid : 0 ;
topics . getTotalUnread ( uid , function ( data ) {
res . json ( data ) ;
} ) ;
} ) ;
app . get ( ' /api /confirm/:id', function ( req , res ) {
app . get ( ' /confirm/:id', function ( req , res ) {
user . email . confirm ( req . params . id , function ( data ) {
if ( data . status === 'ok' ) {
res . json ( {
@ -168,7 +169,7 @@ var user = require('./../user.js'),
} ) ;
} ) ;
app . get ( ' /api /outgoing', function ( req , res ) {
app . get ( ' /outgoing', function ( req , res ) {
var url = req . query . url ;
if ( url ) {
@ -182,7 +183,7 @@ var user = require('./../user.js'),
}
} ) ;
app . get ( ' /api /search', function ( req , res ) {
app . get ( ' /search', function ( req , res ) {
return res . json ( {
show _no _topics : 'hide' ,
show _no _posts : 'hide' ,
@ -193,7 +194,7 @@ var user = require('./../user.js'),
} ) ;
} ) ;
app . get ( ' /api /search/:term', function ( req , res , next ) {
app . get ( ' /search/:term', function ( req , res , next ) {
var reds = require ( 'reds' ) ;
var postSearch = reds . createSearch ( 'nodebbpostsearch' ) ;
@ -244,22 +245,23 @@ var user = require('./../user.js'),
} ) ;
} ) ;
app . get ( ' /api /reset', function ( req , res ) {
app . get ( ' /reset', function ( req , res ) {
res . json ( { } ) ;
} ) ;
app . get ( ' /api /reset/:code', function ( req , res ) {
app . get ( ' /reset/:code', function ( req , res ) {
res . json ( {
reset _code : req . params . code
} ) ;
} ) ;
app . get ( '/ api/ 404', function ( req , res ) {
app . get ( '/ 404', function ( req , res ) {
res . json ( { } ) ;
} ) ;
app . get ( '/ api/ 403', function ( req , res ) {
app . get ( '/ 403', function ( req , res ) {
res . json ( { } ) ;
} ) ;
} ) ;
}
} ( exports ) ) ;