Skip to content

Commit 993815f

Browse files
committed
feat: add grade from Use ratings for flat AI room
1 parent 76b5e40 commit 993815f

File tree

12 files changed

+560
-3
lines changed

12 files changed

+560
-3
lines changed

src/model/room/RoomUser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export class RoomUserModel extends Content {
2929
})
3030
rtc_uid: string;
3131

32+
@Column({
33+
default: -1,
34+
type: "int",
35+
})
36+
grade: number;
37+
3238
@Index("room_users_is_delete_index")
3339
@Column({
3440
default: false,

src/v1/controller/agora/Router.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import { GenerateRTM } from "./token/RTM";
33
import { ControllerClass } from "../../../abstract/controller";
44
import { MessageCallback } from "./message/Callback";
55
import { RTMCensor } from "./rtm/censor";
6+
import { AgoraAIPing } from "./ai/ping";
7+
import { AgoraAIStart } from "./ai/start";
8+
import { AgoraAIStop } from "./ai/stop";
69

710
export const agoraRouters: Readonly<Array<ControllerClass<any, any>>> = Object.freeze([
811
GenerateRTC,
912
GenerateRTM,
1013
MessageCallback,
1114
RTMCensor,
15+
AgoraAIPing,
16+
AgoraAIStart,
17+
AgoraAIStop
1218
]);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const AI_SERVER_URL = "http://106.13.114.185:8081";

src/v1/controller/agora/ai/ping.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/ping",
10+
auth: true,
11+
})
12+
export class AgoraAIPing extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
},
25+
},
26+
};
27+
28+
public async execute(): Promise<Response<any>> {
29+
const { request_id, channel_name } = this.body;
30+
31+
const res = await ax.post<any>(`${AI_SERVER_URL}/ping`, {
32+
request_id,
33+
channel_name
34+
},
35+
{
36+
headers: {
37+
"Content-Type": "application/json"
38+
}
39+
}
40+
)
41+
return res;
42+
43+
}
44+
45+
public errorHandler(error: Error): ResponseError {
46+
return this.autoHandlerError(error);
47+
}
48+
}
49+
50+
interface RequestType {
51+
body: {
52+
request_id: string;
53+
channel_name: string;
54+
};
55+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/start",
10+
auth: true,
11+
})
12+
export class AgoraAIStart extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name", "user_uid", "language", "scene", "role"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
user_uid: {
25+
type: "string",
26+
},
27+
language: {
28+
type: "string",
29+
},
30+
scene: {
31+
type: "string",
32+
},
33+
role: {
34+
type: "string",
35+
},
36+
},
37+
},
38+
};
39+
40+
public async execute(): Promise<Response<any>> {
41+
const { request_id, channel_name, user_uid } = this.body;
42+
43+
const res = await ax.post<any>(`${AI_SERVER_URL}/start`, {
44+
request_id,
45+
channel_name,
46+
user_uid,
47+
},
48+
{
49+
headers: {
50+
"Content-Type": "application/json"
51+
}
52+
}
53+
)
54+
return res;
55+
}
56+
57+
public errorHandler(error: Error): ResponseError {
58+
return this.autoHandlerError(error);
59+
}
60+
}
61+
62+
interface RequestType {
63+
body: {
64+
request_id: string;
65+
channel_name: string;
66+
user_uid: string;
67+
language: string;
68+
scene: string;
69+
role: string;
70+
};
71+
}

