This commit is contained in:
2024-08-10 20:35:02 +08:00
parent 88233c58e3
commit 90f6ed0bc3
50 changed files with 5333 additions and 0 deletions

View File

View File

@@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
import STANDARDRESPONSE from "../../STANDARDRESPONSE";
import Logger from "../../plugs/Logger";
import MySQLConnection from "../../plugs/database/MySQLConnection";
Logger.info('[API][/download/list] 加载成功')
router.get('/list', async (req: any, res: any) => {
let listRes = await MySQLConnection.execute('SELECT `id`,`recommand`,`title`,`describe`,`addition`,`icon_src` FROM `resource` WHERE `type` = "download"');
if(!listRes){
res.json(STANDARDRESPONSE.SERVER_ERROR)
return;
}
res.json({
...STANDARDRESPONSE.OK,
data: listRes
})
});
export default router;

View File

@@ -0,0 +1,34 @@
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;

View File

@@ -0,0 +1,45 @@
import Logger from "@plugs/Logger";
import STANDARDRESPONSE from "STANDARDRESPONSE";
const express = require('express');
const router = express.Router();
const sharp = require('sharp');
const fs = require('fs');
const path = require("path");
const { v4: uuidv4 } = require('uuid');
Logger.info(`[API][/hmv/rotationVerification] 加载成功`);
// 获取人机验证过程的图片返回一个RVSession用于后续的验证
router.get('/rotationVerification', async (req, res) => {
// 读取图像文件
try {
// 获取随机图片路径
const directoryPath = __dirname.slice(0, -8) + "/assets/RotationVerificationPicture/"
let files = fs.readdirSync(directoryPath);
files = files.filter(file => path.extname(file).toLowerCase() === '.jpg');
let filePath= directoryPath + files[Math.floor(Math.random() * files.length)]
Logger.info("[API][/hmv/rotationVerification] 获取人机验证图片:" + filePath)
// 生成session和角度信息
let session_uuid = uuidv4().replace(/-/g,'');// 32 个字符
const rotateDeg = 60 + Math.floor(Math.random() * 240 );// 限制角度范围 60 ~ 300
// 加入验证池
let RVAddRes = await RotationVerificationService.add(session_uuid, rotateDeg);
if(!RVAddRes){
Logger.err("[API][/hmv/rotationVerification] 添加验证信息到验证池中失败")
res.json({...STANDARDRESPONSE.SERVER_ERROR});
return;
}
// 图片旋转处理
const rotatedImage = await sharp(filePath)
.rotate(-rotateDeg)
.toBuffer();
// 转换为Base64编码
let imageBase64 = "data:image/jpg;base64," + rotatedImage.toString('base64');
Logger.info(`[API][/hmv/rotationVerification] session[${session_uuid}] 验证码图片已生成,角度[${rotateDeg}]`)
res.json({...STANDARDRESPONSE.OK,'data': imageBase64,'session': session_uuid})
} catch (error) {
Logger.err("[API][/hmv/rotationVerification] 获取人机验证图片错误:" + error)
res.json({...STANDARDRESPONSE.SERVER_ERROR})
}
})
module.exports = router;

View File

@@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
import STANDARDRESPONSE from "../../STANDARDRESPONSE";
import Logger from "../../plugs/Logger";
import MySQLConnection from "../../plugs/database/MySQLConnection";
Logger.info('[API][/resource/list] 加载成功')
router.get('/list', async (req: any, res: any) => {
let listRes = await MySQLConnection.execute('SELECT `id`,`recommand`,`title`,`describe`,`addition`,`icon_src`,`src` FROM `resource` WHERE `type` = "resource"');
if(!listRes){
res.json(STANDARDRESPONSE.SERVER_ERROR)
return;
}
res.json({
...STANDARDRESPONSE.OK,
data: listRes
})
});
export default router;