Skip to content

Commit

Permalink
add applicationId
Browse files Browse the repository at this point in the history
  • Loading branch information
transcai committed Apr 10, 2023
1 parent 59c4553 commit 1e1f8d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | 开启校验则必要 | 请求校验参数<br>计算方式:SHA256(字段名排序后取字段值,并拼接成字符串,最后再拼接上签名混淆密钥 SALT) |
Expand Down Expand Up @@ -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 | 开启校验则必要 | 请求校验参数<br>计算方式: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 | 开启校验则必要 | 请求校验参数<br>计算方式:SHA256(字段名排序后取字段值,并拼接成字符串,最后再拼接上签名混淆密钥 SALT) |

- 响应

Expand Down
11 changes: 10 additions & 1 deletion routes/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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': {
Expand All @@ -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': {
Expand All @@ -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),
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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) => {
Expand All @@ -189,19 +196,21 @@ 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));
}

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`);
Expand Down

0 comments on commit 1e1f8d5

Please sign in to comment.