-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic-videos-api.ts
47 lines (38 loc) · 1.36 KB
/
public-videos-api.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
import { ApiPath, ContentType } from '~/bundles/common/enums/enums.js';
import { type Http, HTTPMethod } from '~/framework/http/http.js';
import { BaseHttpApi } from '~/framework/http-api/http-api.js';
import { type Storage } from '~/framework/storage/storage.js';
import { VideosApiPath } from './enums/enums.js';
type Constructor = {
baseUrl: string;
http: Http;
storage: Storage;
};
class PublicVideosApi extends BaseHttpApi {
public constructor({ baseUrl, http, storage }: Constructor) {
super({ path: ApiPath.PUBLIC_VIDEO, baseUrl, http, storage });
}
public async getVideoUrlFromJWT(jwt: string): Promise<string> {
const headers = new Headers();
headers.append('video_token', jwt.replaceAll('~', '.'));
// eslint-disable-next-line no-console
console.log('headers', headers);
const options = {
method: HTTPMethod.GET,
contentType: ContentType.JSON,
hasAuth: true,
customHeaders: headers,
};
const response = await this.load(
this.getFullEndpoint(`${VideosApiPath.ROOT}`, {}),
options,
);
if (!response.ok) {
throw new Error(
`Failed to get video ID JWT: ${response.statusText}`,
);
}
return await response.text();
}
}
export { PublicVideosApi };