mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
Code cleanup
This commit is contained in:
parent
cefefffaa4
commit
e952357eae
@ -20,7 +20,7 @@ exports.setup = function(args){
|
||||
loadJson.userinterface = "public";
|
||||
}
|
||||
|
||||
|
||||
// TODO; Preform a full range of checks
|
||||
|
||||
// Export JSON
|
||||
return loadJson;
|
||||
|
||||
@ -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);
|
||||
//
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
//
|
||||
// }
|
||||
@ -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){
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user