|
|
@@ -4,16 +4,16 @@ import * as PlayerService from './player.service';
|
|
|
import { BadRequestError } from '../../middleware/errorHandler';
|
|
|
import { authMiddleware } from '../../middleware/auth';
|
|
|
|
|
|
-const router = new Router({ prefix: '/api/player' });
|
|
|
+const router = new Router();
|
|
|
|
|
|
// 获取播放进度列表
|
|
|
router.get('/progress', authMiddleware, async (ctx: Context) => {
|
|
|
- const userId = ctx.state.user.userId;
|
|
|
- const { audioId } = ctx.query;
|
|
|
+ const userId = ctx.state.user.userId as number;
|
|
|
+ const { audioId } = ctx.query as { audioId?: string };
|
|
|
|
|
|
const records = await PlayerService.getPlayProgress(
|
|
|
userId,
|
|
|
- audioId ? parseInt(audioId as string) : undefined
|
|
|
+ audioId ? parseInt(audioId) : undefined
|
|
|
);
|
|
|
|
|
|
ctx.body = {
|
|
|
@@ -25,12 +25,13 @@ router.get('/progress', authMiddleware, async (ctx: Context) => {
|
|
|
|
|
|
// 保存播放进度
|
|
|
router.post('/progress', authMiddleware, async (ctx: Context) => {
|
|
|
- const userId = ctx.state.user.userId;
|
|
|
- const { audioId, progress, duration } = ctx.request.body as {
|
|
|
+ const userId = ctx.state.user.userId as number;
|
|
|
+ const body = ctx.request.body as {
|
|
|
audioId: number;
|
|
|
progress: number;
|
|
|
duration: number;
|
|
|
};
|
|
|
+ const { audioId, progress, duration } = body;
|
|
|
|
|
|
if (!audioId || typeof progress !== 'number' || typeof duration !== 'number') {
|
|
|
throw new BadRequestError('参数错误');
|
|
|
@@ -47,8 +48,8 @@ router.post('/progress', authMiddleware, async (ctx: Context) => {
|
|
|
|
|
|
// 删除播放记录
|
|
|
router.delete('/progress/:audioId', authMiddleware, async (ctx: Context) => {
|
|
|
- const userId = ctx.state.user.userId;
|
|
|
- const audioId = parseInt(ctx.params.audioId);
|
|
|
+ const userId = ctx.state.user.userId as number;
|
|
|
+ const audioId = parseInt(ctx.params.audioId as string);
|
|
|
|
|
|
await PlayerService.deletePlayRecord(userId, audioId);
|
|
|
|