directory management bugfixes and optimizations

This commit is contained in:
IrosTheBeggar 2019-11-01 00:11:07 -04:00
parent 73c27d0d7e
commit b2b4157e8d
3 changed files with 37 additions and 39 deletions

View File

@ -6,7 +6,16 @@ const winston = require('winston');
const mkdirp = require('make-dir');
const m3u8Parser = require('m3u8-parser');
const masterFileTypesArray = ["mp3", "flac", "wav", "ogg", "aac", "m4a", "opus", "m3u"];
const masterFileTypes = {
"mp3": true,
"flac": true,
"wav": true,
"ogg": true,
"aac": true,
"m4a": true,
"opus": true,
"m3u": false
}
exports.setup = function(mstream, program) {
@ -201,13 +210,6 @@ exports.setup = function(mstream, program) {
return;
}
var fileTypesArray;
if (req.body.filetypes) {
fileTypesArray = req.body.filetypes;
} else {
fileTypesArray = masterFileTypesArray;
}
// get directory contents
const files = fs.readdirSync(pathInfo.fullPath);
@ -229,7 +231,7 @@ exports.setup = function(mstream, program) {
} else {
// Handle Files
const extension = getFileType(files[i]).toLowerCase();
if (fileTypesArray.indexOf(extension) > -1 && masterFileTypesArray.indexOf(extension) > -1) {
if (extension in masterFileTypes) {
filesArray.push({
type: extension,
name: files[i]
@ -280,14 +282,6 @@ exports.setup = function(mstream, program) {
return;
}
// Will only show these files. Prevents people from snooping around
var fileTypesArray;
if (req.body.filetypes) {
fileTypesArray = req.body.filetypes;
} else {
fileTypesArray = masterFileTypesArray;
}
const recursiveTrot = function(dir, filelist, relativePath) {
const files = fs.readdirSync(dir);
files.forEach(file => {
@ -302,8 +296,8 @@ exports.setup = function(mstream, program) {
recursiveTrot(fe.join(dir, file), filelist, fe.join(relativePath, file));
} else {
const extension = getFileType(file).toLowerCase();
if (fileTypesArray.indexOf(extension) > -1 && masterFileTypesArray.indexOf(extension) > -1) {
filelist.push(fe.join(pathInfo.vpath, fe.join(relativePath, file)));
if (masterFileTypes[extension] === true) {
filelist.push(fe.join(pathInfo.vpath, fe.join(relativePath, file)).replace(/\\/g, "/"));
}
}
});

View File

@ -53,7 +53,7 @@ var MSTREAMAPI = (function () {
makePOSTRequest('/fileplaylist/loadpaths', { path }, callback);
}
mstreamModule.recursiveScan = function (directory, filetypes, callback) {
mstreamModule.recursiveScan = function (directory, callback) {
makePOSTRequest('/files/recursive-scan', { dir: directory }, callback);
}

View File

@ -176,7 +176,7 @@ $(document).ready(function () {
});
myDropzone.removeFile(file);
} else {
file.directory = getFileExplorerPath(fileExplorerArray) + file.fullPath.substring(0, file.fullPath.indexOf(file.name));
file.directory = getFileExplorerPath() + file.fullPath.substring(0, file.fullPath.indexOf(file.name));
}
});
@ -471,9 +471,9 @@ $(document).ready(function () {
previousScroll: document.getElementById('filelist').scrollTop,
previousSearch: $('#search_folders').val()
});
var directoryString = getFileExplorerPath(fileExplorerArray);
var directoryString = getFileExplorerPath();
$('.directoryName').html('/' + directoryString);
$('.directoryName').html('/' + directoryString.substring(0, directoryString.length - 1));
$('#filelist').html('<div class="loading-screen"><svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"><circle class="spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div>');
MSTREAMAPI.loadFileplaylist(directoryString, function (response, error) {
@ -495,8 +495,6 @@ $(document).ready(function () {
var thisState = programState.pop();
var backState = programState[programState.length - 1];
console.log(thisState)
if (backState.state === 'allPlaylists') {
getAllPlaylists(thisState);
} else if (backState.state === 'allAlbums') {
@ -514,9 +512,14 @@ $(document).ready(function () {
// send a new directory to be parsed.
function senddir(previousState) {
// Construct the directory string
var directoryString = getFileExplorerPath(fileExplorerArray);
var directoryString = getFileExplorerPath();
$('.directoryName').html('/' + directoryString);
var displayString = directoryString;
if (displayString.substring(0, 1) !== '/') {
displayString = '/' + displayString;
}
$('.directoryName').html(displayString);
$('#filelist').html('<div class="loading-screen"><svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"><circle class="spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div>');
MSTREAMAPI.dirparser(directoryString, false, function (response, error) {
@ -617,7 +620,7 @@ $(document).ready(function () {
} else if (this.type == "m3u") {
filelist.push(createFileplaylistHtml(this.name));
} else {
const fileLocation = this.path || getFileExplorerPath(fileExplorerArray) + this.name;
const fileLocation = this.path || getFileExplorerPath() + this.name;
const title = this.artist != null || this.title != null ? this.artist + ' - ' + this.title : this.name;
filelist.push(createMusicfileHtml(fileLocation, title, "title"));
}
@ -644,12 +647,17 @@ $(document).ready(function () {
}
});
function getFileExplorerPath(explorerArray) {
return explorerArray.join("/") + "/";
function getFileExplorerPath() {
return fileExplorerArray.join("/") + "/";
}
function getDirectoryString(component) {
return "/" + getFileExplorerPath(fileExplorerArray) + component.data("directory");
var newString = getFileExplorerPath() + component.data("directory");
if (newString.substring(0,1) !== '/') {
newString = "/" + newString
}
return newString;
}
function addAllSongs(res) {
@ -660,7 +668,10 @@ $(document).ready(function () {
$("#filelist").on('click', '.recursiveAddDir', function () {
var directoryString = getDirectoryString($(this));
MSTREAMAPI.recursiveScan(directoryString, false, function(res, err){
MSTREAMAPI.recursiveScan(directoryString, function(res, err) {
if (err !== false) {
return boilerplateFailure(res, err);
}
addAllSongs(res);
});
});
@ -1412,7 +1423,6 @@ $(document).ready(function () {
});
$('body').on('click', '.get-federation-stats', function() {
console.log('CLICK')
MSTREAMAPI.getFederationStats( function(res,err){
console.log(res);
});
@ -1470,7 +1480,6 @@ $(document).ready(function () {
var newHtml = '<p>Select and name folders you want to federate:</p>';
try {
var decoded = jwt_decode(e.target.value);
console.log(decoded);
if (fedTokenCache === decoded.iat) {
return;
}
@ -1493,16 +1502,11 @@ $(document).ready(function () {
var decoded = jwt_decode($('#federation-invitation-code').val());
Object.keys(decoded.vPaths).forEach(function(key) {
console.log(decoded.vPaths[key])
console.log($("#" + decoded.vPaths[key]).val())
console.log($("input[type=checkbox][value="+decoded.vPaths[key]+"]").is(":checked"))
if($("input[type=checkbox][value="+decoded.vPaths[key]+"]").is(":checked")){
folderNames[key] = $("#" + decoded.vPaths[key]).val();
}
});
console.log(folderNames);
if (Object.keys(folderNames).length === 0) {
iziToast.error({
title: 'No directories selected',