diff --git a/src/api/playlist.js b/src/api/playlist.js
index 63fc740..bd49d24 100644
--- a/src/api/playlist.js
+++ b/src/api/playlist.js
@@ -30,7 +30,7 @@ exports.setup = (mstream) => {
}
try {
- if (!db.getPlaylistCollection()) { throw 'DB Error'; }
+ if (!db.getPlaylistCollection()) { throw new Error('DB Error'); }
db.getPlaylistCollection().findAndRemove({
'$and': [
@@ -60,7 +60,7 @@ exports.setup = (mstream) => {
}
try {
- if (!db.getPlaylistCollection()) { throw 'No DB'; }
+ if (!db.getPlaylistCollection()) { throw new Error('No DB'); }
db.getPlaylistCollection().insert({
name: req.body.playlist,
filepath: req.body.song,
@@ -84,8 +84,13 @@ exports.setup = (mstream) => {
}
try {
- if (!db.getPlaylistCollection()) { throw 'No DB'; }
- db.getPlaylistCollection().findAndRemove({ '$loki': req.body.lokiid });
+ if (!db.getPlaylistCollection()) { throw new Error('No DB'); }
+ const result = db.getPlaylistCollection().get(req.body.lokiid);
+ if (result.user !== req.user.username) {
+ throw new Error(`User ${req.user.username} tried accessing a resource they don't have access to. Playlist Loki ID: ${req.body.lokiid}`);
+ }
+
+ db.getPlaylistCollection().remove(result);
res.json({});
db.saveUserDB();
}catch (err) {
diff --git a/webapp/assets/js/mstream.js b/webapp/assets/js/mstream.js
index 4f91e69..e24e3dd 100644
--- a/webapp/assets/js/mstream.js
+++ b/webapp/assets/js/mstream.js
@@ -131,7 +131,7 @@ function renderFileWithMetadataHtml(filepath, lokiId, metadata) {
${(!metadata || !metadata.title) ? filepath : `${metadata.artist} - ${metadata.title}`}
@@ -395,14 +404,7 @@ function getAllPlaylists(previousState, el) {
// loop through the json array and make an array of corresponding divs
let playlists = '';
response.forEach(p => {
- console.log(p)
- playlists +=
- `
-
${escapeHtml(p.name)}
-
- Delete
-
-
`;
+ playlists += renderPlaylist(p.name);
const lol = { name: p.name, type: 'playlist' };
currentBrowsingList.push(lol);
VUEPLAYER.playlists.push(lol);
@@ -451,6 +453,65 @@ function deletePlaylist(el) {
});
}
+function onPlaylistClick(el) {
+ var playlistname = decodeURIComponent(el.getAttribute('data-playlistname'));
+ document.getElementById('directoryName').innerHTML = 'Playlist: ' + playlistname;
+ document.getElementById('filelist').innerHTML = getLoadingSvg();
+ currentBrowsingList = [];
+
+ programState.push({
+ state: 'playlist',
+ name: playlistname,
+ previousScroll: document.getElementById('filelist').scrollTop,
+ previousSearch: $('#search_folders').val()
+ });
+ document.getElementById('search_folders').value = '';
+
+ MSTREAMAPI.loadPlaylist(playlistname, (response, error) => {
+ if (error !== false) {
+ document.getElementById('filelist').innerHTML = '
Server call failed
';
+ return boilerplateFailure(response, error);
+ }
+
+ // Add the playlist name to the modal
+ document.getElementById('playlist_name').value = playlistname;
+
+ let files = '';
+ response.forEach(value => {
+ currentBrowsingList.push({
+ type: 'file',
+ name: (!value.metadata || !value.metadata.title) ? value.filepath : `${value.metadata.artist} - ${value.metadata.title}`,
+ metadata: value.metadata,
+ filepath: value.filepath,
+ lokiId: value.lokiId
+ });
+
+ files += renderFileWithMetadataHtml(value.filepath, value.lokiId, value.metadata);
+ });
+
+ document.getElementById('filelist').innerHTML = files;
+
+ // update lazy load plugin
+ ll.update();
+ });
+}
+
+function removePlaylistSong(el) {
+ const lokiId = el.getAttribute('data-lokiid');
+ MSTREAMAPI.removePlaylistSong(lokiId, (response, error) => {
+ if (error !== false) {
+ return boilerplateFailure(response, error);
+ }
+
+ // remove from currentBrowsingList
+ currentBrowsingList = currentBrowsingList.filter(item =>{
+ return item.lokiId !== lokiId
+ });
+
+ document.querySelector(`div[data-lokiid="${lokiId}"]`).remove();
+ });
+}
+
/////////////// Artists
function getAllArtists(previousState, el) {
setBrowserRootPanel(el, 'Artists', 'scrollBoxHeight1');
@@ -1173,7 +1234,7 @@ $(document).ready(function () {
if (this.type === 'directory') {
filelist.push(renderDirHtml(this.name));
} else if (this.type === 'playlist') {
- filelist.push('
' + escapeHtml(this.name) + ' Delete
');
+ filelist.push(renderPlaylist(this.name));
} else if (this.type === 'album') {
var artistString = this.artist ? 'data-artist="' + this.artist + '"' : '';
var albumString = this.name ? this.name : 'SINGLES';
@@ -1320,67 +1381,6 @@ $(document).ready(function () {
});
});
- $("#filelist").on('click', '.removePlaylistSong', function () {
- const lokiId = $(this).data('lokiid');
- MSTREAMAPI.removePlaylistSong(lokiId, function (response, error) {
- if (error !== false) {
- return boilerplateFailure(response, error);
- }
-
- // remove from currentBrowsingList
- currentBrowsingList = currentBrowsingList.filter(item =>{
- return item.lokiId !== lokiId
- });
-
- $('div[data-lokiid="' + lokiId + '"]').remove();
- });
- });
-
- // load up a playlist
- $("#filelist").on('click', '.playlistz', function () {
- var playlistname = decodeURIComponent($(this).data('playlistname'));
- var name = $(this).html();
- $('.directoryName').html('Playlist: ' + name);
- $('#filelist').html('
');
- currentBrowsingList = [];
-
- programState.push({
- state: 'playlist',
- name: playlistname,
- previousScroll: document.getElementById('filelist').scrollTop,
- previousSearch: $('#search_folders').val()
- });
- $('#search_folders').val('');
-
-
- MSTREAMAPI.loadPlaylist(playlistname, (response, error) => {
- if (error !== false) {
- $('#filelist').html('
Server call failed
');
- return boilerplateFailure(response, error);
- }
-
- // Add the playlist name to the modal
- $('#playlist_name').val(name);
-
- const files = [];
- response.forEach(value => {
- currentBrowsingList.push({
- type: 'file',
- name: (!value.metadata || !value.metadata.title) ? value.filepath : `${value.metadata.artist} - ${value.metadata.title}`,
- metadata: value.metadata,
- filepath: value.filepath,
- lokiId: value.lokiId
- });
-
- files.push(renderFileWithMetadataHtml(value.filepath, value.lokiId, value.metadata));
- });
-
- $('#filelist').html(files);
- // update lazy load plugin
- ll.update();
- });
- });
-
/////////////// Download Playlist
$('#downloadPlaylist').click(function () {
// Loop through array and add each file to the playlist