Files
tonePage/Server/apis/hmv/checkRotationVerification.js
2024-08-10 20:35:02 +08:00

34 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const express = require('express');
const router = express.Router();
const { Logger } = require('@plugs/Logger');
const { STANDARDRESPONSE } = require('@root/STANDARDRESPONSE')
const { RotationVerificationService } = require('@plugs/Service/RotationVerificationService');
Logger.info(`[API][/hmv/checkRotationVerification] 加载成功`);
// 验证旋转验证传入RVSession和用户旋转角度返回验证结果
router.post('/checkRotationVerification', async (req, res) => {
let { session, angle } = req.body;
// session为RVSession(32位UUID)angle为用户旋转角度
if(!session || !angle || session.length != 32){
Logger.warn(`[API][/hmv/checkRotationVerification]参数缺失或错误(session=${session}, angle=${angle})`);
res.json({...STANDARDRESPONSE.PARAMETER_MISSING});
return;
}
let result = await RotationVerificationService.check(session,angle);
switch(result){
case 0:
Logger.info(`[API][/hmv/checkRotationVerification] session[${session}]已过期,验证未通过`);
res.json({...STANDARDRESPONSE.ROTATION_VERIFICATION_EXPIRED, endpoint: result});
return;
case -1:
Logger.info(`[API][/hmv/checkRotationVerification] session[${session}]验证次数已达上限,验证未通过`);
res.json({...STANDARDRESPONSE.ROTATION_VERIFICATION_MAX_ATTEMPTS, endpoint: result});
return;
case -2:
Logger.info(`[API][/hmv/checkRotationVerification] session[${session}]验证角度差异过大,验证未通过`);
res.json({...STANDARDRESPONSE.ROTATION_VERIFICATION_ANGLE_DIFFERENCE, endpoint: result});
return;
}
Logger.info(`[API][/hmv/checkRotationVerification] session[${session}]验证通过`);
res.json({...STANDARDRESPONSE.OK});
})
module.exports = router;