From 31aac06f3f9dac3a4e76297369ba4842818088af Mon Sep 17 00:00:00 2001 From: Sunwuyuan Date: Sun, 11 Jan 2026 15:37:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0OAuth=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E8=80=85=E7=9A=84URL=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=95=99=E5=B8=88=E5=90=8D=E7=A7=B0=E7=9A=84?= =?UTF-8?q?API=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BF=AE=E6=94=B9Socket=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/oauth.js | 6 +++--- routes/apps.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ utils/socket.js | 2 +- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/config/oauth.js b/config/oauth.js index d99e38c..8e38584 100644 --- a/config/oauth.js +++ b/config/oauth.js @@ -18,9 +18,9 @@ export const oauthProviders = { zerocat: { clientId: process.env.ZEROCAT_CLIENT_ID, clientSecret: process.env.ZEROCAT_CLIENT_SECRET, - authorizationURL: "https://zerocat-api.houlangs.com/oauth/authorize", - tokenURL: "https://zerocat-api.houlangs.com/oauth/token", - userInfoURL: "https://zerocat-api.houlangs.com/oauth/userinfo", + authorizationURL: "https://zerocat-api.houlang.cloud/oauth/authorize", + tokenURL: "https://zerocat-api.houlang.cloud/oauth/token", + userInfoURL: "https://zerocat-api.houlang.cloud/oauth/userinfo", scope: "user:basic user:email", // 展示相关 name: "ZeroCat", diff --git a/routes/apps.js b/routes/apps.js index be79535..52460f1 100644 --- a/routes/apps.js +++ b/routes/apps.js @@ -338,6 +338,54 @@ router.post( }) ); +/** + * POST /apps/tokens/:token/set-teacher-name + * 设置教师名称 (仅限教师类型的 token) + * Body: { name: string } + */ +router.post( + "/tokens/:token/set-teacher-name", + errors.catchAsync(async (req, res, next) => { + const {token} = req.params; + const {name} = req.body; + + if (!name) { + return next(errors.createError(400, "需要提供教师名称")); + } + + // 查找 token 对应的应用安装记录 + const appInstall = await prisma.appInstall.findUnique({ + where: {token}, + include: { + device: true, + }, + }); + + if (!appInstall) { + return next(errors.createError(404, "Token 不存在")); + } + + // 验证 token 类型是否为 teacher + if (appInstall.deviceType !== 'teacher') { + return next(errors.createError(403, "只有教师类型的 token 可以使用此接口")); + } + + // 更新 AppInstall 的 note 字段为教师名称 + const updatedInstall = await prisma.appInstall.update({ + where: {id: appInstall.id}, + data: {note: name}, + }); + + return res.json({ + success: true, + token: updatedInstall.token, + name: updatedInstall.note, + deviceType: updatedInstall.deviceType, + updatedAt: updatedInstall.updatedAt, + }); + }) +); + /** * PUT /apps/tokens/:token/note * 更新令牌的备注信息 diff --git a/utils/socket.js b/utils/socket.js index 6812522..5e95281 100644 --- a/utils/socket.js +++ b/utils/socket.js @@ -245,7 +245,7 @@ export function initSocket(server) { senderInfo: { appId: tokenInfo?.appId, deviceType: tokenInfo?.deviceType, - deviceName: tokenInfo?.deviceName, + deviceName: tokenInfo?.note, isReadOnly: tokenInfo?.isReadOnly || false, note: tokenInfo?.note }