src/v1/controller/agora/ai/stop.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/stop",
10+
auth: true,
11+
})
12+
export class AgoraAIStop extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
},
25+
},
26+
};
27+
28+
public async execute(): Promise<Response<any>> {
29+
const { request_id, channel_name } = this.body;
30+
31+
const res = await ax.post<any>(`${AI_SERVER_URL}/start`, {
32+
request_id,
33+
channel_name,
34+
},
35+
{
36+
headers: {
37+
"Content-Type": "application/json"
38+
}
39+
}
40+
)
41+
return res;
42+
}
43+
44+
public errorHandler(error: Error): ResponseError {
45+
return this.autoHandlerError(error);
46+
}
47+
}
48+
49+
interface RequestType {
50+
body: {
51+
request_id: string;
52+
channel_name: string;
53+
};
54+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { Status } from "../../../../constants/Project";
3+
import { ErrorCode } from "../../../../ErrorCode";
4+
import { RoomUserDAO } from "../../../../dao";
5+
import { Controller } from "../../../../decorator/Controller";
6+
import { AbstractController } from "../../../../abstract/controller";
7+
8+
@Controller<RequestType, ResponseType>({
9+
method: "post",
10+
path: "user/grade/get",
11+
auth: true,
12+
})
13+
export class GetGrade extends AbstractController<RequestType, ResponseType> {
14+
public static readonly schema: FastifySchema<RequestType> = {
15+
body: {
16+
type: "object",
17+
required: ["roomUUID", "userUUID"],
18+
properties: {
19+
roomUUID: {
20+
type: "string",
21+
},
22+
userUUID: {
23+
type: "string",
24+
}
25+
},
26+
},
27+
};
28+
29+
public async execute(): Promise<Response<any>> {
30+
const { roomUUID, userUUID } = this.body;
31+
32+
const roomUserInfo = await RoomUserDAO().findOne(["grade"], {
33+
user_uuid: userUUID,
34+
room_uuid: roomUUID,
35+
});
36+
37+
if (roomUserInfo === undefined) {
38+
return {
39+
status: Status.Failed,
40+
code: ErrorCode.UserNotFound,
41+
};
42+
}
43+
44+
return {
45+
status: Status.Success,
46+
data: {
47+
grade: roomUserInfo.grade === -1 ? undefined : roomUserInfo.grade,
48+
},
49+
};
50+
51+
}
52+
53+
public errorHandler(error: Error): ResponseError {
54+
return this.autoHandlerError(error);
55+
}
56+
}
57+
type ResponseType = {
58+
grade?: number;
59+
};
60+
61+
interface RequestType {
62+
body: {
63+
roomUUID: string;
64+
userUUID: string;
65+
};
66+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { Status } from "../../../../constants/Project";
3+
import { ErrorCode } from "../../../../ErrorCode";
4+
import { RoomUserDAO } from "../../../../dao";
5+
import { Controller } from "../../../../decorator/Controller";
6+
import { AbstractController } from "../../../../abstract/controller";
7+
8+
@Controller<RequestType, any>({
9+
method: "post",
10+
path: "user/grade/set",
11+
auth: true,
12+
})
13+
export class SetGrade extends AbstractController<RequestType, any> {
14+
public static readonly schema: FastifySchema<RequestType> = {
15+
body: {
16+
type: "object",
17+
required: ["roomUUID", "userUUID", "grade"],
18+
properties: {
19+
roomUUID: {
20+
type: "string",
21+
},
22+
userUUID: {
23+
type: "string",
24+
},
25+
grade: {
26+
type: "integer",
27+
minimum: 0,
28+
maximum: 5,
29+
}
30+
},
31+
},
32+
};
33+
34+
public async execute(): Promise<Response<any>> {
35+
const { roomUUID, userUUID, grade } = this.body;
36+
37+
const roomUserInfo = await RoomUserDAO().findOne(["id"], {
38+
user_uuid: userUUID,
39+
room_uuid: roomUUID,
40+
});
41+
42+
if (roomUserInfo === undefined) {
43+
return {
44+
status: Status.Failed,
45+
code: ErrorCode.UserNotFound,
46+
};
47+
}
48+
49+
await RoomUserDAO().update({
50+
grade,
51+
},{
52+
room_uuid: roomUUID,
53+
user_uuid: userUUID,
54+
});
55+
56+
return {
57+
status: Status.Success,
58+
data: null,
59+
};
60+
61+
}
62+
63+
public errorHandler(error: Error): ResponseError {
64+
return this.autoHandlerError(error);
65+
}
66+
}
67+
68+
interface RequestType {
69+
body: {
70+
roomUUID: string;
71+
userUUID: string;
72+
grade: number;
73+
};
74+
}

0 commit comments

Comments
 (0)