1
1
mirror of https://github.com/ZeroCatDev/ClassworksKV.git synced 2025-12-07 13:03:09 +00:00

feat: 为新设备添加默认自动登录配置

This commit is contained in:
SunWuyuan 2025-11-02 11:53:55 +08:00
parent 2ab90ffebc
commit 296473633c
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64
2 changed files with 48 additions and 0 deletions

View File

@ -13,6 +13,27 @@ import { verifyDevicePassword } from "../utils/crypto.js";
const prisma = new PrismaClient();
/**
* 为新设备创建默认的自动登录配置
* @param {number} deviceId - 设备ID
*/
async function createDefaultAutoAuth(deviceId) {
try {
// 创建默认的自动授权配置不需要密码、类型是classroom一体机
await prisma.autoAuth.create({
data: {
deviceId: deviceId,
password: null, // 无密码
deviceType: "classroom", // 一体机类型
isReadOnly: false, // 非只读
},
});
} catch (error) {
console.error('创建默认自动登录配置失败:', error);
// 这里不抛出错误,避免影响设备创建流程
}
}
/**
* 设备中间件 - 统一处理设备UUID
*
@ -47,6 +68,9 @@ export const deviceMiddleware = errors.catchAsync(async (req, res, next) => {
accountId: null,
},
});
// 为新创建的设备添加默认的自动登录配置
await createDefaultAutoAuth(device.id);
}
// 将设备信息存储到res.locals

View File

@ -9,6 +9,27 @@ import { getOnlineDevices } from "../utils/socket.js";
const prisma = new PrismaClient();
/**
* 为新设备创建默认的自动登录配置
* @param {number} deviceId - 设备ID
*/
async function createDefaultAutoAuth(deviceId) {
try {
// 创建默认的自动授权配置不需要密码、类型是classroom一体机
await prisma.autoAuth.create({
data: {
deviceId: deviceId,
password: null, // 无密码
deviceType: "classroom", // 一体机类型
isReadOnly: false, // 非只读
},
});
} catch (error) {
console.error('创建默认自动登录配置失败:', error);
// 这里不抛出错误,避免影响设备创建流程
}
}
/**
* POST /devices
* 注册新设备
@ -56,6 +77,9 @@ router.post(
},
});
// 为新设备创建默认的自动登录配置
await createDefaultAutoAuth(device.id);
return res.status(201).json({
success: true,
device: {