@ -1,7 +1,7 @@
var async = require ( 'async' ) ;
var async = require ( 'async' ) ;
const { uuid } = require ( 'uuidv4' ) ;
const { uuid } = require ( 'uuidv4' ) ;
var fs = require ( 'fs-extra' ) ;
var fs = require ( 'fs-extra' ) ;
var auth = require ( './authentication/auth' ) ;
var auth _api = require ( './authentication/auth' ) ;
var winston = require ( 'winston' ) ;
var winston = require ( 'winston' ) ;
var path = require ( 'path' ) ;
var path = require ( 'path' ) ;
var youtubedl = require ( 'youtube-dl' ) ;
var youtubedl = require ( 'youtube-dl' ) ;
@ -63,6 +63,7 @@ const logger = winston.createLogger({
config _api . setLogger ( logger ) ;
config _api . setLogger ( logger ) ;
subscriptions _api . setLogger ( logger ) ;
subscriptions _api . setLogger ( logger ) ;
auth _api . setLogger ( logger ) ;
// var GithubContent = require('github-content');
// var GithubContent = require('github-content');
@ -154,7 +155,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
app . use ( bodyParser . json ( ) ) ;
app . use ( bodyParser . json ( ) ) ;
// use passport
// use passport
app . use ( auth . passport . initialize ( ) ) ;
app . use ( auth _api . passport . initialize ( ) ) ;
// objects
// objects
@ -218,6 +219,7 @@ async function runFilesToDBMigration() {
db . set ( 'files_to_db_migration_complete' , true ) . write ( ) ;
db . set ( 'files_to_db_migration_complete' , true ) . write ( ) ;
resolve ( true ) ;
resolve ( true ) ;
} catch ( err ) {
} catch ( err ) {
logger . error ( err ) ;
resolve ( false ) ;
resolve ( false ) ;
}
}
} ) ;
} ) ;
@ -635,7 +637,7 @@ function getMp3s() {
var url = jsonobj . webpage _url ;
var url = jsonobj . webpage _url ;
var uploader = jsonobj . uploader ;
var uploader = jsonobj . uploader ;
var upload _date = jsonobj . upload _date ;
var upload _date = jsonobj . upload _date ;
upload _date = ` ${ upload _date . substring ( 0 , 4 ) } - ${ upload _date . substring ( 4 , 6 ) } - ${ upload _date . substring ( 6 , 8 ) } ` ;
upload _date = upload _date ? ` ${ upload _date . substring ( 0 , 4 ) } - ${ upload _date . substring ( 4 , 6 ) } - ${ upload _date . substring ( 6 , 8 ) } ` : null ;
var size = stats . size ;
var size = stats . size ;
@ -664,7 +666,7 @@ function getMp4s(relative_path = true) {
var url = jsonobj . webpage _url ;
var url = jsonobj . webpage _url ;
var uploader = jsonobj . uploader ;
var uploader = jsonobj . uploader ;
var upload _date = jsonobj . upload _date ;
var upload _date = jsonobj . upload _date ;
upload _date = ` ${ upload _date . substring ( 0 , 4 ) } - ${ upload _date . substring ( 4 , 6 ) } - ${ upload _date . substring ( 6 , 8 ) } ` ;
upload _date = upload _date ? ` ${ upload _date . substring ( 0 , 4 ) } - ${ upload _date . substring ( 4 , 6 ) } - ${ upload _date . substring ( 6 , 8 ) } ` : null ;
var thumbnail = jsonobj . thumbnail ;
var thumbnail = jsonobj . thumbnail ;
var duration = jsonobj . duration ;
var duration = jsonobj . duration ;
@ -1659,6 +1661,14 @@ app.use(function(req, res, next) {
app . use ( compression ( ) ) ;
app . use ( compression ( ) ) ;
const optionalJwt = function ( req , res , next ) {
const multiUserMode = config _api . getConfigItem ( 'ytdl_multi_user_mode' ) ;
if ( multiUserMode && req . query . jwt ) {
return auth _api . passport . authenticate ( 'jwt' , { session : false } ) ( req , res , next ) ;
}
return next ( ) ;
} ;
app . get ( '/api/config' , function ( req , res ) {
app . get ( '/api/config' , function ( req , res ) {
let config _file = config _api . getConfigFile ( ) ;
let config _file = config _api . getConfigFile ( ) ;
res . send ( {
res . send ( {
@ -1781,19 +1791,21 @@ app.post('/api/fileStatusMp4', function(req, res) {
} ) ;
} ) ;
// gets all download mp3s
// gets all download mp3s
app . get ( '/api/getMp3s' , function ( req , res ) {
app . get ( '/api/getMp3s' , optionalJwt , function ( req , res ) {
const multiUserMode = config _api . getConfigItem ( 'ytdl_multi_user_mode' ) ;
var mp3s = db . get ( 'files.audio' ) . value ( ) ; // getMp3s();
var mp3s = db . get ( 'files.audio' ) . value ( ) ; // getMp3s();
var playlists = db . get ( 'playlists.audio' ) . value ( ) ;
var playlists = db . get ( 'playlists.audio' ) . value ( ) ;
const is _authenticated = req . isAuthenticated ( ) ;
if ( req. query . jwt && multiUserMode ) {
if ( is_authenticated ) {
// mp3s = db.get
// mp3s = db.get
}
auth _api . passport . authenticate ( 'jwt' )
mp3s = auth _api . getUserVideos ( )
} else {
res . send ( {
res . send ( {
mp3s : mp3s ,
mp3s : mp3s ,
playlists : playlists
playlists : playlists
} ) ;
} ) ;
}
res . end ( "yes" ) ;
res . end ( "yes" ) ;
} ) ;
} ) ;
@ -2537,11 +2549,18 @@ app.get('/api/audio/:id', function(req , res){
// user authentication
// user authentication
app . post ( '/api/auth/register'
app . post ( '/api/auth/register'
, auth . registerUser ) ;
, auth _api . registerUser ) ;
app . post ( '/api/auth/login'
app . post ( '/api/auth/login'
, auth . passport . authenticate ( 'local' , { } )
, auth _api . passport . authenticate ( 'local' , { } )
, auth . generateJWT
, auth _api . passport . authorize ( 'local' )
, auth . returnAuthResponse
, auth _api . generateJWT
, auth _api . returnAuthResponse
) ;
app . post ( '/api/auth/jwtAuth'
, auth _api . passport . authenticate ( 'jwt' , { session : false } )
, auth _api . passport . authorize ( 'jwt' )
, auth _api . generateJWT
, auth _api . returnAuthResponse
) ;
) ;
app . use ( function ( req , res , next ) {
app . use ( function ( req , res , next ) {