const API = require("../../lib/API.js"); const db = require("../../plugin/DataBase/db.js"); const { BaseStdResponse } = require("../../BaseStdResponse.js"); const AccessControl = require("../../lib/AccessControl.js"); const lepao = require("../../lib/Lepao/Lepao.js").lepao // 单次乐跑 class SingleRun extends API { constructor() { super(); this.setPath('/Lepao/SingleRun') this.setMethod('GET') } async onRequest(req, res) { let { uuid, session, student_num } = req.query if ([uuid, session, student_num].some(value => value === '' || value === null || value === undefined)) return res.json({ ...BaseStdResponse.MISSING_PARAMETER, endpoint: 1513126 }) if (!await AccessControl.checkSession(uuid, session)) return res.status(401).json({ ...BaseStdResponse.ACCESS_DENIED }) let sql = 'SELECT token, uid, school_id FROM lepao_account WHERE create_user = ? AND student_num = ?' let rows = await db.query(sql, [uuid, student_num]) if(!rows || rows.length === 0) return res.json({ ...BaseStdResponse.ERR, msg: '发起乐跑失败!未找到对应的账号信息' }) res.json({ ...BaseStdResponse.OK }) lepao.beginLepao(uuid, student_num, rows[0].token, rows[0].uid, rows[0].school_id) } catch(err) { this.logger.error(`手动乐跑失败!${err.stack}`); res.json({ ...BaseStdResponse.ERR, msg: "乐跑失败!数据库异常" }) } } module.exports.SingleRun = SingleRun;