mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2025-12-07 21:13:10 +00:00
feat: 更新/_info接口响应,优化设备信息返回逻辑
This commit is contained in:
parent
296473633c
commit
87a408d904
@ -28,7 +28,7 @@ router.use(prepareTokenForRateLimit);
|
|||||||
router.get(
|
router.get(
|
||||||
"/_info",
|
"/_info",
|
||||||
tokenReadLimiter,
|
tokenReadLimiter,
|
||||||
errors.catchAsync(async (req, res) => {
|
errors.catchAsync(async (req, res, next) => {
|
||||||
const deviceId = res.locals.deviceId;
|
const deviceId = res.locals.deviceId;
|
||||||
|
|
||||||
// 获取设备信息,包含关联的账号
|
// 获取设备信息,包含关联的账号
|
||||||
@ -43,17 +43,24 @@ router.get(
|
|||||||
return next(errors.createError(404, "设备不存在"));
|
return next(errors.createError(404, "设备不存在"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建响应对象
|
// 构建响应对象:当设备没有关联账号时返回 uuid;若已关联账号则不返回 uuid
|
||||||
const response = {
|
const response = {
|
||||||
device: {
|
device: {
|
||||||
id: device.id,
|
id: device.id,
|
||||||
uuid: device.uuid,
|
|
||||||
name: device.name,
|
name: device.name,
|
||||||
createdAt: device.createdAt,
|
createdAt: device.createdAt,
|
||||||
updatedAt: device.updatedAt,
|
updatedAt: device.updatedAt,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 仅当设备未绑定账号时,包含 uuid 字段
|
||||||
|
if (!device.account) {
|
||||||
|
response.device.uuid = device.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标识是否已绑定账号
|
||||||
|
response.hasAccount = !!device.account;
|
||||||
|
|
||||||
// 如果关联了账号,添加账号信息
|
// 如果关联了账号,添加账号信息
|
||||||
if (device.account) {
|
if (device.account) {
|
||||||
response.account = {
|
response.account = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user