This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
103 lines (86 loc) · 3.36 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { doRequest } from '../../common/utils';
import config from '../config';
import { AnnotationParams, CommentParams, FetchAnnotationsParams } from './types';
export default class ApiService {
static createUrl(baseUrl: string, path: string, query = {}): string {
const url = new URL(path, baseUrl);
Object.keys(query).forEach((key) => url.searchParams.append(key, query[key]));
return url.toString();
}
static validateApiKey(baseUrl: string, apiKey: string) {
const path: string = '/user/checkapikey';
const url: string = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { apiKey });
}
static fetchConfig(baseUrl: string, apiKey: string) {
const path: string = '/immersive-config';
const url: string = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { apiKey });
}
static async fetchWaterMark(baseUrl: string, apiKey: string) {
const path = '/user/watermark';
const url = this.createUrl(baseUrl, path);
const { message } = await doRequest(url, 'POST', { apiKey });
return message;
}
static async createAnnotations(baseUrl: string, apiKey: string, annotations: AnnotationParams) {
const path = '/annotations';
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { ...annotations }, { apikey: apiKey });
}
static async updateComment(baseUrl: string, apiKey: string, commentId: string, text: string) {
const path = `/comments/${commentId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(
url,
'PUT',
{
text,
},
{ apikey: apiKey },
);
}
static async createComment(baseUrl: string, apiKey: string, comment: CommentParams) {
const path = '/comments';
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { ...comment }, { apikey: apiKey });
}
static async fetchAnnotation(baseUrl: string, apiKey: string, query: FetchAnnotationsParams) {
const path = '/annotations';
const url = this.createUrl(baseUrl, path, {
roomId: query.roomId,
url: query.url,
});
return doRequest(url, 'GET', undefined, { apikey: apiKey });
}
static async resolveAnnotation(baseUrl: string, apiKey: string, annotationId: string) {
const path = `/annotations/resolve/${annotationId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', {}, { apikey: apiKey });
}
static async deleteComment(baseUrl: string, apiKey: string, commentId: string) {
const path = `/comments/${commentId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'DELETE', {}, { apikey: apiKey });
}
static async deleteAnnotation(baseUrl: string, apiKey: string, annotationId: string) {
const path = `/annotations/${annotationId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'DELETE', {}, { apikey: apiKey });
}
static async sendActivity(userId: string, groupId: string, groupName: string, product: string) {
const path = '/activity';
const baseUrl = config.get<string>('apiUrl');
const meetingId = config.get<string>('roomId');
const apikey = config.get<string>('apiKey');
const url = this.createUrl(baseUrl, path);
const body = {
groupId,
groupName,
meetingId,
product,
userId,
};
return doRequest(url, 'POST', body, { apikey });
}
}