remove song

This commit is contained in:
Paul Sori 2018-10-09 22:20:21 -04:00
parent 1ca70ebbd0
commit d99ea7a4ea
7 changed files with 116 additions and 101 deletions

View File

@ -20,7 +20,7 @@ function getAllArtistsForUser(user) {
}
}
artists.sort(function (a, b) {
artists.sort((a, b) => {
return a.localeCompare(b);
});
}
@ -52,7 +52,7 @@ function getAllAlbumsForUser(user) {
}
function loadDB() {
filesdb.loadDatabase({}, function (err) {
filesdb.loadDatabase({}, err => {
if (err) {
winston.error(`DB Load Error : ${err}`);
}
@ -91,7 +91,7 @@ exports.setup = function (mstream, program) {
filesdb = new loki(program.database_plugin.dbPath);
// Used to determine the user has a working login token
mstream.get('/ping', function (req, res) {
mstream.get('/ping', (req, res) => {
const playlists = getPlaylists(req.user.username);
res.json({
vpaths: req.user.vpaths,
@ -100,8 +100,8 @@ exports.setup = function (mstream, program) {
});
// Metadata lookup
mstream.post('/db/metadata', function (req, res) {
var pathInfo = program.getVPathInfo(req.body.filepath);
mstream.post('/db/metadata', (req, res) => {
const pathInfo = program.getVPathInfo(req.body.filepath);
if (pathInfo === false) {
res.status(500).json({ error: 'Could not find file' });
return;
@ -112,7 +112,7 @@ exports.setup = function (mstream, program) {
return;
}
var result = fileCollection.findOne({ 'filepath': pathInfo.fullPath });
const result = fileCollection.findOne({ 'filepath': pathInfo.fullPath });
if (!result) {
res.json({ "filepath": pathInfo.relativePath, "metadata": {} });
return;
@ -132,7 +132,7 @@ exports.setup = function (mstream, program) {
});
});
mstream.post('/playlist/add-song', function (req, res) {
mstream.post('/playlist/add-song', (req, res) => {
if(!req.body.song || !req.body.playlist) {
return res.status(500).json({ error: 'Missing Params' });
}
@ -145,19 +145,30 @@ exports.setup = function (mstream, program) {
});
res.json({ success: true });
// Save the DB
filesdb.saveDatabase(function (err) {
filesdb.saveDatabase(err => {
if (err) {
winston.error(`DB Save Error : ${err}`);
}
});
});
mstream.post('/playlist/remove-song', (req, res) => {
if (!req.body.lokiid){
return res.status(500).json({ error: 'Missing Params' });
}
playlistColection.findAndRemove({ '$loki': req.body.lokiid });
res.json({ success: true });
filesdb.saveDatabase(err => {
if (err) {
winston.error(`BB Save Error : ${err}`)
}
});
});
// Save playlists
mstream.post('/playlist/save', function (req, res) {
var title = req.body.title;
var songs = req.body.songs;
mstream.post('/playlist/save', (req, res) => {
const title = req.body.title;
const songs = req.body.songs;
// Delete existing playlist
playlistColection.findAndRemove({
@ -170,7 +181,7 @@ exports.setup = function (mstream, program) {
while (songs.length > 0) {
var song = songs.shift();
const song = songs.shift();
playlistColection.insert({
name: title,
filepath: song,
@ -180,9 +191,7 @@ exports.setup = function (mstream, program) {
}
res.json({ success: true });
// Save the DB
filesdb.saveDatabase(function (err) {
filesdb.saveDatabase(err => {
if (err) {
winston.error(`DB Save Error : ${err}`);
}
@ -190,15 +199,15 @@ exports.setup = function (mstream, program) {
});
// Get all playlists
mstream.get('/playlist/getall', function (req, res) {
mstream.get('/playlist/getall', (req, res) => {
res.json(getPlaylists(req.user.username));
});
function getPlaylists(username) {
var playlists = [];
const playlists = [];
var results = playlistColection.find({ 'user': { '$eq': username } });
var store = [];
const results = playlistColection.find({ 'user': { '$eq': username } });
const store = [];
for (let row of results) {
if (store.indexOf(row.name) === -1) {
playlists.push({ name: row.name });
@ -209,11 +218,11 @@ exports.setup = function (mstream, program) {
}
// Load a playlist
mstream.post('/playlist/load', function (req, res) {
var playlist = req.body.playlistname;
var returnThis = [];
mstream.post('/playlist/load', (req, res) => {
const playlist = req.body.playlistname;
const returnThis = [];
var results = playlistColection.find({
const results = playlistColection.find({
'$and': [{
'user': { '$eq': req.user.username }
}, {
@ -223,11 +232,11 @@ exports.setup = function (mstream, program) {
for (let row of results) {
// Look up metadata
var pathInfo = program.getVPathInfo(row.filepath);
const pathInfo = program.getVPathInfo(row.filepath);
var metadata = {};
if (fileCollection) {
var result = fileCollection.findOne({ 'filepath': pathInfo.fullPath });
const result = fileCollection.findOne({ 'filepath': pathInfo.fullPath });
if (result) {
metadata = {
"artist": result.artist ? result.artist : '',
@ -242,15 +251,15 @@ exports.setup = function (mstream, program) {
}
}
returnThis.push({ filepath: row.filepath, metadata: metadata });
returnThis.push({ lokiId: row['$loki'], filepath: row.filepath, metadata: metadata });
}
res.json(returnThis);
});
// Delete playlist
mstream.post('/playlist/delete', function (req, res) {
var playlistname = req.body.playlistname;
mstream.post('/playlist/delete', (req, res) => {
const playlistname = req.body.playlistname;
// Delete existing playlist
playlistColection.findAndRemove({
@ -264,12 +273,12 @@ exports.setup = function (mstream, program) {
res.json({ success: true });
});
mstream.get('/db/artists', function (req, res) {
mstream.get('/db/artists', (req, res) => {
var artists = { "artists": getAllArtistsForUser(req.user) };
res.json(artists);
});
mstream.post('/db/artists-albums', function (req, res) {
mstream.post('/db/artists-albums', (req, res) => {
var albums = { "albums": [] };
if (fileCollection !== null) {
var orClause;
@ -304,13 +313,13 @@ exports.setup = function (mstream, program) {
res.json(albums);
});
mstream.get('/db/albums', function (req, res) {
mstream.get('/db/albums', (req, res) => {
var albums = { "albums": getAllAlbumsForUser(req.user) };
res.json(albums);
});
// TODO: validate input, allow to search albums by LokiID
mstream.post('/db/album-songs', function (req, res) {
mstream.post('/db/album-songs', (req, res) => {
var songs = [];
if (fileCollection !== null) {
var orClause;
@ -355,7 +364,7 @@ exports.setup = function (mstream, program) {
res.json(songs);
});
mstream.post('/db/rate-song', function (req, res) {
mstream.post('/db/rate-song', (req, res) => {
if (!req.body.filepath || !req.body.rating || !Number.isInteger(req.body.rating) || req.body.rating < 0 || req.body.rating > 10) {
res.status(500).json({ error: 'Bad input data' });
}
@ -393,7 +402,7 @@ exports.setup = function (mstream, program) {
res.status(444).json({ error: 'Coming Soon!' });
});
mstream.post('/db/random-songs', function (req, res) {
mstream.post('/db/random-songs', (req, res) => {
if (!fileCollection) {
res.status(500).json({ error: 'File not found in DB' });
return;
@ -471,13 +480,11 @@ exports.setup = function (mstream, program) {
ignoreList.push(randomNumber);
returnThis.ignoreList = ignoreList;
res.json(returnThis);
});
mstream.get('/db/get-rated', function (req, res) {
mstream.get('/db/get-rated', (req, res) => {
var songs = [];
if (fileCollection == null) {
res.json(songs);

View File

@ -186,7 +186,7 @@ exports.serveit = function (program) {
// Start the server!
// TODO: Check if port is in use before firing up server
server.on('request', mstream);
server.listen(program.port, function () {
server.listen(program.port, () => {
let protocol = program.ssl && program.ssl.cert && program.ssl.key ? 'https' : 'http';
exports.addresses.local = protocol + '://localhost:' + program.port;
winston.info(`Access mStream locally: ${exports.addresses.local}`);

View File

@ -148,31 +148,14 @@ div#jp_container_N {
.dirz {
padding: 10px; }
.deletePlaylist{
width: 29px !important;
height: 33px;
background-color: rgba(255,0,0, .7);
float: right;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 3px 10px 0 rgba(0, 0, 0, 0.19);
text-align: center;
font-size: 28px;
text-shadow: 0 1px darkred;
padding-bottom: 5px;
font-family: "Arial Black", Gadget, sans-serif;
opacity: 0.9;
}
.deletePlaylist:hover{
opacity: 1;
background-color: rgba(255,0,0, .85);
}
.playlistz{
display: block;
padding: 10px;
width: calc(100% - 29px);
width: 100%;
float: left;
}
.left {
float: left;
}

View File

@ -100,7 +100,6 @@
.song-button-box{
position: absolute;
top:0;
right: 0;
}
@ -181,23 +180,31 @@
background-color: #E6EBFA;
}
.removeSong{
width: 28px !important;
.removeSong, .deletePlaylist, .removePlaylistSong{
padding-top: 1px;
cursor: pointer;
min-width: 28px !important;
height: 14px;
background-color: rgba(255,0,0, .7);
float: right;
text-align: center;
font-size: 12px;
text-shadow: 0 1px darkred;
font-family: "Arial Black", Gadget, sans-serif;
opacity: 0.9;
}
.removeSong:hover{
.removeSong:hover, .deletePlaylist:hover, .removePlaylistSong:hover{
opacity: 1;
background-color: rgba(255,0,0, .85);
}
.deletePlaylist, .removePlaylistSong {
padding-left: 7px;
padding-right: 7px;
padding-top: 1px;
border-bottom-left-radius: 3px;
}
.song-area{
display: block;
width: calc(100% - 26px);

View File

@ -67,6 +67,10 @@ var MSTREAMAPI = (function () {
makePOSTRequest('/playlist/delete', { playlistname: playlistname }, callback);
}
mstreamModule.removePlaylistSong = function (lokiId, callback) {
makePOSTRequest('/playlist/remove-song', { lokiid: lokiId }, callback);
}
mstreamModule.loadPlaylist = function (playlistname, callback) {
makePOSTRequest('/playlist/load', { playlistname: playlistname }, callback);
}

View File

@ -417,7 +417,7 @@ $(document).ready(function () {
if (this.type === 'directory') {
filelist.push('<div data-directory="' + this.name + '" class="dirz"><img class="folder-image" src="public/img/folder.svg"><span class="item-text">' + this.name + '</span></div>');
} else if (this.type === 'playlist') {
filelist.push('<div data-playlistname="' + this.name + '" class="playlist_row_container"><span data-playlistname="' + this.name + '" class="playlistz force-width">' + this.name + '</span><span data-playlistname="' + this.name + '" class="deletePlaylist">x</span></div>');
filelist.push('<div data-playlistname="' + this.name + '" class="playlist_row_container"><span data-playlistname="' + this.name + '" class="playlistz force-width">' + this.name + '</span><div class="song-button-box"><span data-playlistname="' + this.name + '" class="deletePlaylist">Delete</span></div></div>');
} else if (this.type === 'album') {
if (this.album_art_file) {
filelist.push('<div data-album="' + this.name + '" class="albumz"><img class="album-art-box" data-original="/album-art/' + this.album_art_file + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + this.name + '</span></div>');
@ -565,7 +565,7 @@ $(document).ready(function () {
// loop through the json array and make an array of corresponding divs
var playlists = [];
$.each(response, function () {
playlists.push('<div data-playlistname="' + this.name + '" class="playlist_row_container"><span data-playlistname="' + this.name + '" class="playlistz force-width">' + this.name + '</span><span data-playlistname="' + this.name + '" class="deletePlaylist">x</span></div>');
playlists.push('<div data-playlistname="' + this.name + '" class="playlist_row_container"><span data-playlistname="' + this.name + '" class="playlistz force-width">' + this.name + '</span><div class="song-button-box"><span data-playlistname="' + this.name + '" class="deletePlaylist">Delete</span></div></div>');
this.type = 'playlist';
currentBrowsingList.push(this);
VUEPLAYER.playlists.push(this);
@ -577,15 +577,42 @@ $(document).ready(function () {
// delete playlist
$("#filelist").on('click', '.deletePlaylist', function () {
// Get Playlist ID
var playlistname = $(this).data('playlistname');
var that = this;
MSTREAMAPI.deletePlaylist(playlistname, function (response, error) {
iziToast.question({
timeout: 10000,
close: false,
overlayClose: true,
overlay: true,
displayMode: 'once',
id: 'question',
zindex: 99999,
title: "Delete '" + playlistname + "'?",
position: 'center',
buttons: [
['<button><b>Delete</b></button>', function (instance, toast) {
MSTREAMAPI.deletePlaylist(playlistname, function (response, error) {
if (error !== false) {
return boilerplateFailure(response, error);
}
$('div[data-playlistname="'+playlistname+'"]').remove();
});
instance.hide({ transitionOut: 'fadeOut' }, toast, 'button');
}, true],
['<button>Go Back</button>', function (instance, toast) {
instance.hide({ transitionOut: 'fadeOut' }, toast, 'button');
}],
]
});
});
$("#filelist").on('click', '.removePlaylistSong', function () {
var lokiId = $(this).data('lokiid');
MSTREAMAPI.removePlaylistSong(lokiId, function (response, error) {
if (error !== false) {
return boilerplateFailure(response, error);
}
$(that).parent().remove();
$('div[data-lokiid="' + lokiId + '"]').remove();
});
});
@ -614,16 +641,15 @@ $(document).ready(function () {
//parse through the json array and make an array of corresponding divs
var files = [];
$.each(response, function (index, value) {
if (!value.metadata || !value.metadata.title) {
currentBrowsingList.push({ type: 'file', name: value.filepath, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" src="/public/img/default.png"><span class="explorer-label-1">' + value.filepath + '</span></div>');
files.push('<div data-lokiid="'+value.lokiId+'" class="clear"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" src="/public/img/default.png"><span class="explorer-label-1">' + value.filepath + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
} else if (value.metadata['album-art']) {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" data-original="/album-art/' + value.metadata['album-art'] + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div>');
files.push('<div data-lokiid="'+value.lokiId+'" class="clear"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" data-original="/album-art/' + value.metadata['album-art'] + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
} else {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" src="/public/img/default.png"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div>');
files.push('<div data-lokiid="'+value.lokiId+'" class="clear"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" src="/public/img/default.png"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
}
});

View File

@ -72,7 +72,7 @@
var path = window.location.pathname;
var uuid = path.split("/").pop();
// // Call Server
// Call Server
var request = $.ajax({
url: "/shared/get-token-and-playlist",
type: "POST",
@ -81,41 +81,29 @@
data: JSON.stringify({ tokenid: uuid })
});
//
request.done(function (msg) {
var playlist = msg.playlist;
// Get playlist
for (var i = 0; i < playlist.length; i++) {
MSTREAMPLAYER.addSong(
{
url: '/media/' + playlist[i] + '?token=' + msg.token,
filepath: playlist[i],
metadata: {
"artist": "",
"album": "",
"track": "",
"title": "",
"year": "",
"album-art": ""
}
MSTREAMPLAYER.addSong({
url: '/media/' + playlist[i] + '?token=' + msg.token,
filepath: playlist[i],
metadata: {
"artist": "",
"album": "",
"track": "",
"title": "",
"year": "",
"album-art": ""
}
);
});
}
// Add playlist to mstream
});
request.fail(function (jqXHR, textStatus) {
// TODO: Alert user
});
}
</script>
</head>
<body>