|
@@ -1,4 +1,5 @@
|
|
import async from "async";
|
|
import async from "async";
|
|
|
|
+import config from "config";
|
|
|
|
|
|
import { isAdminRequired, isLoginRequired } from "./hooks";
|
|
import { isAdminRequired, isLoginRequired } from "./hooks";
|
|
|
|
|
|
@@ -10,39 +11,122 @@ const WSModule = moduleManager.modules.ws;
|
|
const CacheModule = moduleManager.modules.cache;
|
|
const CacheModule = moduleManager.modules.cache;
|
|
const SongsModule = moduleManager.modules.songs;
|
|
const SongsModule = moduleManager.modules.songs;
|
|
const ActivitiesModule = moduleManager.modules.activities;
|
|
const ActivitiesModule = moduleManager.modules.activities;
|
|
|
|
+const YouTubeModule = moduleManager.modules.youtube;
|
|
const PlaylistsModule = moduleManager.modules.playlists;
|
|
const PlaylistsModule = moduleManager.modules.playlists;
|
|
|
|
|
|
CacheModule.runJob("SUB", {
|
|
CacheModule.runJob("SUB", {
|
|
- channel: "song.removed",
|
|
|
|
|
|
+ channel: "song.newUnverifiedSong",
|
|
|
|
+ cb: async songId => {
|
|
|
|
+ const songModel = await DBModule.runJob("GET_MODEL", {
|
|
|
|
+ modelName: "song"
|
|
|
|
+ });
|
|
|
|
+ songModel.findOne({ _id: songId }, (err, song) => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.unverifiedSongs",
|
|
|
|
+ args: ["event:admin.unverifiedSong.added", song]
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.removedUnverifiedSong",
|
|
cb: songId => {
|
|
cb: songId => {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
- room: "admin.songs",
|
|
|
|
- args: ["event:admin.song.removed", songId]
|
|
|
|
|
|
+ room: "admin.unverifiedSongs",
|
|
|
|
+ args: ["event:admin.unverifiedSong.removed", songId]
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.updatedUnverifiedSong",
|
|
|
|
+ cb: async songId => {
|
|
|
|
+ const songModel = await DBModule.runJob("GET_MODEL", {
|
|
|
|
+ modelName: "song"
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ songModel.findOne({ _id: songId }, (err, song) => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.unverifiedSongs",
|
|
|
|
+ args: ["event:admin.unverifiedSong.updated", song]
|
|
|
|
+ });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
CacheModule.runJob("SUB", {
|
|
CacheModule.runJob("SUB", {
|
|
- channel: "song.added",
|
|
|
|
|
|
+ channel: "song.newVerifiedSong",
|
|
cb: async songId => {
|
|
cb: async songId => {
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
|
|
songModel.findOne({ songId }, (err, song) => {
|
|
songModel.findOne({ songId }, (err, song) => {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
room: "admin.songs",
|
|
room: "admin.songs",
|
|
- args: ["event:admin.song.added", song]
|
|
|
|
|
|
+ args: ["event:admin.verifiedSong.added", song]
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
CacheModule.runJob("SUB", {
|
|
CacheModule.runJob("SUB", {
|
|
- channel: "song.updated",
|
|
|
|
|
|
+ channel: "song.removedVerifiedSong",
|
|
|
|
+ cb: songId => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.songs",
|
|
|
|
+ args: ["event:admin.verifiedSong.removed", songId]
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.updatedVerifiedSong",
|
|
cb: async songId => {
|
|
cb: async songId => {
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
|
|
songModel.findOne({ songId }, (err, song) => {
|
|
songModel.findOne({ songId }, (err, song) => {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
WSModule.runJob("EMIT_TO_ROOM", {
|
|
room: "admin.songs",
|
|
room: "admin.songs",
|
|
- args: ["event:admin.song.updated", song]
|
|
|
|
|
|
+ args: ["event:admin.verifiedSong.updated", song]
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.newHiddenSong",
|
|
|
|
+ cb: async songId => {
|
|
|
|
+ const songModel = await DBModule.runJob("GET_MODEL", {
|
|
|
|
+ modelName: "song"
|
|
|
|
+ });
|
|
|
|
+ songModel.findOne({ _id: songId }, (err, song) => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.hiddenSongs",
|
|
|
|
+ args: ["event:admin.hiddenSong.added", song]
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.removedHiddenSong",
|
|
|
|
+ cb: songId => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.hiddenSongs",
|
|
|
|
+ args: ["event:admin.hiddenSong.removed", songId]
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+CacheModule.runJob("SUB", {
|
|
|
|
+ channel: "song.updatedHiddenSong",
|
|
|
|
+ cb: async songId => {
|
|
|
|
+ const songModel = await DBModule.runJob("GET_MODEL", {
|
|
|
|
+ modelName: "song"
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ songModel.findOne({ _id: songId }, (err, song) => {
|
|
|
|
+ WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
|
+ room: "admin.hiddenSongs",
|
|
|
|
+ args: ["event:admin.hiddenSong.updated", song]
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -160,21 +244,29 @@ export default {
|
|
* @param {object} session - the session object automatically added by the websocket
|
|
* @param {object} session - the session object automatically added by the websocket
|
|
* @param cb
|
|
* @param cb
|
|
*/
|
|
*/
|
|
- length: isAdminRequired(async function length(session, cb) {
|
|
|
|
|
|
+ length: isAdminRequired(async function length(session, status, cb) {
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
async.waterfall(
|
|
async.waterfall(
|
|
[
|
|
[
|
|
next => {
|
|
next => {
|
|
- songModel.countDocuments({}, next);
|
|
|
|
|
|
+ songModel.countDocuments({ status }, next);
|
|
}
|
|
}
|
|
],
|
|
],
|
|
async (err, count) => {
|
|
async (err, count) => {
|
|
if (err) {
|
|
if (err) {
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
- this.log("ERROR", "SONGS_LENGTH", `Failed to get length from songs. "${err}"`);
|
|
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "SONGS_LENGTH",
|
|
|
|
+ `Failed to get length from songs that have the status ${status}. "${err}"`
|
|
|
|
+ );
|
|
return cb({ status: "failure", message: err });
|
|
return cb({ status: "failure", message: err });
|
|
}
|
|
}
|
|
- this.log("SUCCESS", "SONGS_LENGTH", `Got length from songs successfully.`);
|
|
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "SONGS_LENGTH",
|
|
|
|
+ `Got length from songs that have the status ${status} successfully.`
|
|
|
|
+ );
|
|
return cb(count);
|
|
return cb(count);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -187,13 +279,13 @@ export default {
|
|
* @param set - the set number to return
|
|
* @param set - the set number to return
|
|
* @param cb
|
|
* @param cb
|
|
*/
|
|
*/
|
|
- getSet: isAdminRequired(async function getSet(session, set, cb) {
|
|
|
|
|
|
+ getSet: isAdminRequired(async function getSet(session, set, status, cb) {
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
async.waterfall(
|
|
async.waterfall(
|
|
[
|
|
[
|
|
next => {
|
|
next => {
|
|
songModel
|
|
songModel
|
|
- .find({})
|
|
|
|
|
|
+ .find({ status })
|
|
.skip(15 * (set - 1))
|
|
.skip(15 * (set - 1))
|
|
.limit(15)
|
|
.limit(15)
|
|
.exec(next);
|
|
.exec(next);
|
|
@@ -202,10 +294,14 @@ export default {
|
|
async (err, songs) => {
|
|
async (err, songs) => {
|
|
if (err) {
|
|
if (err) {
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
- this.log("ERROR", "SONGS_GET_SET", `Failed to get set from songs. "${err}"`);
|
|
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "SONGS_GET_SET",
|
|
|
|
+ `Failed to get set from songs that have the status ${status}. "${err}"`
|
|
|
|
+ );
|
|
return cb({ status: "failure", message: err });
|
|
return cb({ status: "failure", message: err });
|
|
}
|
|
}
|
|
- this.log("SUCCESS", "SONGS_GET_SET", `Got set from songs successfully.`);
|
|
|
|
|
|
+ this.log("SUCCESS", "SONGS_GET_SET", `Got set from songs that have the status ${status} successfully.`);
|
|
return cb(songs);
|
|
return cb(songs);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -377,10 +473,22 @@ export default {
|
|
|
|
|
|
this.log("SUCCESS", "SONGS_UPDATE", `Successfully updated song "${songId}".`);
|
|
this.log("SUCCESS", "SONGS_UPDATE", `Successfully updated song "${songId}".`);
|
|
|
|
|
|
- CacheModule.runJob("PUB", {
|
|
|
|
- channel: "song.updated",
|
|
|
|
- value: song.songId
|
|
|
|
- });
|
|
|
|
|
|
+ if (song.status === "verified") {
|
|
|
|
+ CacheModule.runJob("PUB", {
|
|
|
|
+ channel: "song.updatedVerifiedSong",
|
|
|
|
+ value: song.songId
|
|
|
|
+ });
|
|
|
|
+ } else if (song.status === "unverified") {
|
|
|
|
+ CacheModule.runJob("PUB", {
|
|
|
|
+ channel: "song.updatedUnverifiedSong",
|
|
|
|
+ value: song.songId
|
|
|
|
+ });
|
|
|
|
+ } else if (song.status === "hidden") {
|
|
|
|
+ CacheModule.runJob("PUB", {
|
|
|
|
+ channel: "song.updatedHiddenSong",
|
|
|
|
+ value: song.songId
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
return cb({
|
|
return cb({
|
|
status: "success",
|
|
status: "success",
|
|
@@ -391,139 +499,456 @@ export default {
|
|
);
|
|
);
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
+ // /**
|
|
|
|
+ // * Removes a song
|
|
|
|
+ // *
|
|
|
|
+ // * @param session
|
|
|
|
+ // * @param songId - the song id
|
|
|
|
+ // * @param cb
|
|
|
|
+ // */
|
|
|
|
+ // remove: isAdminRequired(async function remove(session, songId, cb) {
|
|
|
|
+ // const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
|
+ // let song = null;
|
|
|
|
+ // async.waterfall(
|
|
|
|
+ // [
|
|
|
|
+ // next => {
|
|
|
|
+ // songModel.findOne({ _id: songId }, next);
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // (_song, next) => {
|
|
|
|
+ // song = _song;
|
|
|
|
+ // songModel.deleteOne({ _id: songId }, next);
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // (res, next) => {
|
|
|
|
+ // // TODO Check if res gets returned from above
|
|
|
|
+ // CacheModule.runJob("HDEL", { table: "songs", key: songId }, this)
|
|
|
|
+ // .then(() => {
|
|
|
|
+ // next();
|
|
|
|
+ // })
|
|
|
|
+ // .catch(next)
|
|
|
|
+ // .finally(() => {
|
|
|
|
+ // song.genres.forEach(genre => {
|
|
|
|
+ // PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
+ // .then(() => {})
|
|
|
|
+ // .catch(() => {});
|
|
|
|
+ // });
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // ],
|
|
|
|
+ // async err => {
|
|
|
|
+ // if (err) {
|
|
|
|
+ // err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+
|
|
|
|
+ // this.log("ERROR", "SONGS_REMOVE", `Failed to remove song "${songId}". "${err}"`);
|
|
|
|
+
|
|
|
|
+ // return cb({ status: "failure", message: err });
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // this.log("SUCCESS", "SONGS_REMOVE", `Successfully remove song "${songId}".`);
|
|
|
|
+
|
|
|
|
+ // if (song.verified) {
|
|
|
|
+ // CacheModule.runJob("PUB", {
|
|
|
|
+ // channel: "song.removedVerifiedSong",
|
|
|
|
+ // value: songId
|
|
|
|
+ // });
|
|
|
|
+ // } else {
|
|
|
|
+ // CacheModule.runJob("PUB", {
|
|
|
|
+ // channel: "song.removedUnverifiedSong",
|
|
|
|
+ // value: songId
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // return cb({
|
|
|
|
+ // status: "success",
|
|
|
|
+ // message: "Song has been successfully removed"
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // );
|
|
|
|
+ // }),
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Requests a song
|
|
|
|
+ *
|
|
|
|
+ * @param {object} session - the session object automatically added by the websocket
|
|
|
|
+ * @param {string} songId - the id of the song that gets requested
|
|
|
|
+ * @param {Function} cb - gets called with the result
|
|
|
|
+ */
|
|
|
|
+ request: isLoginRequired(async function add(session, songId, cb) {
|
|
|
|
+ SongsModule.runJob("REQUEST_SONG", { songId, userId: session.userId }, this)
|
|
|
|
+ .then(() => {
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "SONGS_REQUEST",
|
|
|
|
+ `User "${session.userId}" successfully requested song "${songId}".`
|
|
|
|
+ );
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: "Successfully requested that song"
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch(async err => {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "SONGS_REQUEST",
|
|
|
|
+ `Requesting song "${songId}" failed for user ${session.userId}. "${err}"`
|
|
|
|
+ );
|
|
|
|
+ return cb({ status: "failure", message: err });
|
|
|
|
+ });
|
|
|
|
+ }),
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Removes a song
|
|
|
|
|
|
+ * Hides a song
|
|
|
|
+ *
|
|
|
|
+ * @param {object} session - the session object automatically added by the websocket
|
|
|
|
+ * @param {string} songId - the Musare id of the song that gets hidden
|
|
|
|
+ * @param {Function} cb - gets called with the result
|
|
|
|
+ */
|
|
|
|
+ hide: isLoginRequired(async function add(session, songId, cb) {
|
|
|
|
+ SongsModule.runJob("HIDE_SONG", { songId }, this)
|
|
|
|
+ .then(() => {
|
|
|
|
+ this.log("SUCCESS", "SONGS_HIDE", `User "${session.userId}" successfully hid song "${songId}".`);
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: "Successfully hid that song"
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch(async err => {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log("ERROR", "SONGS_HIDE", `Hiding song "${songId}" failed for user ${session.userId}. "${err}"`);
|
|
|
|
+ return cb({ status: "failure", message: err });
|
|
|
|
+ });
|
|
|
|
+ }),
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Unhides a song
|
|
|
|
+ *
|
|
|
|
+ * @param {object} session - the session object automatically added by the websocket
|
|
|
|
+ * @param {string} songId - the Musare id of the song that gets hidden
|
|
|
|
+ * @param {Function} cb - gets called with the result
|
|
|
|
+ */
|
|
|
|
+ unhide: isLoginRequired(async function add(session, songId, cb) {
|
|
|
|
+ SongsModule.runJob("UNHIDE_SONG", { songId }, this)
|
|
|
|
+ .then(() => {
|
|
|
|
+ this.log("SUCCESS", "SONGS_UNHIDE", `User "${session.userId}" successfully unhid song "${songId}".`);
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: "Successfully unhid that song"
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch(async err => {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "SONGS_UNHIDE",
|
|
|
|
+ `Unhiding song "${songId}" failed for user ${session.userId}. "${err}"`
|
|
|
|
+ );
|
|
|
|
+ return cb({ status: "failure", message: err });
|
|
|
|
+ });
|
|
|
|
+ }),
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Verifies a song
|
|
*
|
|
*
|
|
* @param session
|
|
* @param session
|
|
- * @param songId - the song id
|
|
|
|
|
|
+ * @param song - the song object
|
|
* @param cb
|
|
* @param cb
|
|
*/
|
|
*/
|
|
- remove: isAdminRequired(async function remove(session, songId, cb) {
|
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
|
- let song = null;
|
|
|
|
|
|
+ verify: isAdminRequired(async function add(session, songId, cb) {
|
|
|
|
+ const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
async.waterfall(
|
|
async.waterfall(
|
|
[
|
|
[
|
|
next => {
|
|
next => {
|
|
- songModel.findOne({ _id: songId }, next);
|
|
|
|
|
|
+ SongModel.findOne({ songId }, next);
|
|
},
|
|
},
|
|
|
|
|
|
- (_song, next) => {
|
|
|
|
- song = _song;
|
|
|
|
- songModel.deleteOne({ _id: songId }, next);
|
|
|
|
|
|
+ (song, next) => {
|
|
|
|
+ if (!song) return next("This song is not in the database.");
|
|
|
|
+ return next(null, song);
|
|
},
|
|
},
|
|
|
|
|
|
- (res, next) => {
|
|
|
|
- // TODO Check if res gets returned from above
|
|
|
|
- CacheModule.runJob("HDEL", { table: "songs", key: songId }, this)
|
|
|
|
- .then(() => {
|
|
|
|
- next();
|
|
|
|
- })
|
|
|
|
- .catch(next)
|
|
|
|
- .finally(() => {
|
|
|
|
- song.genres.forEach(genre => {
|
|
|
|
- PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
- .then(() => {})
|
|
|
|
- .catch(() => {});
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ (song, next) => {
|
|
|
|
+ song.acceptedBy = session.userId;
|
|
|
|
+ song.acceptedAt = Date.now();
|
|
|
|
+ song.status = "verified";
|
|
|
|
+ song.save(err => {
|
|
|
|
+ next(err, song);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ (song, next) => {
|
|
|
|
+ song.genres.forEach(genre => {
|
|
|
|
+ PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
+ .then(() => {})
|
|
|
|
+ .catch(() => {});
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
|
+
|
|
|
|
+ next(null, song);
|
|
}
|
|
}
|
|
],
|
|
],
|
|
- async err => {
|
|
|
|
|
|
+ async (err, song) => {
|
|
if (err) {
|
|
if (err) {
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
|
|
- this.log("ERROR", "SONGS_REMOVE", `Failed to remove song "${songId}". "${err}"`);
|
|
|
|
|
|
+ this.log("ERROR", "SONGS_VERIFY", `User "${session.userId}" failed to verify song. "${err}"`);
|
|
|
|
|
|
return cb({ status: "failure", message: err });
|
|
return cb({ status: "failure", message: err });
|
|
}
|
|
}
|
|
|
|
|
|
- this.log("SUCCESS", "SONGS_REMOVE", `Successfully remove song "${songId}".`);
|
|
|
|
|
|
+ this.log("SUCCESS", "SONGS_VERIFY", `User "${session.userId}" successfully verified song "${songId}".`);
|
|
|
|
|
|
- CacheModule.runJob("PUB", { channel: "song.removed", value: songId });
|
|
|
|
|
|
+ CacheModule.runJob("PUB", {
|
|
|
|
+ channel: "song.newVerifiedSong",
|
|
|
|
+ value: song._id
|
|
|
|
+ });
|
|
|
|
|
|
return cb({
|
|
return cb({
|
|
status: "success",
|
|
status: "success",
|
|
- message: "Song has been successfully removed"
|
|
|
|
|
|
+ message: "Song has been verified successfully."
|
|
});
|
|
});
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
+ // TODO Check if video is in queue and Add the song to the appropriate stations
|
|
}),
|
|
}),
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Adds a song
|
|
|
|
|
|
+ * Un-verifies a song
|
|
*
|
|
*
|
|
* @param session
|
|
* @param session
|
|
- * @param song - the song object
|
|
|
|
|
|
+ * @param songId - the song id
|
|
* @param cb
|
|
* @param cb
|
|
*/
|
|
*/
|
|
- add: isAdminRequired(async function add(session, song, cb) {
|
|
|
|
|
|
+ unverify: isAdminRequired(async function add(session, songId, cb) {
|
|
const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
async.waterfall(
|
|
async.waterfall(
|
|
[
|
|
[
|
|
next => {
|
|
next => {
|
|
- SongModel.findOne({ songId: song.songId }, next);
|
|
|
|
|
|
+ SongModel.findOne({ _id: songId }, next);
|
|
},
|
|
},
|
|
|
|
|
|
- (existingSong, next) => {
|
|
|
|
- if (existingSong) return next("Song is already in rotation.");
|
|
|
|
- return next();
|
|
|
|
|
|
+ (song, next) => {
|
|
|
|
+ if (!song) return next("This song is not in the database.");
|
|
|
|
+ return next(null, song);
|
|
},
|
|
},
|
|
|
|
|
|
- next => {
|
|
|
|
- const newSong = new SongModel(song);
|
|
|
|
- newSong.acceptedBy = session.userId;
|
|
|
|
- newSong.acceptedAt = Date.now();
|
|
|
|
- newSong.save(next);
|
|
|
|
|
|
+ (song, next) => {
|
|
|
|
+ song.status = "unverified";
|
|
|
|
+ song.save(err => {
|
|
|
|
+ next(err, song);
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
- (res, next) => {
|
|
|
|
- this.module
|
|
|
|
- .runJob(
|
|
|
|
- "RUN_ACTION2",
|
|
|
|
- {
|
|
|
|
- session,
|
|
|
|
- namespace: "queueSongs",
|
|
|
|
- action: "remove",
|
|
|
|
- args: [song._id]
|
|
|
|
- },
|
|
|
|
- this
|
|
|
|
- )
|
|
|
|
- .finally(() => {
|
|
|
|
- song.genres.forEach(genre => {
|
|
|
|
- PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
- .then(() => {})
|
|
|
|
- .catch(() => {});
|
|
|
|
- });
|
|
|
|
|
|
+ (song, next) => {
|
|
|
|
+ song.genres.forEach(genre => {
|
|
|
|
+ PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
+ .then(() => {})
|
|
|
|
+ .catch(() => {});
|
|
|
|
+ });
|
|
|
|
|
|
- next();
|
|
|
|
- });
|
|
|
|
|
|
+ SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
|
+
|
|
|
|
+ next(null);
|
|
}
|
|
}
|
|
],
|
|
],
|
|
async err => {
|
|
async err => {
|
|
if (err) {
|
|
if (err) {
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
|
|
- this.log("ERROR", "SONGS_ADD", `User "${session.userId}" failed to add song. "${err}"`);
|
|
|
|
|
|
+ this.log("ERROR", "SONGS_UNVERIFY", `User "${session.userId}" failed to verify song. "${err}"`);
|
|
|
|
|
|
return cb({ status: "failure", message: err });
|
|
return cb({ status: "failure", message: err });
|
|
}
|
|
}
|
|
|
|
|
|
- this.log("SUCCESS", "SONGS_ADD", `User "${session.userId}" successfully added song "${song.songId}".`);
|
|
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "SONGS_UNVERIFY",
|
|
|
|
+ `User "${session.userId}" successfully unverified song "${songId}".`
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ CacheModule.runJob("PUB", {
|
|
|
|
+ channel: "song.newUnverifiedSong",
|
|
|
|
+ value: songId
|
|
|
|
+ });
|
|
|
|
|
|
CacheModule.runJob("PUB", {
|
|
CacheModule.runJob("PUB", {
|
|
- channel: "song.added",
|
|
|
|
- value: song.songId
|
|
|
|
|
|
+ channel: "song.removedVerifiedSong",
|
|
|
|
+ value: songId
|
|
});
|
|
});
|
|
|
|
|
|
return cb({
|
|
return cb({
|
|
status: "success",
|
|
status: "success",
|
|
- message: "Song has been moved from the queue successfully."
|
|
|
|
|
|
+ message: "Song has been unverified successfully."
|
|
});
|
|
});
|
|
}
|
|
}
|
|
);
|
|
);
|
|
// TODO Check if video is in queue and Add the song to the appropriate stations
|
|
// TODO Check if video is in queue and Add the song to the appropriate stations
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Requests a set of songs
|
|
|
|
+ *
|
|
|
|
+ * @param {object} session - the session object automatically added by the websocket
|
|
|
|
+ * @param {string} url - the url of the the YouTube playlist
|
|
|
|
+ * @param {boolean} musicOnly - whether to only get music from the playlist
|
|
|
|
+ * @param {Function} cb - gets called with the result
|
|
|
|
+ */
|
|
|
|
+ requestSet: isLoginRequired(function requestSet(session, url, musicOnly, cb) {
|
|
|
|
+ async.waterfall(
|
|
|
|
+ [
|
|
|
|
+ next => {
|
|
|
|
+ YouTubeModule.runJob(
|
|
|
|
+ "GET_PLAYLIST",
|
|
|
|
+ {
|
|
|
|
+ url,
|
|
|
|
+ musicOnly
|
|
|
|
+ },
|
|
|
|
+ this
|
|
|
|
+ )
|
|
|
|
+ .then(res => {
|
|
|
|
+ next(null, res.songs);
|
|
|
|
+ })
|
|
|
|
+ .catch(next);
|
|
|
|
+ },
|
|
|
|
+ (songIds, next) => {
|
|
|
|
+ let successful = 0;
|
|
|
|
+ let failed = 0;
|
|
|
|
+ let alreadyInDatabase = 0;
|
|
|
|
+
|
|
|
|
+ if (songIds.length === 0) next();
|
|
|
|
+
|
|
|
|
+ async.eachLimit(
|
|
|
|
+ songIds,
|
|
|
|
+ 1,
|
|
|
|
+ (songId, next) => {
|
|
|
|
+ WSModule.runJob(
|
|
|
|
+ "RUN_ACTION2",
|
|
|
|
+ {
|
|
|
|
+ session,
|
|
|
|
+ namespace: "songs",
|
|
|
|
+ action: "request",
|
|
|
|
+ args: [songId]
|
|
|
|
+ },
|
|
|
|
+ this
|
|
|
|
+ )
|
|
|
|
+ .then(res => {
|
|
|
|
+ if (res.status === "success") successful += 1;
|
|
|
|
+ else failed += 1;
|
|
|
|
+ if (res.message === "This song is already in the database.") alreadyInDatabase += 1;
|
|
|
|
+ })
|
|
|
|
+ .catch(() => {
|
|
|
|
+ failed += 1;
|
|
|
|
+ })
|
|
|
|
+ .finally(() => {
|
|
|
|
+ next();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ () => {
|
|
|
|
+ next(null, { successful, failed, alreadyInDatabase });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ async (err, response) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "REQUEST_SET",
|
|
|
|
+ `Importing a YouTube playlist to be requested failed for user "${session.userId}". "${err}"`
|
|
|
|
+ );
|
|
|
|
+ return cb({ status: "failure", message: err });
|
|
|
|
+ }
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "REQUEST_SET",
|
|
|
|
+ `Successfully imported a YouTube playlist to be requested for user "${session.userId}".`
|
|
|
|
+ );
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: `Playlist is done importing. ${response.successful} were added succesfully, ${response.failed} failed (${response.alreadyInDatabase} were already in database)`
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }),
|
|
|
|
+
|
|
|
|
+ // /**
|
|
|
|
+ // * Adds a song
|
|
|
|
+ // *
|
|
|
|
+ // * @param session
|
|
|
|
+ // * @param song - the song object
|
|
|
|
+ // * @param cb
|
|
|
|
+ // */
|
|
|
|
+ // add: isAdminRequired(async function add(session, song, cb) {
|
|
|
|
+ // const SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
|
+ // async.waterfall(
|
|
|
|
+ // [
|
|
|
|
+ // next => {
|
|
|
|
+ // SongModel.findOne({ songId: song.songId }, next);
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // (existingSong, next) => {
|
|
|
|
+ // if (existingSong) return next("Song is already in rotation.");
|
|
|
|
+ // return next();
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // next => {
|
|
|
|
+ // const newSong = new SongModel(song);
|
|
|
|
+ // newSong.acceptedBy = session.userId;
|
|
|
|
+ // newSong.acceptedAt = Date.now();
|
|
|
|
+ // newSong.save(next);
|
|
|
|
+ // },
|
|
|
|
+
|
|
|
|
+ // (res, next) => {
|
|
|
|
+ // this.module
|
|
|
|
+ // .runJob(
|
|
|
|
+ // "RUN_ACTION2",
|
|
|
|
+ // {
|
|
|
|
+ // session,
|
|
|
|
+ // namespace: "queueSongs",
|
|
|
|
+ // action: "remove",
|
|
|
|
+ // args: [song._id]
|
|
|
|
+ // },
|
|
|
|
+ // this
|
|
|
|
+ // )
|
|
|
|
+ // .finally(() => {
|
|
|
|
+ // song.genres.forEach(genre => {
|
|
|
|
+ // PlaylistsModule.runJob("AUTOFILL_GENRE_PLAYLIST", { genre })
|
|
|
|
+ // .then(() => {})
|
|
|
|
+ // .catch(() => {});
|
|
|
|
+ // });
|
|
|
|
+
|
|
|
|
+ // next();
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // ],
|
|
|
|
+ // async err => {
|
|
|
|
+ // if (err) {
|
|
|
|
+ // err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+
|
|
|
|
+ // this.log("ERROR", "SONGS_ADD", `User "${session.userId}" failed to add song. "${err}"`);
|
|
|
|
+
|
|
|
|
+ // return cb({ status: "failure", message: err });
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // this.log("SUCCESS", "SONGS_ADD", `User "${session.userId}" successfully added song "${song.songId}".`);
|
|
|
|
+
|
|
|
|
+ // CacheModule.runJob("PUB", {
|
|
|
|
+ // channel: "song.added",
|
|
|
|
+ // value: song.songId
|
|
|
|
+ // });
|
|
|
|
+
|
|
|
|
+ // return cb({
|
|
|
|
+ // status: "success",
|
|
|
|
+ // message: "Song has been moved from the queue successfully."
|
|
|
|
+ // });
|
|
|
|
+ // }
|
|
|
|
+ // );
|
|
|
|
+ // // TODO Check if video is in queue and Add the song to the appropriate stations
|
|
|
|
+ // }),
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Likes a song
|
|
* Likes a song
|
|
*
|
|
*
|