diff --git a/modules/configure-json-file.js b/modules/configure-json-file.js index 0849113..e2544a4 100644 --- a/modules/configure-json-file.js +++ b/modules/configure-json-file.js @@ -20,7 +20,7 @@ exports.setup = function(args){ loadJson.userinterface = "public"; } - + // TODO; Preform a full range of checks // Export JSON return loadJson; diff --git a/modules/db-management/database-beets-manager.js b/modules/db-management/database-beets-manager.js deleted file mode 100644 index a2291f5..0000000 --- a/modules/db-management/database-beets-manager.js +++ /dev/null @@ -1,151 +0,0 @@ -// Special functions for beets DB - -// Download the database -// TODO: Fix these -mstream.get('/db/download-db', function(req, res){ - var file = program.database; - - res.download(file); // Set disposition and send it. -}); - - -// Get hash of database -mstream.get( '/db/hash', function(req, res){ - var hash = crypto.createHash('sha256'); - var fileStream = fs.createReadStream(program.database); - - hash.setEncoding('hex'); - fileStream.pipe(hash, { end: false }); - - - fileStream.on('end', function () { - hash.end(); - - var returnThis = { - hash:String(hash.read()) - }; - - res.send(JSON.stringify(returnThis)); - - }); -}); - - - - - -// // TODO: This thing has to be tested -// -// // TODO: These functions are for interacting withe the beets DB -// // Includes: rescan DB, hash files -// // Once DB has been updated, call functiosn in /db-write/database-beets-[mysql/sqlite/loki].js to pull info into publicDB -// -// const spawn = require('child_process').spawn; -// var scanLock = false; -// var yetAnotherArrayOfSongs = []; -// var totalFileCount = 0; -// -// exports.setup = function(mstream, program, rootDir, db){ -// const scanThisDir = program.beetspath; // TODO: Check that this is a real directory -// -// -// mstream.get('/db/recursive-scan-beets', function(req,res){ -// -// if(scanLock === true){ -// // Return error -// res.status(401).send('{"error":"Scan in progress"}'); -// return; -// } -// -// scanLock = true; -// var cmd = spawn('beet', [ 'import', '-A', '--group-albums' , scanThisDir]); -// -// cmd.stdout.on('data', (data) => { -// console.log(`stdout: ${data}`); -// }); -// -// cmd.stderr.on('data', (data) => { -// console.log(`stderr: ${data}`); -// scanLock = false; -// -// }); -// -// cmd.on('close', (code) => { -// console.log(`child process exited with code ${code}`); -// hashFileBeets(); -// -// // TODO: Remove all empty dirs -// }); -// }); -// -// -// function hashFileBeets(){ -// // var hashCmd = spawn('beet check -a'); -// var hashCmd = spawn('beet', [ 'check', '-a']); -// -// -// hashCmd.stdout.on('data', (data) => { -// console.log(`stdout: ${data}`); -// }); -// -// hashCmd.stderr.on('data', (data) => { -// console.log(`stderr: ${data}`); -// scanLock = false; -// -// }); -// -// hashCmd.on('close', (code) => { -// console.log(`child process exited with code ${code}`); -// scanLock = false; -// -// }); -// } -// -// // TODO: Function that will remove all empty folders -// function removeEmptyFolders(){ -// var hashCmd = spawn('beet', [ 'check', '-a']); -// // 'find ~ -type d -empty -delete' -// } -// -// -// -// mstream.get('/db/status-beets', function(req, res){ -// var returnObject = {}; -// -// returnObject.locked = scanLock; -// -// -// if(scanLock){ -// -// // Currently we don't support filecount stats when using beets DB -// // Dummy data -// returnObject.totalFileCount = 0; -// returnObject.filesLeft = 0; -// -// -// res.json(returnObject); -// -// }else{ -// var sql = 'SELECT Count(*) FROM items'; -// -// db.get(sql, function(err, row){ -// if(err){ -// console.log(err.message); -// -// res.status(500).json({ error: err.message }); -// return; -// } -// -// -// var fileCountDB = row['Count(*)']; // TODO: Is this correct??? -// -// returnObject.totalFileCount = fileCountDB; -// res.json(returnObject); -// -// }); -// } -// -// }); -// -// -// } diff --git a/modules/db-management/database-master.js b/modules/db-management/database-master.js index ed36d7f..95ebfde 100644 --- a/modules/db-management/database-master.js +++ b/modules/db-management/database-master.js @@ -50,12 +50,17 @@ exports.setup = function(mstream, program){ /////////////////////////// // TODO: We could use some kind of manager to make sure we don't spawn to many child processes - // For know we spawn indiscriminately and let the CPU sort it out + // For now we spawn indiscriminately and let the CPU sort it out /////////////////////////// // TODO: Fill this out function forkBeets(user, publicDBType, dbSettings){ + // Pull beets commands from config + // Run commands + // beet import -A --group-albums /path/to/music + // beet check -a + // find ~ -type d -empty -delete } function forkDefault(user, dbSettings){ @@ -81,8 +86,6 @@ exports.setup = function(mstream, program){ userDBStatus[user.username] = false; console.log(`child process exited with code ${code}`); }); - - // TODO: Need to make an on error } @@ -98,25 +101,7 @@ exports.setup = function(mstream, program){ // TODO: Handle user status mstream.get('/db/status-mstream', function(req, res){ + res.send('Coming Soon!'); }); - - - - - - - - - -// TODO: Load any plugins necessary for habdling indivudal user dbs - // Then construct routing between api calls and userDB management functions - - - // TODO: Handle Specialized DB Functions - // mstream.get('/db/download-db', function(req, res){ - // }); - // mstream.get( '/db/hash', function(req, res){ - // }); - } diff --git a/modules/db-read/database-public-sqlite.js b/modules/db-read/database-public-sqlite.js index 2fdda92..2ba09d4 100644 --- a/modules/db-read/database-public-sqlite.js +++ b/modules/db-read/database-public-sqlite.js @@ -1,6 +1,7 @@ const sqlite3 = require('sqlite3').verbose(); const slash = require('slash'); const fe = require('path'); +const crypto = require('crypto'); @@ -266,4 +267,38 @@ exports.setup = function(mstream, dbSettings){ }); }); + mstream.get('/db/download-db', function(req, res){ + // Check user for beets db + if(!req.user.privateDB || req.user.privateDB != 'BEETS'){ + res.status(500).json({ error: 'DB Error' }); + return; + } + + // Download File + res.download(req.user.privateDBOptions.importDB); + }); + + + // Get hash of database + // TODO: Change the name of this endpoint + mstream.get( '/db/hash', function(req, res){ + // Check if user is using beets + if(!req.user.privateDB || req.user.privateDB != 'BEETS'){ + res.status(500).json({ error: 'DB Error' }); + return; + } + + var hash = crypto.createHash('sha256'); + hash.setEncoding('hex'); + + var fileStream = fs.createReadStream(req.user.privateDBOptions.importDB); + fileStream.on('end', function () { + hash.end(); + res.json( {hash:String(hash.read())} ); + }); + + fileStream.pipe(hash, { end: false }); + }); + + } diff --git a/modules/db-write/database-default-sqlite.js b/modules/db-write/database-default-sqlite.js index eb6b663..bf59c39 100644 --- a/modules/db-write/database-default-sqlite.js +++ b/modules/db-write/database-default-sqlite.js @@ -22,17 +22,12 @@ exports.getUserFiles = function(thisUser, callback){ exports.insertEntries = function(arrayOfSongs, username, callback){ - // TODO: Update SQL var sql2 = "insert into items (title,artist,year,album,path,format, track, disk, user, filesize, file_modified_date, file_created_date) values "; var sqlParser = []; - console.log(arrayOfSongs); - while(arrayOfSongs.length > 0) { var song = arrayOfSongs.pop(); - - var songTitle = null; var songYear = null; var songAlbum = null;