From 1e1f8d5e9b0afe6d500fa0551b05868c74a23f06 Mon Sep 17 00:00:00 2001 From: transcai Date: Mon, 10 Apr 2023 15:47:35 +0800 Subject: [PATCH] add applicationId --- README.md | 14 ++++++++------ routes/car.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0e8cbb9..22c00b3 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ curl -X POST --data "ClientSession=xxx&RequestId=req123&UserId=userid123&Project | ------------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------- | | UserId | string | 是 | 用户 ID,业务自定义生成,不同用户需要生成不同 UserId 来区分 | | ProjectId | string | 是 | 项目 ID,应用云渲染项目创建时生成,[项目管理](https://console.cloud.tencent.com/car/project) 中获取,格式为 cap-xxx | +| ApplicationId | string | 否 | 应用 ID,多应用共享项目请求时有效,应用云渲染应用创建时生成,[应用管理](https://console.cloud.tencent.com/car/application) 中获取,格式为 app-xxx | | ClientSession | string | 是 | 客户端会话描述 | | RequestId | string | 否 | 请求 ID,业务自定义生成,可用于业务区分不同请求 | | Sign | string | 开启校验则必要 | 请求校验参数
计算方式:SHA256(字段名排序后取字段值,并拼接成字符串,最后再拼接上签名混淆密钥 SALT) | @@ -194,12 +195,13 @@ curl -X POST --data "ClientSession=xxx&RequestId=req123&UserId=userid123&Project - 请求 -| 字段 | 类型 | 必要 | 描述 | -| --------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------- | -| UserId | string | 是 | 用户 ID,业务自定义生成,不同用户需要生成不同 UserId 来区分 | -| ProjectId | string | 是 | 项目 ID,应用云渲染项目创建时生成,[项目管理](https://console.cloud.tencent.com/car/project) 中获取,格式为 cap-xxx | -| RequestId | string | 否 | 请求 ID,业务自定义生成,可用于业务区分不同请求 | -| Sign | string | 开启校验则必要 | 请求校验参数
计算方式:SHA256(字段名排序后取字段值,并拼接成字符串,最后再拼接上签名混淆密钥 SALT) | +| 字段 | 类型 | 必要 | 描述 | +| ------------- | ------ | -------------- | ------------------------------------------------------------------------------------------------------------------- | +| UserId | string | 是 | 用户 ID,业务自定义生成,不同用户需要生成不同 UserId 来区分 | +| ProjectId | string | 是 | 项目 ID,应用云渲染项目创建时生成,[项目管理](https://console.cloud.tencent.com/car/project) 中获取,格式为 cap-xxx | +| ApplicationId | string | 否 | 应用 ID,多应用共享项目请求时有效,应用云渲染应用创建时生成,[应用管理](https://console.cloud.tencent.com/car/application) 中获取,格式为 app-xxx | +| RequestId | string | 否 | 请求 ID,业务自定义生成,可用于业务区分不同请求 | +| Sign | string | 开启校验则必要 | 请求校验参数
计算方式:SHA256(字段名排序后取字段值,并拼接成字符串,最后再拼接上签名混淆密钥 SALT) | - 响应 diff --git a/routes/car.js b/routes/car.js index c873eb2..9c5908d 100644 --- a/routes/car.js +++ b/routes/car.js @@ -41,6 +41,7 @@ if (Config.configs[DefaultKeys.API_SIGN] == 'Y') { '/StartProject': { UserId: validSchema(validString, true), ProjectId: validSchema(validString, true), + ApplicationId: validSchema(validString, false), ClientSession: validSchema(validString, true), Sign: validSchema(validString, true), }, @@ -51,6 +52,7 @@ if (Config.configs[DefaultKeys.API_SIGN] == 'Y') { '/Enqueue': { UserId: validSchema(validString, true), ProjectId: validSchema(validString, true), + ApplicationId: validSchema(validString, false), Sign: validSchema(validString, true), }, '/Dequeue': { @@ -64,6 +66,7 @@ if (Config.configs[DefaultKeys.API_SIGN] == 'Y') { '/StartProject': { UserId: validSchema(validString, true), ProjectId: validSchema(validString, true), + ApplicationId: validSchema(validString, false), ClientSession: validSchema(validString, true), }, '/StopProject': { @@ -72,6 +75,7 @@ if (Config.configs[DefaultKeys.API_SIGN] == 'Y') { '/Enqueue': { UserId: validSchema(validString, true), ProjectId: validSchema(validString, true), + ApplicationId: validSchema(validString, false), }, '/Dequeue': { UserId: validSchema(validString, true), @@ -93,6 +97,7 @@ router.post('/StartProject', verifyReqParams, verifySign, async (req, res, next) UserId: params.UserId, UserIp: userIp, ProjectId: params.ProjectId, + ApplicationId: params.ApplicationId, }); if (ret.Code != 0) { simpleRespone(req, res, ret); @@ -143,6 +148,7 @@ const doCheckQueue = async key => { const params = { UserId: item.UserId, ProjectId: item.ProjectId, + ApplicationId: item.ApplicationId, UserIp: item.UserIp }; waitQueue[key].State = QueueState.Locking; @@ -167,6 +173,7 @@ router.post('/Enqueue', verifyReqParams, verifySign, async (req, res, next) => { const Params = req.body; const UserId = Params.UserId; const ProjectId = Params.ProjectId; + const ApplicationId = Params.ApplicationId; const UserIp = getClientIp(req); const response = (item, index) => { @@ -189,6 +196,7 @@ router.post('/Enqueue', verifyReqParams, verifySign, async (req, res, next) => { if (waitQueue[UserId]) { waitQueue[UserId].TimeStamp = Date.now(); waitQueue[UserId].ProjectId = ProjectId; + waitQueue[UserId].ApplicationId = ApplicationId; LOG.debug(`${UserId} update timestamp`); return response(waitQueue[UserId], await queue.indexOf(UserId)); } @@ -196,12 +204,13 @@ router.post('/Enqueue', verifyReqParams, verifySign, async (req, res, next) => { const newUser = { UserId, ProjectId, + ApplicationId, UserIp, TimeStamp: Date.now(), State: QueueState.Wait, }; try { - await applyConcurrent({ UserId: UserId, ProjectId: ProjectId, UserIp: UserIp }); + await applyConcurrent({ UserId: UserId, ProjectId: ProjectId, ApplicationId: ApplicationId, UserIp: UserIp }); newUser.State = QueueState.Done; newUser.TimeStamp = Date.now(); LOG.debug(`${UserId} ready to play`);