Browse Source

deal danmaku maximum in back-end

DIYgod 9 years ago
parent
commit
02cbcf4495
6 changed files with 20 additions and 13 deletions
  1. 3 1
      README.md
  2. 1 1
      demo/index.html
  3. 0 0
      dist/DPlayer.min.js
  4. 0 0
      dist/DPlayer.min.js.map
  5. 7 3
      nodejs/index.js
  6. 9 8
      src/DPlayer.js

+ 3 - 1
README.md

@@ -123,9 +123,11 @@ $ npm run build
 
 ## Todo
 
+- [ ] 截图
+
 - [ ] 记录播放位置 记录透明度
 
-- [ ] 中英文切换
+- [ ] 国际化
 
 - [ ] 微博登录
 

+ 1 - 1
demo/index.html

@@ -70,7 +70,7 @@
             id: '9E2E3368B56CDBB4',
             api: 'https://dplayer.daoapp.io/',
             token: 'tokendemo',
-            maximum: 1000
+            maximum: 3000
         }
     });
     dp.init();

File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js.map


+ 7 - 3
nodejs/index.js

@@ -79,7 +79,10 @@ app.get('/', function (req, res) {
     var db = mongoose.connection;
     db.on('error', errorListener);
 
-    var id = url.parse(req.url,true).query.id;
+    var query = url.parse(req.url,true).query;
+    var id = query.id;
+    var max = query.max;
+    var length;
     db.once('open', function() {
         cleanListener();
         danmaku.find({player: id}, function (err, data) {
@@ -88,9 +91,10 @@ app.get('/', function (req, res) {
             }
 
             var json = `{"code": 1,"danmaku":[`;
-            for (var i = 0; i < data.length; i++) {
+            length = max ? Math.min(data.length, max) : data.length;
+            for (var i = 0; i < length; i++) {
                 json += JSON.stringify(data[i]);
-                if (i !== data.length - 1) {
+                if (i !== length - 1) {
                     json += `,`;
                 }
             }

+ 9 - 8
src/DPlayer.js

@@ -837,13 +837,7 @@
                                 alert(response.msg);
                             }
                             else {
-                                if (this.option.danmaku.maximum) {
-                                    this.maximum = parseInt(this.option.danmaku.maximum);
-                                    this.dan = response.danmaku.splice(-this.maximum, this.maximum).sort((a, b) => a.time - b.time);
-                                }
-                                else {
-                                    this.dan = response.danmaku.sort((a, b) => a.time - b.time);
-                                }
+                                this.dan = response.danmaku.sort((a, b) => a.time - b.time);
 
                                 // autoplay
                                 if (this.option.autoplay && !this.isMobile) {
@@ -859,7 +853,14 @@
                         }
                     }
                 };
-                xhr.open('get', this.option.danmaku.api + '?id=' + this.option.danmaku.id, true);
+                let apiurl;
+                if (this.option.danmaku.maximum) {
+                    apiurl = `${this.option.danmaku.api}?id=${this.option.danmaku.id}&max=${this.option.danmaku.maximum}`;
+                }
+                else {
+                    apiurl = `${this.option.danmaku.api}?id=${this.option.danmaku.id}`;
+                }
+                xhr.open('get', apiurl, true);
                 xhr.send(null);
             }
             else {

Some files were not shown because too many files changed in this diff