-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from UestcCarpediem/dev_backend
Dev backend
- Loading branch information
Showing
27 changed files
with
635 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# doc | ||
|
||
api.md - server接口文档 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# api document | ||
|
||
接口文档 | ||
|
||
## 获取视频流 | ||
|
||
获取播放视频的接口 | ||
|
||
```javascript | ||
url: /api/video/getlist | ||
methon: GET | ||
request: | ||
{ | ||
id=numbser // 默认为1即可,视频的编号,用于区分已经看到的位置,不填服务器默认为0 | ||
} | ||
response: | ||
[{ | ||
'id': 0, | ||
author: 'w3.org', | ||
url: 'https://media.w3.org/2020/08/ml-workshop/virtual-character-web-meeting.mp4', | ||
desc: 'virtual-character-web-meeting.mp4', | ||
tags: [ | ||
'mc', 'course', | ||
], | ||
like: 10000, | ||
comment: 20000, | ||
share: 1000, | ||
}] | ||
``` | ||
|
||
## 获取直播流 | ||
|
||
获取直播流数据的接口 | ||
```javascript | ||
url: /api/live/getlist | ||
methon: GET | ||
request: | ||
{ | ||
id=number // 默认为1即可,直播流的编号,用于区分已经看到的位置,不填服务器默认为0 | ||
} | ||
response: | ||
[{ | ||
id: 0, | ||
author: 'cctv', | ||
url: 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8', | ||
desc: 'cctv - 1', | ||
createdAt: '2021-01-26T19:30:22.420Z', | ||
updatedAt: '2020-01-30T10:24:26.590Z' , | ||
like: 0, | ||
comment: 0, | ||
share: 0, | ||
}] | ||
``` | ||
|
||
## Socket.io | ||
|
||
```javascript | ||
url: /ws | ||
``` | ||
|
||
## 报错 | ||
|
||
```javascript | ||
response: | ||
{ | ||
code: 404, | ||
msg: 'url invalid', | ||
request: Object, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'egg-mock', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "eslint-config-egg" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 2 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [10] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- name: Checkout Git Source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Dependencies | ||
run: npm i -g npminstall && npminstall | ||
|
||
- name: Continuous Integration | ||
run: npm run ci | ||
|
||
- name: Code Coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
logs/ | ||
npm-debug.log | ||
yarn-error.log | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage/ | ||
.idea/ | ||
.vscode | ||
temp/ | ||
run/ | ||
.DS_Store | ||
*.sw* | ||
*.un~ | ||
typings/ | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
language: node_js | ||
node_js: | ||
- '10' | ||
before_install: | ||
- npm i npminstall -g | ||
install: | ||
- npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# tiktok-server | ||
|
||
server for tiktok-like webapp | ||
|
||
## QuickStart | ||
|
||
<!-- add docs here for user --> | ||
|
||
see [egg docs][egg] for more detail. | ||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### npm scripts | ||
|
||
- Use `npm run lint` to check code style. | ||
- Use `npm test` to run unit test. | ||
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. | ||
|
||
|
||
[egg]: https://eggjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class ErrorController extends Controller { | ||
async pageNotFound() { | ||
const { ctx } = this; | ||
ctx.body = { | ||
code: 404, | ||
msg: `url:${ctx.request.url} is invalid`, | ||
request: ctx.request.toJSON(), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = ErrorController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
const { ctx } = this; | ||
ctx.body = 'server runing successful!'; | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class LiveController extends Controller { | ||
async getLiveList() { | ||
const { ctx } = this; | ||
const ldata = await ctx.service.live.getLiveList(0); | ||
ctx.body = ldata; | ||
} | ||
} | ||
|
||
module.exports = LiveController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class VideoController extends Controller { | ||
async getVideoList() { | ||
const { ctx } = this; | ||
const vdata = await ctx.service.video.getViderList(0); | ||
ctx.body = vdata; | ||
} | ||
} | ||
|
||
module.exports = VideoController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// {app_root}/app/io/controller/default.js | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
class Controller extends app.Controller { | ||
async rejoin() { | ||
const { ctx } = this; | ||
const message = ctx.args[0]; | ||
console.log(ctx.args); | ||
await ctx.socket.emit('res', `Hi! I've got your message: ${message}`); | ||
} | ||
async chat() { | ||
const { ctx } = this; | ||
const message = ctx.args[0]; | ||
console.log(ctx.args); | ||
await ctx.socket.emit('res', `Hi! I've got your message: ${message}`); | ||
} | ||
} | ||
return Controller; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
// {app_root}/app/io/middleware/connection.js | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
module.exports = app => { | ||
return async (ctx, next) => { | ||
// console.log('auth:', ctx.query); | ||
ctx.socket.emit('res', 'connected!'); | ||
await next(); | ||
// execute when disconnect. | ||
console.log('disconnection!'); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
// {app_root}/app/io/middleware/packet.js | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
module.exports = app => { | ||
return async (ctx, next) => { | ||
ctx.socket.emit('res', 'packet received!'); | ||
console.log('packet:', this); | ||
await next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @param {Egg.Application} app - egg application | ||
*/ | ||
module.exports = app => { | ||
const { router, controller, io } = app; | ||
router.get('/', controller.home.index); | ||
|
||
// 获取视频列表 | ||
router.get('/api/video/getlist', controller.video.getVideoList); | ||
|
||
// 获取直播流列表 | ||
router.get('/api/live/getlist', controller.live.getLiveList); | ||
|
||
// websocket.io | ||
io.of('/ws').route('rejoin', io.controller.default.rejoin); | ||
|
||
io.of('/ws').route('chat', io.controller.default.chat); | ||
|
||
// 错误url处理 | ||
router.get(/^.*$/i, controller.error.pageNotFound); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const Service = require('egg').Service; | ||
|
||
class LiveService extends Service { | ||
// 从数据库获取视频列表 | ||
async getLiveList(vid = 0) { | ||
const vdata = [{ | ||
id: vid, | ||
author: 'cctv', | ||
url: 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8', | ||
desc: 'cctv - 1', | ||
createdAt: '2021-01-26T19:30:22.420Z', | ||
updatedAt: '2020-01-30T10:24:26.590Z', | ||
like: 0, | ||
comment: 0, | ||
share: 0, | ||
}, { | ||
id: vid + 1, | ||
author: 'cctv', | ||
url: 'http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8', | ||
desc: 'cctv - 2', | ||
createdAt: '2021-01-26T19:30:22.420Z', | ||
updatedAt: '2020-01-30T10:24:26.590Z', | ||
like: 0, | ||
comment: 0, | ||
share: 0, | ||
}]; | ||
return vdata; | ||
} | ||
} | ||
|
||
|
||
module.exports = LiveService; |
Oops, something went wrong.