2
0
Эх сурвалжийг харах

Fixed lots of things that got broken with the new implementation of schemas.

KrisVos130 9 жил өмнө
parent
commit
41c8270db2

+ 3 - 3
app/client/client.js

@@ -1669,7 +1669,7 @@ Template.room.onCreated(function () {
                     }
                 }
 
-                if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
+                if (room.currentSong.song !== undefined && (currentSongR === undefined || room.currentSong.started !== currentSongR.started)) {
                     Session.set("previousSong", currentSong);
                     currentSongR = room.currentSong;
 
@@ -1840,7 +1840,7 @@ Template.stations.events({
     "click #moveSong": function(e){
       var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
       if (genre !== Session.get(genre)) {
-        Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes});
+        Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes, requestedBy: Session.get("song").requestedBy});
         Meteor.call("removeSongFromPlaylist", Session.get("genre"), Session.get("song").mid);
       }else {
         console.log("Something Went Wrong?!");
@@ -1850,7 +1850,7 @@ Template.stations.events({
     },
     "click #copySong": function(e){
       var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
-      Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes});
+      Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes, requestedBy: Session.get("song").requestedBy});
     },
     "click .copyMove-button": function(e){
         Session.set("song", this);

+ 141 - 116
app/database/schemas.js

@@ -1,5 +1,109 @@
 var Schemas = {};
 
+Schemas.FullSong = new SimpleSchema({
+    "id": {
+        type: String,
+        label: "Song YouTube id"
+    },
+    "mid": {
+        type: String,
+        label: "Song mid"
+    },
+    "likes": {
+        type: Number,
+        label: "Song likes",
+        defaultValue: 0
+    },
+    "dislikes": {
+        type: Number,
+        label: "Song dislikes",
+        defaultValue: 0
+    },
+    "title": {
+        type: String,
+        label: "Song title"
+    },
+    "artist": {
+        type: String,
+        label: "Song artist"
+    },
+    "img": {
+        type: String,
+        label: "Song img"
+    },
+    "type": {
+        type: String,
+        label: "Song type",
+        defaultValue: "YouTube"
+    },
+    "duration": {
+        type: Number,
+        label: "Song duration",
+        min: 0,
+        decimal: true
+    },
+    "skipDuration": {
+        type: Number,
+        label: "Song skipDuration",
+        min: 0,
+        decimal: true
+    }
+});
+
+Schemas.QueueSong = new SimpleSchema({
+    "id": {
+        type: String,
+        label: "Song YouTube id"
+    },
+    "mid": {
+        type: String,
+        label: "Song mid"
+    },
+    "likes": {
+        type: Number,
+        label: "Song likes",
+        defaultValue: 0
+    },
+    "dislikes": {
+        type: Number,
+        label: "Song dislikes",
+        defaultValue: 0
+    },
+    "title": {
+        type: String,
+        label: "Song title"
+    },
+    "artist": {
+        type: String,
+        label: "Song artist"
+    },
+    "img": {
+        type: String,
+        label: "Song img"
+    },
+    "type": {
+        type: String,
+        label: "Song type",
+        defaultValue: "YouTube"
+    },
+    "duration": {
+        type: Number,
+        label: "Song duration",
+        min: 0,
+        decimal: true
+    },
+    "skipDuration": {
+        type: Number,
+        label: "Song skipDuration",
+        min: 0,
+        decimal: true
+    },
+    "songs.$.requestedBy": {
+        type: String,
+        label: "User ID of the person who requested the song"
+    }
+});
+
 Schemas.Chat = new SimpleSchema({
     type: {
         type: String,
@@ -12,7 +116,8 @@ Schemas.Chat = new SimpleSchema({
     },
     rank: {
         type: String,
-        label: "Display tag of the rank of the user who sent a message"
+        label: "Display tag of the rank of the user who sent a message",
+        optional: true
     },
     message: {
         type: String,
@@ -65,6 +170,14 @@ Schemas.Room = new SimpleSchema({
         defaultValue: {},
         label: "Current Song"
     },
+    "currentSong.song": {
+        type: Schemas.FullSong,
+        label: "Current Song Object"
+    },
+    "currentSong.started": {
+        type: Number,
+        label: "Current Song Start Date"
+    },
     timePaused: {
         type: Number,
         defaultValue: 0,
@@ -106,62 +219,9 @@ Schemas.Playlist = new SimpleSchema({
         label: "All songs in that playlist"
     },
     "songs.$": {
-        type: Object,
+        type: Schemas.FullSong,
         label: "Song object"
     },
-    "songs.$.id": {
-        type: String,
-        label: "Song YouTube id"
-    },
-    "songs.$.mid": {
-        type: String,
-        label: "Song mid"
-    },
-    "songs.$.likes": {
-        type: Number,
-        label: "Song likes",
-        defaultValue: 0
-    },
-    "songs.$.dislikes": {
-        type: Number,
-        label: "Song dislikes",
-        defaultValue: 0
-    },
-    "songs.$.title": {
-        type: String,
-        label: "Song title"
-    },
-    "songs.$.artist": {
-        type: String,
-        label: "Song artist"
-    },
-    "songs.$.img": {
-        type: String,
-        label: "Song img"
-    },
-    "songs.$.type": {
-        type: String,
-        label: "Song type",
-        defaultValue: "YouTube"
-    },
-    "songs.$.duration": {
-        type: Number,
-        label: "Song duration",
-        min: 0
-    },
-    "songs.$.skipDuration": {
-        type: Number,
-        label: "Song skipDuration",
-        min: 0
-    },
-    "songs.$.requestedBy": {
-        type: String,
-        label: "User ID of the person who requested the song"
-    },
-    "songs.$.approvedBy": {
-        type: String,
-        label: "User ID of the person who approved the song"
-    },
     lastSong: {
         type: Number,
         label: "Index of the previous song",
@@ -180,69 +240,28 @@ Schemas.Queue = new SimpleSchema({
         label: "All songs in that playlist"
     },
     "songs.$": {
-        type: Object,
+        type: Schemas.QueueSong,
         label: "Song object"
-    },
-    "songs.$.id": {
-        type: String,
-        label: "Song YouTube id"
-    },
-    "songs.$.mid": {
-        type: String,
-        label: "Song mid"
-    },
-    "songs.$.likes": {
-        type: Number,
-        label: "Song likes",
-        defaultValue: 0
-    },
-    "songs.$.dislikes": {
-        type: Number,
-        label: "Song dislikes",
-        defaultValue: 0
-    },
-    "songs.$.title": {
-        type: String,
-        label: "Song title"
-    },
-    "songs.$.artist": {
-        type: String,
-        label: "Song artist"
-    },
-    "songs.$.img": {
-        type: String,
-        label: "Song img"
-    },
-    "songs.$.type": {
-        type: String,
-        label: "Song type",
-        defaultValue: "YouTube"
-    },
-    "songs.$.duration": {
-        type: Number,
-        label: "Song duration",
-        min: 0
-    },
-    "songs.$.skipDuration": {
-        type: Number,
-        label: "Song skipDuration",
-        min: 0
-    },
-    "songs.$.requestedBy": {
-        type: String,
-        label: "User ID of the person who requested the song"
     }
 });
 
 Schemas.UserProfile = new SimpleSchema({
     username: {
         type: String,
-        label: "User's Username"
+        label: "User's Username",
+        regEx: /^[a-zA-Z0-9_]+$/,
+        min: 6,
+        max: 26
     },
     usernameL: {
         type: String,
         label: "User's Username in lowercase",
-        regEx: /^[a-z0-9_]$/
+        regEx: /^[a-z0-9_]+$/
+    },
+    realname: {
+        type: String,
+        label: "User's Real Name",
+        regEx: /^[A-Za-z0-9 .'-]+$/
     },
     rank: {
         type: String,
@@ -288,7 +307,8 @@ Schemas.UserProfile = new SimpleSchema({
 Schemas.UserPunishments = new SimpleSchema({
     mute: {
         type: Object,
-        label: "User's Current Mute Info"
+        label: "User's Current Mute Info",
+        optional: true
     },
     "mute.mutedBy": {
         type: String,
@@ -304,7 +324,8 @@ Schemas.UserPunishments = new SimpleSchema({
     },
     mutes: {
         type: Array,
-        label: "All of the mutes of a user"
+        label: "All of the mutes of a user",
+        optional: true
     },
     "mutes.$": {
         type: Object,
@@ -324,7 +345,8 @@ Schemas.UserPunishments = new SimpleSchema({
     },
     ban: {
         type: Object,
-        label: "User's Current Ban Info"
+        label: "User's Current Ban Info",
+        optional: true
     },
     "ban.bannedBy": {
         type: String,
@@ -340,7 +362,8 @@ Schemas.UserPunishments = new SimpleSchema({
     },
     bans: {
         type: Array,
-        label: "All of the bans of a user"
+        label: "All of the bans of a user",
+        optional: true
     },
     "bans.$": {
         type: Object,
@@ -366,7 +389,10 @@ Schemas.User = new SimpleSchema({
         // For accounts-password, either emails or username is required, but not both. It is OK to make this
         // optional here because the accounts-password package does its own validation.
         // Third-party login packages may not require either. Adjust this schema as necessary for your usage.
-        optional: true
+        optional: true,
+        regEx: /^[a-zA-Z0-9_]+$/,
+        min: 6,
+        max: 26
     },
     emails: {
         type: Array,
@@ -392,7 +418,8 @@ Schemas.User = new SimpleSchema({
         type: Schemas.UserProfile
     },
     punishments: {
-        type: Schemas.UserPunishments
+        type: Schemas.UserPunishments,
+        defaultValue: {mutes: [], bans: []}
     },
     // Make sure this services field is in your schema if you're using any of the accounts packages
     services: {
@@ -456,6 +483,4 @@ Chat.attachSchema(Schemas.Chat);
 Playlists.attachSchema(Schemas.Playlist);
 Queues.attachSchema(Schemas.Queue);
 Meteor.users.attachSchema(Schemas.User);
-Reports.attachSchema(Schemas.Report);
-
-//Rooms.insert({display: "Test Room", type: "testest"});
+Reports.attachSchema(Schemas.Report);

+ 13 - 45
app/server/server.js

@@ -101,17 +101,7 @@ function createRoom(display, tag, private) {
             if (err) {
                 throw err;
             } else {
-                if (Playlists.find({type: type}).count() === 1) {
-                    stations.push(new Station(type));
-                } else {
-                    Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
-                        if (err2) {
-                            throw err2;
-                        } else {
-                            stations.push(new Station(type));
-                        }
-                    });
-                }
+                stations.push(new Station(type));
             }
         });
     } else if (Rooms.find({type: type}).count() === 0 && private === true) {
@@ -119,17 +109,7 @@ function createRoom(display, tag, private) {
             if (err) {
                 throw err;
             } else {
-                if (Playlists.find({type: type}).count() === 1) {
-                    stations.push(new Station(type));
-                } else {
-                    Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
-                        if (err2) {
-                            throw err2;
-                        } else {
-                            stations.push(new Station(type));
-                        }
-                    });
-                }
+                stations.push(new Station(type));
             }
         });
     } else {
@@ -157,7 +137,8 @@ function Station(type) {
     } else currentSong = 0;
     var currentTitle = songs[currentSong].title;
 
-    Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}, users: 0}});
+    var res = Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}, users: 0}});
+    console.log(res);
 
     this.skipSong = function() {
         self.voted = [];
@@ -339,6 +320,7 @@ function getSongDuration(query, artistName){
             }
         }
     }
+    return 0;
 }
 
 function getSongAlbumArt(query, artistName){
@@ -359,29 +341,10 @@ function getSongAlbumArt(query, artistName){
 //var room_types = ["edm", "nightcore"];
 var songsArr = [];
 
-function getSongsByType(type) {
-    if (type === "edm") {
-        return [
-            {id: "aE2GCa-_nyU", mid: "fh6_Gf", title: "Radioactive", duration: getSongDuration("Radioactive - Lindsey Stirling and Pentatonix", "Lindsey Stirling, Pentatonix"), artist: "Lindsey Stirling, Pentatonix", type: "YouTube", img: "https://i.scdn.co/image/62167a9007cef2e8ef13ab1d93019312b9b03655"},
-            {id: "aHjpOzsQ9YI", mid: "goG88g", title: "Crystallize", artist: "Lindsey Stirling", duration: getSongDuration("Crystallize", "Lindsey Stirling"), type: "YouTube", img: "https://i.scdn.co/image/b0c1ccdd0cd7bcda741ccc1c3e036f4ed2e52312"}
-        ];
-    } else if (type === "nightcore") {
-        return [{id: "f7RKOP87tt4", mid: "5pGGog", title: "Monster (DotEXE Remix)", duration: getSongDuration("Monster (DotEXE Remix)", "Meg & Dia"), artist: "Meg & Dia", type: "YouTube", img: "https://i.scdn.co/image/35ecdfba9c31a6c54ee4c73dcf1ad474c560cd00"}];
-    } else {
-        return [{id: "dQw4w9WgXcQ", mid: "6_fdr4", title: "Never Gonna Give You Up", duration: getSongDuration("Never Gonna Give You Up", "Rick Astley"), artist: "Rick Astley", type: "YouTube", img: "https://i.scdn.co/image/5246898e19195715e65e261899baba890a2c1ded"}];
-    }
-}
-
 Rooms.find({}).fetch().forEach(function(room) {
     var type = room.type;
     if (Playlists.find({type: type}).count() === 0) {
-        if (type === "edm") {
-            Playlists.insert({type: type, songs: getSongsByType(type)});
-        } else if (type === "nightcore") {
-            Playlists.insert({type: type, songs: getSongsByType(type)});
-        } else {
-            Playlists.insert({type: type, songs: getSongsByType(type)});
-        }
+        Playlists.insert({type: type, songs: []});
     }
     if (Playlists.findOne({type: type}).songs.length === 0) {
         // Add a global video to Playlist so it can proceed
@@ -877,7 +840,7 @@ Meteor.methods({
                     Queues.insert({type: type, songs: []});
                 }
                 if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
-                    songData.duration = getSongDuration(songData.title, songData.artist) || 0;
+                    songData.duration = Number(getSongDuration(songData.title, songData.artist));
                     songData.img = getSongAlbumArt(songData.title, songData.artist) || "";
                     songData.skipDuration = 0;
                     songData.likes = 0;
@@ -997,12 +960,17 @@ Meteor.methods({
                                 type: songData.type,
                                 likes: Number(songData.likes),
                                 dislikes: Number(songData.dislikes),
-                                requesedBy: songData.requestedBy,
+                                requestedBy: songData.requestedBy,
                                 approvedBy: Meteor.userId()
                             }
                         }
                     });
                     Queues.update({type: type}, {$pull: {songs: {mid: songData.mid}}});
+                    getStation(type, function(station) {
+                        if (station === undefined) {
+                            stations.push(new Station(type));
+                        }
+                    });
                     return true;
                 } else {
                     throw new Meteor.Error(403, "Invalid data.");