|
|
@@ -1,5 +1,7 @@
|
|
|
const API = require("../../lib/API")
|
|
|
const { v4: uuidv4 } = require('uuid')
|
|
|
+const Redis = require('../../plugin/DataBase/Redis')
|
|
|
+const db = require("../../plugin/DataBase/db.js")
|
|
|
const { BaseStdResponse } = require("../../BaseStdResponse")
|
|
|
const multer = require('multer')
|
|
|
const path = require('path')
|
|
|
@@ -11,7 +13,7 @@ const storage = multer.diskStorage({
|
|
|
destination: (req, file, cb) => {
|
|
|
const { student_num } = req.body
|
|
|
if (!student_num) {
|
|
|
- return cb(new Error('缺少 student_num'))
|
|
|
+ return cb(new Error('缺少参数'))
|
|
|
}
|
|
|
const destPath = path.join('uploads', 'faces', student_num)
|
|
|
fs.mkdirSync(destPath, { recursive: true }) // 确保目录存在
|
|
|
@@ -56,13 +58,13 @@ class UploadFaceVideo extends API {
|
|
|
this.logger.error(`视频上传失败!${err.stack || ''}`)
|
|
|
return res.json({
|
|
|
...BaseStdResponse.ERR,
|
|
|
- msg: '视频上传失败!'
|
|
|
+ msg: err.message ?? '视频上传失败!'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const { student_num } = req.body
|
|
|
+ const { student_num, key } = req.body
|
|
|
|
|
|
- if ([student_num].some(value => value === '' || value === null || value === undefined)) {
|
|
|
+ if ([student_num, key].some(value => value === '' || value === null || value === undefined)) {
|
|
|
return res.json({
|
|
|
...BaseStdResponse.MISSING_PARAMETER
|
|
|
})
|
|
|
@@ -75,13 +77,35 @@ class UploadFaceVideo extends API {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const videoPath = `${url}/uploads/faces/${student_num}/${req.file.filename}`
|
|
|
+ try {
|
|
|
+ const code = await Redis.get(`faceReco:${student_num}`)
|
|
|
+ if (!code || code !== key)
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '令牌已过期!请刷新页面重试'
|
|
|
+ })
|
|
|
+
|
|
|
+ await Redis.del(`faceReco:${student_num}`)
|
|
|
+ } catch (err) {
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '令牌验证失败!请刷新页面重试'
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const videoPath = `/uploads/faces/${student_num}/${req.file.filename}`
|
|
|
+ const time = new Date().getTime()
|
|
|
+
|
|
|
+ let sql = 'INSERT INTO lepao_face (student_num, video_path, create_time, state) VALUES (?, ?, ?, ?)'
|
|
|
+ let rows = await db.query(sql, [student_num, videoPath, time, 1])
|
|
|
+ if (!rows || rows.affectedRows !== 1)
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '上传失败,请稍后再试'
|
|
|
+ })
|
|
|
|
|
|
res.json({
|
|
|
- ...BaseStdResponse.OK,
|
|
|
- data: {
|
|
|
- videoPath
|
|
|
- }
|
|
|
+ ...BaseStdResponse.OK
|
|
|
})
|
|
|
})
|
|
|
}
|