Browse Source

fix: fixed a lot more issues, still unstable

Kristian Vos 5 years ago
parent
commit
4fe2306517

+ 6 - 6
backend/logic/actions/news.js

@@ -15,8 +15,8 @@ cache.runJob("SUB", {
     cb: (news) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: news.createdBy,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:admin.news.created", news);
                 });
             },
@@ -29,8 +29,8 @@ cache.runJob("SUB", {
     cb: (news) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: news.createdBy,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:admin.news.removed", news);
                 });
             },
@@ -43,8 +43,8 @@ cache.runJob("SUB", {
     cb: (news) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: news.createdBy,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:admin.news.updated", news);
                 });
             },

+ 20 - 17
backend/logic/actions/playlists.js

@@ -18,8 +18,8 @@ cache.runJob("SUB", {
         playlists.runJob("GET_PLAYLIST", { playlistId }).then((playlist) => {
             utils
                 .runJob("SOCKETS_FROM_USER", { userId: playlist.createdBy })
-                .then((sockets) => {
-                    sockets.forEach((socket) => {
+                .then((response) => {
+                    response.sockets.forEach((socket) => {
                         socket.emit("event:playlist.create", playlist);
                     });
                 });
@@ -32,8 +32,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.delete", res.playlistId);
                 });
             });
@@ -45,8 +45,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.moveSongToTop", {
                         playlistId: res.playlistId,
                         songId: res.songId,
@@ -61,8 +61,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.moveSongToBottom", {
                         playlistId: res.playlistId,
                         songId: res.songId,
@@ -77,8 +77,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.addSong", {
                         playlistId: res.playlistId,
                         song: res.song,
@@ -93,8 +93,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.removeSong", {
                         playlistId: res.playlistId,
                         songId: res.songId,
@@ -109,8 +109,8 @@ cache.runJob("SUB", {
     cb: (res) => {
         utils
             .runJob("SOCKETS_FROM_USER", { userId: res.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:playlist.updateDisplayName", {
                         playlistId: res.playlistId,
                         displayName: res.displayName,
@@ -525,8 +525,9 @@ let lib = {
                     },
                     (next) => {
                         songs
-                            .runJob("GET_SONG", { songId })
-                            .then((song) => {
+                            .runJob("GET_SONG", { id: songId })
+                            .then((response) => {
+                                const song = response.song;
                                 next(null, {
                                     _id: song._id,
                                     songId: songId,
@@ -537,7 +538,9 @@ let lib = {
                             .catch(() => {
                                 utils
                                     .runJob("GET_SONG_FROM_YOUTUBE", { songId })
-                                    .then((song) => next(null, song))
+                                    .then((response) =>
+                                        next(null, response.song)
+                                    )
                                     .catch(next);
                             });
                     },

+ 2 - 1
backend/logic/actions/queueSongs.js

@@ -264,7 +264,8 @@ let lib = {
                     //TODO Add err object as first param of callback
                     utils
                         .runJob("GET_SONG_FROM_YOUTUBE", { songId })
-                        .then((song) => {
+                        .then((response) => {
+                            const song = response.song;
                             song.duration = -1;
                             song.artists = [];
                             song.genres = [];

+ 2 - 2
backend/logic/actions/reports.js

@@ -265,8 +265,8 @@ module.exports = {
                 (song, next) => {
                     if (!song) return next("Song not found.");
                     songs
-                        .runJob("GET_SONG", { songId })
-                        .then((song) => next(null, song))
+                        .runJob("GET_SONG", { id: song._id })
+                        .then((response) => next(null, response.song))
                         .catch(next);
                 },
 

+ 9 - 9
backend/logic/actions/songs.js

@@ -66,8 +66,8 @@ cache.runJob("SUB", {
         });
         utils
             .runJob("SOCKETS_FROM_USER", { userId: data.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:song.newRatings", {
                         songId: data.songId,
                         liked: true,
@@ -94,8 +94,8 @@ cache.runJob("SUB", {
         });
         utils
             .runJob("SOCKETS_FROM_USER", { userId: data.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:song.newRatings", {
                         songId: data.songId,
                         liked: false,
@@ -122,8 +122,8 @@ cache.runJob("SUB", {
         });
         utils
             .runJob("SOCKETS_FROM_USER", { userId: data.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:song.newRatings", {
                         songId: data.songId,
                         liked: false,
@@ -150,8 +150,8 @@ cache.runJob("SUB", {
         });
         utils
             .runJob("SOCKETS_FROM_USER", { userId: data.userId })
-            .then((sockets) => {
-                sockets.forEach((socket) => {
+            .then((response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:song.newRatings", {
                         songId: data.songId,
                         liked: false,
@@ -286,7 +286,7 @@ module.exports = {
                 (next) => {
                     songs
                         .runJob("GET_SONG_FROM_ID", { songId })
-                        .then((song) => next(null, song))
+                        .then((responsesong) => next(null, response.song))
                         .catch(next);
                 },
             ],

+ 172 - 167
backend/logic/actions/stations.js

@@ -21,131 +21,132 @@ let userList = {};
 let usersPerStation = {};
 let usersPerStationCount = {};
 
-setInterval(async () => {
-    let stationsCountUpdated = [];
-    let stationsUpdated = [];
-
-    let oldUsersPerStation = usersPerStation;
-    usersPerStation = {};
-
-    let oldUsersPerStationCount = usersPerStationCount;
-    usersPerStationCount = {};
-
-    const userModel = await db.runJob("GET_MODEL", {
-        modelName: "user",
-    });
-
-    async.each(
-        Object.keys(userList),
-        function(socketId, next) {
-            utils.runJob("SOCKET_FROM_SESSION", { socketId }).then((socket) => {
-                let stationId = userList[socketId];
-                if (
-                    !socket ||
-                    Object.keys(socket.rooms).indexOf(
-                        `station.${stationId}`
-                    ) === -1
-                ) {
-                    if (stationsCountUpdated.indexOf(stationId) === -1)
-                        stationsCountUpdated.push(stationId);
-                    if (stationsUpdated.indexOf(stationId) === -1)
-                        stationsUpdated.push(stationId);
-                    delete userList[socketId];
-                    return next();
-                }
-                if (!usersPerStationCount[stationId])
-                    usersPerStationCount[stationId] = 0;
-                usersPerStationCount[stationId]++;
-                if (!usersPerStation[stationId])
-                    usersPerStation[stationId] = [];
-
-                async.waterfall(
-                    [
-                        (next) => {
-                            if (!socket.session || !socket.session.sessionId)
-                                return next("No session found.");
-                            cache
-                                .runJob("HGET", {
-                                    table: "sessions",
-                                    key: socket.session.sessionId,
-                                })
-                                .then((session) => next(null, session))
-                                .catch(next);
-                        },
-
-                        (session, next) => {
-                            if (!session) return next("Session not found.");
-                            userModel.findOne({ _id: session.userId }, next);
-                        },
-
-                        (user, next) => {
-                            if (!user) return next("User not found.");
-                            if (
-                                usersPerStation[stationId].indexOf(
-                                    user.username
-                                ) !== -1
-                            )
-                                return next("User already in the list.");
-                            next(null, user.username);
-                        },
-                    ],
-                    (err, username) => {
-                        if (!err) {
-                            usersPerStation[stationId].push(username);
-                        }
-                        next();
-                    }
-                );
-            });
-            //TODO Code to show users
-        },
-        (err) => {
-            for (let stationId in usersPerStationCount) {
-                if (
-                    oldUsersPerStationCount[stationId] !==
-                    usersPerStationCount[stationId]
-                ) {
-                    if (stationsCountUpdated.indexOf(stationId) === -1)
-                        stationsCountUpdated.push(stationId);
-                }
-            }
-
-            for (let stationId in usersPerStation) {
-                if (
-                    _.difference(
-                        usersPerStation[stationId],
-                        oldUsersPerStation[stationId]
-                    ).length > 0 ||
-                    _.difference(
-                        oldUsersPerStation[stationId],
-                        usersPerStation[stationId]
-                    ).length > 0
-                ) {
-                    if (stationsUpdated.indexOf(stationId) === -1)
-                        stationsUpdated.push(stationId);
-                }
-            }
-
-            stationsCountUpdated.forEach((stationId) => {
-                //console.log("INFO", "UPDATE_STATION_USER_COUNT", `Updating user count of ${stationId}.`);
-                cache.runJob("PUB", {
-                    table: "station.updateUserCount",
-                    value: stationId,
-                });
-            });
-
-            stationsUpdated.forEach((stationId) => {
-                //console.log("INFO", "UPDATE_STATION_USER_LIST", `Updating user list of ${stationId}.`);
-                cache.runJob("PUB", {
-                    table: "station.updateUsers",
-                    value: stationId,
-                });
-            });
-
-            //console.log("Userlist", usersPerStation);
-        }
-    );
-}, 3000);
+// Temporarily disabled until the messages in console can be limited
+// setInterval(async () => {
+//     let stationsCountUpdated = [];
+//     let stationsUpdated = [];
+
+//     let oldUsersPerStation = usersPerStation;
+//     usersPerStation = {};
+
+//     let oldUsersPerStationCount = usersPerStationCount;
+//     usersPerStationCount = {};
+
+//     const userModel = await db.runJob("GET_MODEL", {
+//         modelName: "user",
+//     });
+//
+//     async.each(
+//         Object.keys(userList),
+//         function(socketId, next) {
+//             utils.runJob("SOCKET_FROM_SESSION", { socketId }).then((socket) => {
+//                 let stationId = userList[socketId];
+//                 if (
+//                     !socket ||
+//                     Object.keys(socket.rooms).indexOf(
+//                         `station.${stationId}`
+//                     ) === -1
+//                 ) {
+//                     if (stationsCountUpdated.indexOf(stationId) === -1)
+//                         stationsCountUpdated.push(stationId);
+//                     if (stationsUpdated.indexOf(stationId) === -1)
+//                         stationsUpdated.push(stationId);
+//                     delete userList[socketId];
+//                     return next();
+//                 }
+//                 if (!usersPerStationCount[stationId])
+//                     usersPerStationCount[stationId] = 0;
+//                 usersPerStationCount[stationId]++;
+//                 if (!usersPerStation[stationId])
+//                     usersPerStation[stationId] = [];
+
+//                 async.waterfall(
+//                     [
+//                         (next) => {
+//                             if (!socket.session || !socket.session.sessionId)
+//                                 return next("No session found.");
+//                             cache
+//                                 .runJob("HGET", {
+//                                     table: "sessions",
+//                                     key: socket.session.sessionId,
+//                                 })
+//                                 .then((session) => next(null, session))
+//                                 .catch(next);
+//                         },
+
+//                         (session, next) => {
+//                             if (!session) return next("Session not found.");
+//                             userModel.findOne({ _id: session.userId }, next);
+//                         },
+
+//                         (user, next) => {
+//                             if (!user) return next("User not found.");
+//                             if (
+//                                 usersPerStation[stationId].indexOf(
+//                                     user.username
+//                                 ) !== -1
+//                             )
+//                                 return next("User already in the list.");
+//                             next(null, user.username);
+//                         },
+//                     ],
+//                     (err, username) => {
+//                         if (!err) {
+//                             usersPerStation[stationId].push(username);
+//                         }
+//                         next();
+//                     }
+//                 );
+//             });
+//             //TODO Code to show users
+//         },
+//         (err) => {
+//             for (let stationId in usersPerStationCount) {
+//                 if (
+//                     oldUsersPerStationCount[stationId] !==
+//                     usersPerStationCount[stationId]
+//                 ) {
+//                     if (stationsCountUpdated.indexOf(stationId) === -1)
+//                         stationsCountUpdated.push(stationId);
+//                 }
+//             }
+
+//             for (let stationId in usersPerStation) {
+//                 if (
+//                     _.difference(
+//                         usersPerStation[stationId],
+//                         oldUsersPerStation[stationId]
+//                     ).length > 0 ||
+//                     _.difference(
+//                         oldUsersPerStation[stationId],
+//                         usersPerStation[stationId]
+//                     ).length > 0
+//                 ) {
+//                     if (stationsUpdated.indexOf(stationId) === -1)
+//                         stationsUpdated.push(stationId);
+//                 }
+//             }
+
+//             stationsCountUpdated.forEach((stationId) => {
+//                 //console.log("INFO", "UPDATE_STATION_USER_COUNT", `Updating user count of ${stationId}.`);
+//                 cache.runJob("PUB", {
+//                     table: "station.updateUserCount",
+//                     value: stationId,
+//                 });
+//             });
+
+//             stationsUpdated.forEach((stationId) => {
+//                 //console.log("INFO", "UPDATE_STATION_USER_LIST", `Updating user list of ${stationId}.`);
+//                 cache.runJob("PUB", {
+//                     table: "station.updateUsers",
+//                     value: stationId,
+//                 });
+//             });
+
+//             //console.log("Userlist", usersPerStation);
+//         }
+//     );
+// }, 3000);
 
 cache.runJob("SUB", {
     channel: "station.updateUsers",
@@ -234,26 +235,20 @@ cache.runJob("SUB", {
 cache.runJob("SUB", {
     channel: "station.updatePartyMode",
     cb: (data) => {
-        utils.runJob(
-            "EMIT_TO_ROOM",
-            {
-                room: `station.${data.stationId}`,
-                args: ["event:partyMode.updated", data],
-            }.partyMode
-        );
+        utils.runJob("EMIT_TO_ROOM", {
+            room: `station.${data.stationId}`,
+            args: ["event:partyMode.updated", data.partyMode],
+        });
     },
 });
 
 cache.runJob("SUB", {
     channel: "privatePlaylist.selected",
     cb: (data) => {
-        utils.runJob(
-            "EMIT_TO_ROOM",
-            {
-                room: `station.${data.stationId}`,
-                args: ["event:privatePlaylist.selected", data],
-            }.playlistId
-        );
+        utils.runJob("EMIT_TO_ROOM", {
+            room: `station.${data.stationId}`,
+            args: ["event:privatePlaylist.selected", data.playlistId],
+        });
     },
 });
 
@@ -327,7 +322,8 @@ cache.runJob("SUB", {
 
         stations
             .runJob("INITIALIZE_STATION", { stationId })
-            .then(async (station) => {
+            .then(async (response) => {
+                const station = response.station;
                 station.userCount = usersPerStationCount[stationId] || 0;
                 utils.runJob("EMIT_TO_ROOM", {
                     room: "admin.stations",
@@ -352,12 +348,8 @@ cache.runJob("SUB", {
                                     table: "sessions",
                                     key: session.sessionId,
                                 })
-                                .then(async (session) => {
+                                .then((session) => {
                                     if (session) {
-                                        const userModel = await db.runJob(
-                                            "GET_MODEL",
-                                            {}
-                                        );
                                         userModel.findOne(
                                             { _id: session.userId },
                                             (err, user) => {
@@ -399,6 +391,7 @@ module.exports = {
         async.waterfall(
             [
                 (next) => {
+                    console.log(111);
                     cache
                         .runJob("HGETALL", { table: "stations" })
                         .then((stations) => {
@@ -407,6 +400,8 @@ module.exports = {
                 },
 
                 (stations, next) => {
+                    console.log(222);
+
                     let resultStations = [];
                     for (let id in stations) {
                         resultStations.push(stations[id]);
@@ -415,6 +410,8 @@ module.exports = {
                 },
 
                 (stationsArray, next) => {
+                    console.log(333);
+
                     let resultStations = [];
                     async.each(
                         stationsArray,
@@ -428,12 +425,15 @@ module.exports = {
                                                 userId: session.userId,
                                             })
                                             .then((exists) => {
+                                                console.log(444, exists);
+
                                                 next(null, exists);
                                             })
                                             .catch(next);
                                     },
                                 ],
                                 (err, exists) => {
+                                    if (err) console.log(err);
                                     station.userCount =
                                         usersPerStationCount[station._id] || 0;
                                     if (exists) resultStations.push(station);
@@ -718,7 +718,8 @@ module.exports = {
                         .runJob("GET_SONG_FROM_ID", {
                             songId: data.currentSong.songId,
                         })
-                        .then((song) => {
+                        .then((response) => {
+                            const song = response.song;
                             if (song) {
                                 data.currentSong.likes = song.likes;
                                 data.currentSong.dislikes = song.dislikes;
@@ -1887,30 +1888,31 @@ module.exports = {
                 },
 
                 (station, next) => {
-                    songs
-                        .runJob("GET_SONG", { songId })
-                        .then((song) => {
-                            if (song) return next(null, song, station);
-                            else {
-                                utils
-                                    .runJob("GET_SONG_FROM_YOUTUBE", { songId })
-                                    .then((song) => {
-                                        song.artists = [];
-                                        song.skipDuration = 0;
-                                        song.likes = -1;
-                                        song.dislikes = -1;
-                                        song.thumbnail = "empty";
-                                        song.explicit = false;
-                                        next(null, song, station);
-                                    })
-                                    .catch((err) => {
-                                        next(err);
-                                    });
-                            }
+                    // songs
+                    //     .runJob("GET_SONG", { id: songId })
+                    //     .then((song) => {
+                    //         if (song) return next(null, song, station);
+                    //         else {
+                    utils
+                        .runJob("GET_SONG_FROM_YOUTUBE", { songId })
+                        .then((response) => {
+                            const song = response.song;
+                            song.artists = [];
+                            song.skipDuration = 0;
+                            song.likes = -1;
+                            song.dislikes = -1;
+                            song.thumbnail = "empty";
+                            song.explicit = false;
+                            next(null, song, station);
                         })
                         .catch((err) => {
                             next(err);
                         });
+                    //     }
+                    // })
+                    // .catch((err) => {
+                    //     next(err);
+                    // });
                 },
 
                 (song, station, next) => {
@@ -2174,6 +2176,9 @@ module.exports = {
             const stationModel = await db.runJob("GET_MODEL", {
                 modelName: "station",
             });
+            const playlistModel = await db.runJob("GET_MODEL", {
+                modelName: "playlist",
+            });
             async.waterfall(
                 [
                     (next) => {
@@ -2191,7 +2196,7 @@ module.exports = {
                             return next(
                                 "That private playlist is already selected."
                             );
-                        db.models.playlist.findOne({ _id: playlistId }, next);
+                        playlistModel.findOne({ _id: playlistId }, next);
                     },
 
                     (playlist, next) => {

+ 18 - 18
backend/logic/actions/users.js

@@ -23,8 +23,8 @@ cache.runJob("SUB", {
     cb: (user) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: user._id,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.username.changed", user.username);
                 });
             },
@@ -37,8 +37,8 @@ cache.runJob("SUB", {
     cb: (userId) => {
         utils.runJob("SOCKETS_FROM_USER_WITHOUT_CACHE", {
             userId: userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("keep.event:user.session.removed");
                 });
             },
@@ -51,8 +51,8 @@ cache.runJob("SUB", {
     cb: (userId) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.linkPassword");
                 });
             },
@@ -65,8 +65,8 @@ cache.runJob("SUB", {
     cb: (userId) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.linkGitHub");
                 });
             },
@@ -79,8 +79,8 @@ cache.runJob("SUB", {
     cb: (userId) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.unlinkPassword");
                 });
             },
@@ -93,8 +93,8 @@ cache.runJob("SUB", {
     cb: (userId) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.unlinkGitHub");
                 });
             },
@@ -107,8 +107,8 @@ cache.runJob("SUB", {
     cb: (data) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: data.userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("keep.event:banned", data.punishment);
                     socket.disconnect(true);
                 });
@@ -122,8 +122,8 @@ cache.runJob("SUB", {
     cb: (data) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: data.userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit("event:user.favoritedStation", data.stationId);
                 });
             },
@@ -136,8 +136,8 @@ cache.runJob("SUB", {
     cb: (data) => {
         utils.runJob("SOCKETS_FROM_USER", {
             userId: data.userId,
-            cb: (sockets) => {
-                sockets.forEach((socket) => {
+            cb: (response) => {
+                response.sockets.forEach((socket) => {
                     socket.emit(
                         "event:user.unfavoritedStation",
                         data.stationId

+ 5 - 2
backend/logic/activities.js

@@ -1,5 +1,8 @@
 const CoreClass = require("../core.js");
 
+const async = require("async");
+const mongoose = require("mongoose");
+
 class ActivitiesModule extends CoreClass {
     constructor() {
         super("activities");
@@ -47,8 +50,8 @@ class ActivitiesModule extends CoreClass {
                             .runJob("SOCKETS_FROM_USER", {
                                 userId: activity.userId,
                             })
-                            .then((sockets) =>
-                                sockets.forEach((socket) => {
+                            .then((response) =>
+                                response.sockets.forEach((socket) => {
                                     socket.emit(
                                         "event:activity.create",
                                         activity

+ 109 - 52
backend/logic/app.js

@@ -15,7 +15,7 @@ class AppModule extends CoreClass {
     }
 
     initialize() {
-        return new Promise((resolve, reject) => {
+        return new Promise(async (resolve, reject) => {
             const mail = this.moduleManager.modules["mail"],
                 cache = this.moduleManager.modules["cache"],
                 db = this.moduleManager.modules["db"],
@@ -32,6 +32,10 @@ class AppModule extends CoreClass {
             app.use(bodyParser.json());
             app.use(bodyParser.urlencoded({ extended: true }));
 
+            const userModel = await db.runJob("GET_MODEL", {
+                modelName: "user",
+            });
+
             let corsOptions = Object.assign({}, config.get("cors"));
 
             app.use(cors(corsOptions));
@@ -50,11 +54,18 @@ class AppModule extends CoreClass {
                 config.get("serverDomain") + "/auth/github/authorize/callback";
 
             app.get("/auth/github/authorize", async (req, res) => {
-                try {
-                    await this._validateHook();
-                } catch {
-                    return;
+                if (this.getStatus() !== "READY") {
+                    this.log(
+                        "INFO",
+                        "APP_REJECTED_GITHUB_AUTHORIZE",
+                        `A user tried to use github authorize, but the APP module is currently not ready.`
+                    );
+                    return redirectOnErr(
+                        res,
+                        "Something went wrong on our end. Please try again later."
+                    );
                 }
+
                 let params = [
                     `client_id=${config.get("apis.github.client")}`,
                     `redirect_uri=${config.get(
@@ -68,10 +79,16 @@ class AppModule extends CoreClass {
             });
 
             app.get("/auth/github/link", async (req, res) => {
-                try {
-                    await this._validateHook();
-                } catch {
-                    return;
+                if (this.getStatus() !== "READY") {
+                    this.log(
+                        "INFO",
+                        "APP_REJECTED_GITHUB_AUTHORIZE",
+                        `A user tried to use github authorize, but the APP module is currently not ready.`
+                    );
+                    return redirectOnErr(
+                        res,
+                        "Something went wrong on our end. Please try again later."
+                    );
                 }
                 let params = [
                     `client_id=${config.get("apis.github.client")}`,
@@ -93,10 +110,16 @@ class AppModule extends CoreClass {
             }
 
             app.get("/auth/github/authorize/callback", async (req, res) => {
-                try {
-                    await this._validateHook();
-                } catch {
-                    return;
+                if (this.getStatus() !== "READY") {
+                    this.log(
+                        "INFO",
+                        "APP_REJECTED_GITHUB_AUTHORIZE",
+                        `A user tried to use github authorize, but the APP module is currently not ready.`
+                    );
+                    return redirectOnErr(
+                        res,
+                        "Something went wrong on our end. Please try again later."
+                    );
                 }
 
                 let code = req.query.code;
@@ -106,8 +129,9 @@ class AppModule extends CoreClass {
 
                 const state = req.query.state;
 
-                const verificationToken = await this.utils.generateRandomString(
-                    64
+                const verificationToken = await this.utils.runJob(
+                    "GENERATE_RANDOM_STRING",
+                    { length: 64 }
                 );
 
                 async.waterfall(
@@ -147,13 +171,21 @@ class AppModule extends CoreClass {
                                 return async.waterfall(
                                     [
                                         (next) => {
-                                            cache.hget("sessions", state, next);
+                                            cache
+                                                .runJob("HGET", {
+                                                    table: "sessions",
+                                                    key: state,
+                                                })
+                                                .then((session) =>
+                                                    next(null, session)
+                                                )
+                                                .catch(next);
                                         },
 
                                         (session, next) => {
                                             if (!session)
                                                 return next("Invalid session.");
-                                            db.models.user.findOne(
+                                            userModel.findOne(
                                                 { _id: session.userId },
                                                 next
                                             );
@@ -169,7 +201,7 @@ class AppModule extends CoreClass {
                                                 return next(
                                                     "Account already has GitHub linked."
                                                 );
-                                            db.models.user.updateOne(
+                                            userModel.updateOne(
                                                 { _id: user._id },
                                                 {
                                                     $set: {
@@ -188,10 +220,10 @@ class AppModule extends CoreClass {
                                         },
 
                                         (user) => {
-                                            cache.pub(
-                                                "user.linkGitHub",
-                                                user._id
-                                            );
+                                            cache.runJob("PUB", {
+                                                channel: "user.linkGithub",
+                                                value: user._id,
+                                            });
                                             res.redirect(
                                                 `${config.get(
                                                     "domain"
@@ -205,7 +237,7 @@ class AppModule extends CoreClass {
 
                             if (!body.id)
                                 return next("Something went wrong, no id.");
-                            db.models.user.findOne(
+                            userModel.findOne(
                                 { "services.github.id": body.id },
                                 (err, user) => {
                                     next(err, user, body);
@@ -220,7 +252,7 @@ class AppModule extends CoreClass {
                                     next(true, user._id);
                                 });
                             }
-                            db.models.user.findOne(
+                            userModel.findOne(
                                 {
                                     username: new RegExp(
                                         `^${body.login}$`,
@@ -257,16 +289,20 @@ class AppModule extends CoreClass {
                                     address = email.email.toLowerCase();
                             });
 
-                            db.models.user.findOne(
+                            userModel.findOne(
                                 { "email.address": address },
                                 next
                             );
                         },
 
                         (user, next) => {
-                            this.utils.generateRandomString(12).then((_id) => {
-                                next(null, user, _id);
-                            });
+                            this.utils
+                                .runJob("GENERATE_RANDOM_STRING", {
+                                    length: 12,
+                                })
+                                .then((_id) => {
+                                    next(null, user, _id);
+                                });
                         },
 
                         (user, _id, next) => {
@@ -294,7 +330,9 @@ class AppModule extends CoreClass {
                         // generate the url for gravatar avatar
                         (user, next) => {
                             this.utils
-                                .createGravatar(user.email.address)
+                                .runJob("CREATE_GRAVATAR", {
+                                    email: user.email.address,
+                                })
                                 .then((url) => {
                                     user.avatar = { type: "gravatar", url };
                                     next(null, user);
@@ -303,22 +341,29 @@ class AppModule extends CoreClass {
 
                         // save the new user to the database
                         (user, next) => {
-                            db.models.user.create(user, next);
+                            userModel.create(user, next);
                         },
 
                         // add the activity of account creation
                         (user, next) => {
-                            activities.addActivity(user._id, "created_account");
+                            activities.runJob("ADD_ACTIVITY", {
+                                userId: user._id,
+                                activityType: "created_account",
+                            });
                             next(null, user);
                         },
 
                         (user, next) => {
-                            mail.schemas.verifyEmail(
-                                address,
-                                body.login,
-                                user.email.verificationToken
-                            );
-                            next(null, user._id);
+                            mail.runJob("GET_SCHEMA", {
+                                schemaName: "verifyEmail",
+                            }).then((verifyEmailSchema) => {
+                                verifyEmailSchema(
+                                    address,
+                                    body.login,
+                                    user.email.verificationToken
+                                );
+                                next(null, user._id);
+                            });
                         },
                     ],
                     async (err, userId) => {
@@ -331,13 +376,17 @@ class AppModule extends CoreClass {
                             return redirectOnErr(res, err);
                         }
 
-                        const sessionId = await this.utils.guid();
-                        cache.hset(
-                            "sessions",
-                            sessionId,
-                            cache.schemas.session(sessionId, userId),
-                            (err) => {
-                                if (err) return redirectOnErr(res, err.message);
+                        const sessionId = await this.utils.runJob("GUID", {});
+                        const sessionSchema = await cache.runJob("GET_SCHEMA", {
+                            schemaName: "session",
+                        });
+                        cache
+                            .runJob("HSET", {
+                                table: "sessions",
+                                key: sessionId,
+                                value: sessionSchema(sessionId, userId),
+                            })
+                            .then(() => {
                                 let date = new Date();
                                 date.setTime(
                                     new Date().getTime() +
@@ -354,17 +403,25 @@ class AppModule extends CoreClass {
                                     `User "${userId}" successfully authorized with GitHub.`
                                 );
                                 res.redirect(`${config.get("domain")}/`);
-                            }
-                        );
+                            })
+                            .catch((err) => {
+                                return redirectOnErr(res, err.message);
+                            });
                     }
                 );
             });
 
             app.get("/auth/verify_email", async (req, res) => {
-                try {
-                    await this._validateHook();
-                } catch {
-                    return;
+                if (this.getStatus() !== "READY") {
+                    this.log(
+                        "INFO",
+                        "APP_REJECTED_GITHUB_AUTHORIZE",
+                        `A user tried to use github authorize, but the APP module is currently not ready.`
+                    );
+                    return redirectOnErr(
+                        res,
+                        "Something went wrong on our end. Please try again later."
+                    );
                 }
 
                 let code = req.query.code;
@@ -377,7 +434,7 @@ class AppModule extends CoreClass {
                         },
 
                         (next) => {
-                            db.models.user.findOne(
+                            userModel.findOne(
                                 { "email.verificationToken": code },
                                 next
                             );
@@ -387,7 +444,7 @@ class AppModule extends CoreClass {
                             if (!user) return next("User not found.");
                             if (user.email.verified)
                                 return next("This email is already verified.");
-                            db.models.user.updateOne(
+                            userModel.updateOne(
                                 { "email.verificationToken": code },
                                 {
                                     $set: { "email.verified": true },

+ 1 - 1
backend/logic/cache/index.js

@@ -244,7 +244,7 @@ class CacheModule extends CoreClass {
                         try {
                             message = JSON.parse(message);
                         } catch (e) {}
-                        subs[channel].cbs.forEach((cb) => payload.cb(message));
+                        subs[channel].cbs.forEach((cb) => cb(message));
                     }
                 );
                 subs[payload.channel].client.subscribe(payload.channel);

+ 6 - 3
backend/logic/playlists.js

@@ -222,7 +222,7 @@ class ExampleModule extends CoreClass {
                             .runJob("HSET", {
                                 table: "playlists",
                                 key: payload.playlistId,
-                                value: playlists,
+                                value: playlist,
                             })
                             .then((playlist) => next(null, playlist))
                             .catch(next);
@@ -252,14 +252,17 @@ class ExampleModule extends CoreClass {
             async.waterfall(
                 [
                     (next) => {
-                        playlistModel.deleteOne({ _id: playlistId }, next);
+                        playlistModel.deleteOne(
+                            { _id: payload.playlistId },
+                            next
+                        );
                     },
 
                     (res, next) => {
                         this.cache
                             .runJob("HDEL", {
                                 table: "playlists",
-                                key: playlistId,
+                                key: payload.playlistId,
                             })
                             .then(() => next())
                             .catch(next);

+ 7 - 6
backend/logic/songs.js

@@ -1,6 +1,7 @@
 const CoreClass = require("../core.js");
 
 const async = require("async");
+const mongoose = require("mongoose");
 
 class SongsModule extends CoreClass {
     constructor() {
@@ -104,7 +105,7 @@ class SongsModule extends CoreClass {
     GET_SONG(payload) {
         //id, cb
         return new Promise(async (resolve, reject) => {
-            const songModel = await db.runJob("GET_MODEL", {
+            const songModel = await this.db.runJob("GET_MODEL", {
                 modelName: "song",
             });
 
@@ -138,7 +139,7 @@ class SongsModule extends CoreClass {
                 (err, song) => {
                     if (err && err !== true) return reject(new Error(err));
 
-                    resolve(song);
+                    resolve({ song });
                 }
             );
         });
@@ -153,7 +154,7 @@ class SongsModule extends CoreClass {
     GET_SONG_FROM_ID(payload) {
         //songId, cb
         return new Promise(async (resolve, reject) => {
-            const songModel = await db.runJob("GET_MODEL", {
+            const songModel = await this.db.runJob("GET_MODEL", {
                 modelName: "song",
             });
             async.waterfall(
@@ -164,7 +165,7 @@ class SongsModule extends CoreClass {
                 ],
                 (err, song) => {
                     if (err && err !== true) return reject(new Error(err));
-                    resolve(song);
+                    resolve({ song });
                 }
             );
         });
@@ -179,7 +180,7 @@ class SongsModule extends CoreClass {
     UPDATE_SONG(payload) {
         //songId, cb
         return new Promise(async (resolve, reject) => {
-            const songModel = await db.runJob("GET_MODEL", {
+            const songModel = await this.db.runJob("GET_MODEL", {
                 modelName: "song",
             });
             async.waterfall(
@@ -225,7 +226,7 @@ class SongsModule extends CoreClass {
     DELETE_SONG(payload) {
         //songId, cb
         return new Promise(async (resolve, reject) => {
-            const songModel = await db.runJob("GET_MODEL", {
+            const songModel = await this.db.runJob("GET_MODEL", {
                 modelName: "song",
             });
             async.waterfall(

+ 130 - 96
backend/logic/stations.js

@@ -73,11 +73,13 @@ class StationsModule extends CoreClass {
                         })
                         .then((playlistObj) => {
                             if (playlistObj) {
-                                this.utils.emitToRoom(
-                                    `station.${stationId}`,
-                                    "event:newOfficialPlaylist",
-                                    playlistObj.songs
-                                );
+                                this.utils.runJob("EMIT_TO_ROOM", {
+                                    room: `station.${stationId}`,
+                                    args: [
+                                        "event:newOfficialPlaylist",
+                                        playlistObj.songs,
+                                    ],
+                                });
                             }
                         });
                 },
@@ -268,12 +270,12 @@ class StationsModule extends CoreClass {
                                 .then((station) => next(null, station))
                                 .catch(next);
                         } else {
-                            this.notifications.schedule(
-                                `stations.nextSong?id=${station._id}`,
-                                timeLeft,
-                                null,
-                                station
-                            );
+                            //name, time, cb, station
+                            this.notifications.runJob("SCHEDULE", {
+                                name: `stations.nextSong?id=${station._id}`,
+                                time: timeLeft,
+                                station,
+                            });
                             next(null, station);
                         }
                     },
@@ -293,10 +295,10 @@ class StationsModule extends CoreClass {
     CALCULATE_SONG_FOR_STATION(payload) {
         //station, cb, bypassValidate = false
         return new Promise(async (resolve, reject) => {
-            const songModel = await db.runJob("GET_MODEL", {
+            const songModel = await this.db.runJob("GET_MODEL", {
                 modelName: "song",
             });
-            const stationModel = await db.runJob("GET_MODEL", {
+            const stationModel = await this.db.runJob("GET_MODEL", {
                 modelName: "station",
             });
 
@@ -351,9 +353,6 @@ class StationsModule extends CoreClass {
                             .runJob("SHUFFLE", { array: playlist })
                             .then((playlist) => next(null, playlist))
                             .catch(next);
-                        this.utils.shuffle(playlist).then((playlist) => {
-                            next(null, playlist);
-                        });
                     },
 
                     (playlist, next) => {
@@ -406,7 +405,10 @@ class StationsModule extends CoreClass {
 
                     (station, next) => {
                         if (station) return next(true, station);
-                        this.stationModel.findOne({ _id: stationId }, next);
+                        this.stationModel.findOne(
+                            { _id: payload.stationId },
+                            next
+                        );
                     },
 
                     (station, next) => {
@@ -426,7 +428,7 @@ class StationsModule extends CoreClass {
                             this.cache
                                 .runJob("HSET", {
                                     table: "stations",
-                                    key: "stationId",
+                                    key: payload.stationId,
                                     value: station,
                                 })
                                 .then()
@@ -468,7 +470,10 @@ class StationsModule extends CoreClass {
                             if (station.type === "official") {
                                 this.runJob(
                                     "CALCULATE_OFFICIAL_PLAYLIST_LIST",
-                                    { stationId, songList: playlist }
+                                    {
+                                        stationId: station._id,
+                                        songList: station.playlist,
+                                    }
                                 );
                             }
                             this.cache
@@ -553,8 +558,9 @@ class StationsModule extends CoreClass {
                 payload.songList,
                 (song, next) => {
                     this.songs
-                        .runJob("GET_SONG", { song })
-                        .then((song) => {
+                        .runJob("GET_SONG", { id: song })
+                        .then((response) => {
+                            const song = response.song;
                             if (song) {
                                 let newSong = {
                                     songId: song.songId,
@@ -618,12 +624,14 @@ class StationsModule extends CoreClass {
                     },
                     (station, next) => {
                         if (!station) return next("Station not found.");
+
                         if (
                             station.type === "community" &&
                             station.partyMode &&
                             station.queue.length === 0
                         )
                             return next(null, null, -11, station); // Community station with party mode enabled and no songs in the queue
+
                         if (
                             station.type === "community" &&
                             station.partyMode &&
@@ -634,7 +642,7 @@ class StationsModule extends CoreClass {
                                 return next(null, null, -19, station);
                             } else {
                                 return this.stationModel.updateOne(
-                                    { _id: stationId },
+                                    { _id: payload.stationId },
                                     {
                                         $pull: {
                                             queue: {
@@ -719,13 +727,16 @@ class StationsModule extends CoreClass {
                                                 )
                                                     this.songs
                                                         .runJob("GET_SONG", {
-                                                            songId:
+                                                            id:
                                                                 playlist[
                                                                     currentSongIndex
                                                                 ]._id,
                                                         })
-                                                        .then((song) =>
-                                                            callback(null, song)
+                                                        .then((response) =>
+                                                            callback(
+                                                                null,
+                                                                response.song
+                                                            )
                                                         )
                                                         .catch(callback);
                                                 else
@@ -739,8 +750,11 @@ class StationsModule extends CoreClass {
                                                                     ].songId,
                                                             }
                                                         )
-                                                        .then((song) =>
-                                                            callback(null, song)
+                                                        .then((response) =>
+                                                            callback(
+                                                                null,
+                                                                response.song
+                                                            )
                                                         )
                                                         .catch(callback);
                                             } else
@@ -774,10 +788,15 @@ class StationsModule extends CoreClass {
                                     else {
                                         this.songs
                                             .runJob("GET_SONG", {
-                                                songId: playlist[0],
+                                                id: playlist[0],
                                             })
-                                            .then((song) => {
-                                                next(null, song, 0, station);
+                                            .then((response) => {
+                                                next(
+                                                    null,
+                                                    response.song,
+                                                    0,
+                                                    station
+                                                );
                                             })
                                             .catch((err) => {
                                                 return next(
@@ -803,16 +822,16 @@ class StationsModule extends CoreClass {
                                     ) {
                                         this.songs
                                             .runJob("GET_SONG", {
-                                                songId:
+                                                id:
                                                     station.playlist[
                                                         station.currentSongIndex +
                                                             1
                                                     ],
                                             })
-                                            .then((song) => {
+                                            .then((response) => {
                                                 return next(
                                                     null,
-                                                    song,
+                                                    response.song,
                                                     station.currentSongIndex + 1
                                                 );
                                             })
@@ -827,8 +846,7 @@ class StationsModule extends CoreClass {
                                                 station,
                                                 bypassQueue:
                                                     payload.bypassQueue,
-                                            },
-                                            { bypassQueue: payload.bypassQueue }
+                                            }
                                         )
                                             .then((newPlaylist) => {
                                                 this.songs.getSong(
@@ -908,14 +926,10 @@ class StationsModule extends CoreClass {
                             { _id: station._id },
                             { $set },
                             (err) => {
-                                this.runJob(
-                                    "UPDATE_STATION",
-                                    {
-                                        stationId: station._id,
-                                        bypassQueue: payload.bypassQueue,
-                                    },
-                                    { bypassQueue: payload.bypassQueue }
-                                )
+                                this.runJob("UPDATE_STATION", {
+                                    stationId: station._id,
+                                    bypassQueue: payload.bypassQueue,
+                                })
                                     .then((station) => {
                                         if (
                                             station.type === "community" &&
@@ -984,48 +998,62 @@ class StationsModule extends CoreClass {
                                 .then()
                                 .catch();
                         } else {
-                            let sockets = await this.utils.getRoomSockets(
-                                "home"
+                            let sockets = await this.utils.runJob(
+                                "GET_ROOM_SOCKETS",
+                                { room: "home" }
                             );
                             for (let socketId in sockets) {
                                 let socket = sockets[socketId];
                                 let session = sockets[socketId].session;
                                 if (session.sessionId) {
-                                    this.cache.hget(
-                                        "sessions",
-                                        session.sessionId,
-                                        (err, session) => {
-                                            if (!err && session) {
-                                                this.db.models.user.findOne(
-                                                    { _id: session.userId },
-                                                    (err, user) => {
-                                                        if (!err && user) {
-                                                            if (
-                                                                user.role ===
-                                                                "admin"
-                                                            )
-                                                                socket.emit(
-                                                                    "event:station.nextSong",
-                                                                    station._id,
-                                                                    station.currentSong
-                                                                );
-                                                            else if (
-                                                                station.type ===
-                                                                    "community" &&
-                                                                station.owner ===
-                                                                    session.userId
-                                                            )
-                                                                socket.emit(
-                                                                    "event:station.nextSong",
-                                                                    station._id,
-                                                                    station.currentSong
-                                                                );
-                                                        }
-                                                    }
-                                                );
+                                    this.cache
+                                        .runJob("HGET", {
+                                            table: "sessions",
+                                            key: session.sessionId,
+                                        })
+                                        .then((session) => {
+                                            if (session) {
+                                                this.db
+                                                    .runJob("GET_MODEL", {
+                                                        modelName: "user",
+                                                    })
+                                                    .then((userModel) => {
+                                                        userModel.findOne(
+                                                            {
+                                                                _id:
+                                                                    session.userId,
+                                                            },
+                                                            (err, user) => {
+                                                                if (
+                                                                    !err &&
+                                                                    user
+                                                                ) {
+                                                                    if (
+                                                                        user.role ===
+                                                                        "admin"
+                                                                    )
+                                                                        socket.emit(
+                                                                            "event:station.nextSong",
+                                                                            station._id,
+                                                                            station.currentSong
+                                                                        );
+                                                                    else if (
+                                                                        station.type ===
+                                                                            "community" &&
+                                                                        station.owner ===
+                                                                            session.userId
+                                                                    )
+                                                                        socket.emit(
+                                                                            "event:station.nextSong",
+                                                                            station._id,
+                                                                            station.currentSong
+                                                                        );
+                                                                }
+                                                            }
+                                                        );
+                                                    });
                                             }
-                                        }
-                                    );
+                                        });
                                 }
                             }
                         }
@@ -1034,19 +1062,19 @@ class StationsModule extends CoreClass {
                             station.currentSong !== null &&
                             station.currentSong.songId !== undefined
                         ) {
-                            this.utils.socketsJoinSongRoom(
-                                await this.utils.getRoomSockets(
-                                    `station.${station._id}`
+                            this.utils.runJob("SOCKETS_JOIN_SONG_ROOM", {
+                                sockets: await this.utils.runJob(
+                                    "GET_ROOM_SOCKETS",
+                                    { room: `station.${station._id}` }
                                 ),
-                                `song.${station.currentSong.songId}`
-                            );
+                                room: `song.${station.currentSong.songId}`,
+                            });
                             if (!station.paused) {
-                                this.notifications.schedule(
-                                    `stations.nextSong?id=${station._id}`,
-                                    station.currentSong.duration * 1000,
-                                    null,
-                                    station
-                                );
+                                this.notifications.runJob("SCHEDULE", {
+                                    name: `stations.nextSong?id=${station._id}`,
+                                    time: station.currentSong.duration * 1000,
+                                    station,
+                                });
                             }
                         } else {
                             this.utils
@@ -1079,11 +1107,17 @@ class StationsModule extends CoreClass {
                         next();
                     },
 
-                    async (next) => {
-                        const userModel = await this.db.runJob("GET_MODEL", {
-                            modelName: "user",
-                        });
-                        userModel.findOne({ _id: userId }, next);
+                    (next) => {
+                        this.db
+                            .runJob("GET_MODEL", {
+                                modelName: "user",
+                            })
+                            .then((userModel) => {
+                                userModel.findOne(
+                                    { _id: payload.userId },
+                                    next
+                                );
+                            });
                     },
 
                     (user, next) => {
@@ -1097,7 +1131,7 @@ class StationsModule extends CoreClass {
                     },
                 ],
                 async (errOrResult) => {
-                    if (errOrResult !== true && err !== "Not allowed") {
+                    if (errOrResult !== true && errOrResult !== "Not allowed") {
                         errOrResult = await this.utils.runJob("GET_ERROR", {
                             error: errOrResult,
                         });

+ 12 - 3
backend/logic/utils.js

@@ -1,5 +1,14 @@
 const CoreClass = require("../core.js");
 
+const config = require("config");
+const async = require("async");
+const request = require("request");
+const crypto = require("crypto");
+
+let youtubeRequestCallbacks = [];
+let youtubeRequestsPending = 0;
+let youtubeRequestsActive = false;
+
 class UtilsModule extends CoreClass {
     constructor() {
         super("utils");
@@ -366,7 +375,7 @@ class UtilsModule extends CoreClass {
         return new Promise((resolve, reject) => {
             for (let id in payload.sockets) {
                 let socket = payload.sockets[id];
-                let rooms = payload.socket.rooms;
+                let rooms = socket.rooms;
                 for (let room in rooms) {
                     if (room.indexOf("song.") !== -1) socket.leave(room);
                 }
@@ -633,7 +642,7 @@ class UtilsModule extends CoreClass {
         });
     }
 
-    GET_SONGS_FROM_SPOTIFY() {
+    GET_SONGS_FROM_SPOTIFY(payload) {
         //title, artist, cb
         return new Promise(async (resolve, reject) => {
             if (!config.get("apis.spotify.enabled"))
@@ -695,7 +704,7 @@ class UtilsModule extends CoreClass {
         });
     }
 
-    SHUFFLE() {
+    SHUFFLE(payload) {
         //array
         return new Promise((resolve, reject) => {
             const array = payload.array.slice();