@ -164,27 +164,45 @@ var fs = require('fs'),
} ) ;
} ) ;
} ;
} ;
Plugins . get = function ( id , callback ) {
var url = ( nconf . get ( 'registry' ) || 'https://packages.nodebb.org' ) + '/api/v1/plugins/' + id ;
console . log ( url ) ;
require ( 'request' ) ( url , {
json : true
} , function ( err , res , body ) {
Plugins . normalise ( [ body . payload ] , function ( err , normalised ) {
return callback ( err , ! err ? normalised [ 0 ] : undefined ) ;
} ) ;
} ) ;
} ;
Plugins . getAll = function ( callback ) {
Plugins . getAll = function ( callback ) {
var url = ( nconf . get ( 'registry' ) || 'https://packages.nodebb.org' ) + '/api/v1/plugins?version=' + require ( '../package.json' ) . version ;
var url = ( nconf . get ( 'registry' ) || 'https://packages.nodebb.org' ) + '/api/v1/plugins?version=' + require ( '../package.json' ) . version ;
require ( 'request' ) ( url , function ( err , res , body ) {
require ( 'request' ) ( url , {
json : true
} , function ( err , res , body ) {
var plugins = [ ] ;
var plugins = [ ] ;
try {
if ( err ) {
plugins = JSON . parse ( body ) ;
} catch ( err ) {
winston . error ( 'Error parsing plugins : ' + err . message ) ;
winston . error ( 'Error parsing plugins : ' + err . message ) ;
plugins = [ ] ;
plugins = [ ] ;
}
}
Plugins . normalise ( body , callback ) ;
} ) ;
} ;
Plugins . normalise = function ( apiReturn , callback ) {
var pluginMap = { } ;
var pluginMap = { } ;
for ( var i = 0 ; i < plugins . length ; ++ i ) {
for ( var i = 0 ; i < a piRetur n. length ; ++ i ) {
plugins [ i ] . id = plugins [ i ] . name ;
apiReturn [ i ] . id = a piRetur n[ i ] . name ;
plugins [ i ] . installed = false ;
apiReturn [ i ] . installed = false ;
plugins [ i ] . active = false ;
apiReturn [ i ] . active = false ;
plugins [ i ] . url = plug ins [ i ] . url ? plugins[ i ] . url : plugins [ i ] . repository ? plug ins [ i ] . repository . url : '' ;
apiReturn [ i ] . url = a piRetur n[ i ] . url ? apiReturn[ i ] . url : apiReturn [ i ] . repository ? a piRetur n[ i ] . repository . url : '' ;
plugins [ i ] . latest = plug ins [ i ] . latest ;
apiReturn [ i ] . latest = a piRetur n[ i ] . latest ;
pluginMap [ plug ins [ i ] . name ] = plug ins [ i ] ;
pluginMap [ a piRetur n[ i ] . name ] = a piRetur n[ i ] ;
}
}
Plugins . showInstalled ( function ( err , installedPlugins ) {
Plugins . showInstalled ( function ( err , installedPlugins ) {
@ -199,6 +217,8 @@ var fs = require('fs'),
pluginMap [ plugin . id ] . installed = true ;
pluginMap [ plugin . id ] . installed = true ;
pluginMap [ plugin . id ] . error = true ;
pluginMap [ plugin . id ] . error = true ;
return next ( ) ;
return next ( ) ;
} else if ( ! pluginMap . hasOwnProperty ( plugin . id ) ) {
return next ( ) ;
}
}
pluginMap [ plugin . id ] = pluginMap [ plugin . id ] || { } ;
pluginMap [ plugin . id ] = pluginMap [ plugin . id ] || { } ;
@ -240,7 +260,6 @@ var fs = require('fs'),
callback ( null , pluginArray ) ;
callback ( null , pluginArray ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ;
} ;
Plugins . showInstalled = function ( callback ) {
Plugins . showInstalled = function ( callback ) {