浏览代码

Merge branch 'master' of https://github.com/AkiraLaine/music-app

unknown 9 年之前
父节点
当前提交
2906c064cd
共有 2 个文件被更改,包括 14 次插入6 次删除
  1. 1 0
      app/.meteor/packages
  2. 13 6
      app/app.js

+ 1 - 0
app/.meteor/packages

@@ -26,3 +26,4 @@ ejson
 joncursi:socket-io-client
 meteorhacks:async
 altapp:recaptcha
+http

+ 13 - 6
app/app.js

@@ -1,4 +1,5 @@
 History = new Mongo.Collection("history");
+Playlists = new Mongo.Collection("playlists");
 
 if (Meteor.isClient) {
     Meteor.startup(function() {
@@ -189,7 +190,8 @@ if (Meteor.isClient) {
 
     Template.playlist.helpers({
         playlist_songs: function() {
-
+            console.log(Playlists.find({type: "edm"}).fetch());
+            return Playlists.find({type: "edm"}).fetch()[0].songs;
         }
     });
 
@@ -313,6 +315,7 @@ if (Meteor.isClient) {
         }
 
         Meteor.subscribe("history");
+        Meteor.subscribe("playlists");
         Meteor.setInterval(function() {
             var data = undefined;
             var dataCursor = History.find({type: "edm"});
@@ -342,6 +345,10 @@ if (Meteor.isServer) {
         });
     });
 
+    if (Playlists.find({type: "edm"}).fetch().length === 0) {
+        Playlists.insert({type: "edm", songs: [{id: "aE2GCa-_nyU", title: "Radioactive - Lindsey Stirling and Pentatonix", duration: 264, type: "youtube"}, {id: "aHjpOzsQ9YI", title: "Crystallize", artist: "Linsdey Stirling", duration: 300, type: "youtube"}]});
+    }
+
     var duration = 226440;
 
     Meteor.users.deny({update: function () { return true; }});
@@ -349,11 +356,7 @@ if (Meteor.isServer) {
     Meteor.users.deny({remove: function () { return true; }});
 
     var startedAt = Date.now();
-    var songs = [
-      {id: "aE2GCa-_nyU", title: "Radioactive - Lindsey Stirling and Pentatonix", duration: 264, type: "youtube"},
-      {id: "aHjpOzsQ9YI", title: "Crystallize", artist: "Linsdey Stirling", duration: 300, type: "youtube"}
-      // {id: 172055891, title: "Immortals", artist: "Fall Out Boy", duration: 244, type: "soundcloud"}
-    ];
+    var songs = Playlists.find({type: "edm"}).fetch()[0].songs;
     var currentSong = 0;
     addToHistory(songs[currentSong], startedAt);
 
@@ -402,6 +405,10 @@ if (Meteor.isServer) {
         return History.find({type: "edm"})
     });
 
+    Meteor.publish("playlists", function() {
+        return Playlists.find({type: "edm"})
+    });
+
     Meteor.methods({
         createUserMethod: function(formData, captchaData) {
             var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData);