function sendListOfFiles(response){
  let uploadDir = path.join(__dirname, 'catalogue');
  if (!fs.existsSync(uploadDir)){
    	fs.mkdirSync(uploadDir);
	}
  fs.readdir(uploadDir, (err, files) => {
    if(err){
      console.log(err);
      response.writeHead(400, {'Content-Type': 'application/json'});
      response.write(JSON.stringify(err.message));
      response.end();
    }else{
	//Deleting the files with no m3u8 extension from the list
	for( var i = 0; i < files.length; i++){ 
	   if ( path.extname(files[i]) != ".m3u8") {
	     files.splice(i, 1); 
	     i--;
	   }
	}
      //create json objects
        var dict = {}
	var sources = []
        var videolist = []
	for( var i = 0; i < files.length; i++){ 
		dict["src"] = files[i]
		dict["type"] = "temp"
		sources.push(dict)	
	}
      console.log(JSON.stringify(dict))
      console.log(JSON.stringify(sources))
      for ( var i = 0; i < sources.length; i++){ 
		videolist["sources"] = sources[i]	
	}
      console.log(JSON.stringify(videolist))

      response.writeHead(200, {'Content-Type': 'application/json'});
      response.write(JSON.stringify(files));
      response.end();
    }
  })
}
//Send list of files in /catalogue
Send list of files in /catalogue
Send list of files in / catalogue
function sendListOfFiles(response){
  let uploadDir = path.join(__dirname, 'catalogue');
  if (!fs.existsSync(uploadDir)){
    	fs.mkdirSync(uploadDir);
	}
  fs.readdir(uploadDir, (err, files) => {
    if(err){
      console.log(err);
      response.writeHead(400, {'Content-Type': 'application/json'});
      response.write(JSON.stringify(err.message));
      response.end();
    }else{
	for( var i = 0; i < files.length; i++){ 
	   if ( path.extname(files[i]) != ".m3u8") {
	     files.splice(i, 1); 
	     i--;
	   }
	}
        var dict = {}
	var sources = []
        var videolist = []
	for( var i = 0; i < files.length; i++){ 
		dict["src"] = files[i]
		dict["type"] = "temp"
		sources.push(dict)	
	}
      console.log(JSON.stringify(dict))
      console.log(JSON.stringify(sources))
      for ( var i = 0; i < sources.length; i++){ 
		videolist["sources"] = sources[i]	
	}
      console.log(JSON.stringify(videolist))
      response.writeHead(200, {'Content-Type': 'application/json'});
      response.write(JSON.stringify(files));
      response.end();
    }
  })
}
function sendListOfFiles ( response ) { let uploadDir = path . join ( __dirname , 'catalogue' ) ; if ( ! fs . existsSync ( uploadDir ) ) { fs . mkdirSync ( uploadDir ) ; } fs . readdir ( uploadDir , ( err , files ) => { if ( err ) { console . log ( err ) ; response . writeHead ( 400 , { 'Content-Type' : 'application/json' } ) ; response . write ( JSON . stringify ( err . message ) ) ; response . end ( ) ; } else { for ( var i = 0 ; i < files . length ; i ++ ) { if ( path . extname ( files [ i ] ) != ".m3u8" ) { files . splice ( i , 1 ) ; i -- ; } } var dict = { } var sources = [ ] var videolist = [ ] for ( var i = 0 ; i < files . length ; i ++ ) { dict [ "src" ] = files [ i ] dict [ "type" ] = "temp" sources . push ( dict ) } console . log ( JSON . stringify ( dict ) ) console . log ( JSON . stringify ( sources ) ) for ( var i = 0 ; i < sources . length ; i ++ ) { videolist [ "sources" ] = sources [ i ] } console . log ( JSON . stringify ( videolist ) ) response . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ; response . write ( JSON . stringify ( files ) ) ; response . end ( ) ; } } ) }
Send list of files in /catalogue
Send list of files in / catalogue
//Deleting the files with no m3u8 extension from the list //create json objects