back-end: id list

This commit is contained in:
DIYgod 2016-05-20 10:33:55 +08:00
parent 1d22794bde
commit 697dbdf5bd
No known key found for this signature in database
GPG Key ID: F8797DD1088C6506
3 changed files with 50 additions and 3 deletions

View File

@ -56,7 +56,7 @@ var option = {
pic: '若能绽放光芒.png' // Optional, music picture
},
danmaku: { // Optional, showing danmaku
id: '9E2E3368B56CDBB4', // Required, danmaku id, MUST BE UNIQUE
id: '9E2E3368B56CDBB4', // Required, danmaku id, MUST BE UNIQUE, CAN NOT USE THESE IN YOUR NEW PLAYER: `https://dplayer.daoapp.io/list`
api: 'https://dplayer.daoapp.io/', // Required, danmaku api
token: 'tokendemo' // Optional, danmaku token for api
}
@ -90,6 +90,19 @@ var dp = new DPlayer({
});
```
### Danmaku back-end
**Ready-made API:**
`https://dplayer.daoapp.io/`
**Build yourself:**
Required environment
- Node.js
- Mongodb
## Run in development
```

View File

@ -35,7 +35,9 @@ else {
}
var danmakuSchema = new mongoose.Schema({
player: String,
player: {
type: [String], index: true
},
author: String,
time: Number,
text: String,
@ -218,4 +220,36 @@ app.post('/', function (req, res) {
}
});
app.get('/list', function (req, res) {
mongoose.connect(mongodbUrl);
var db = mongoose.connection;
db.on('error', errorListener);
db.once('open', function() {
cleanListener();
danmaku.distinct('player', function (err, data) {
if (err) {
logger.error(err);
}
var json = ``;
for (var i = 0; i < data.length; i++) {
json += data[i] + `<br>`;
}
res.send(json);
db.close();
})
});
function errorListener (err) {
cleanListener();
logger.error(err);
res.send(`{"code": 0, "msg": "Error happens, please contact system administrator."}`);
}
function cleanListener () {
db.removeListener('error', errorListener);
}
});
app.listen(1207);

View File

@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "0.1.0",
"version": "0.1.2",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"scripts": {