Skip to content

Commit 4d81666

Browse files
Merge pull request #463 from BinaryStudioAcademy/task/OV-00-add-logs
OV-00: + body
2 parents 6a3e6db + 8644227 commit 4d81666

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

backend/src/bundles/public-video/public-video.controller.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,30 @@ class PublicVideoController extends BaseController {
2020

2121
this.addRoute({
2222
path: PublicVideosApiPath.ROOT,
23-
method: HTTPMethod.GET,
24-
handler: (options) => this.findUrlByToken(options),
23+
method: HTTPMethod.POST,
24+
handler: (options) => {
25+
return this.findUrlByToken(
26+
options as ApiHandlerOptions<{
27+
body: { id: string };
28+
}>,
29+
);
30+
},
2531
});
2632
}
2733

2834
private async findUrlByToken(
29-
options: ApiHandlerOptions,
35+
options: ApiHandlerOptions<{
36+
body: { id: string };
37+
}>,
3038
): Promise<ApiHandlerResponse> {
3139
// eslint-disable-next-line no-console
32-
console.log(options, 'options');
33-
const headers = options.headers as Record<string, { value: string }>;
34-
const videoTokenHeader = headers['video_token']?.toString() ?? '';
40+
console.log(options.body, 'options.body');
41+
const jwt = options.body.id;
3542
// eslint-disable-next-line no-console
36-
console.log(videoTokenHeader);
43+
console.log(jwt, 'jwt');
3744
return {
3845
status: HTTPCode.OK,
39-
payload:
40-
await this.publicVideoService.findUrlByToken(videoTokenHeader),
46+
payload: await this.publicVideoService.findUrlByToken(jwt),
4147
};
4248
}
4349
}

backend/src/bundles/public-video/public-video.service.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,8 @@ class PublicVideoService {
1111
}
1212

1313
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14-
public async findUrlByToken(token: any): Promise<string> {
15-
let id;
16-
17-
// eslint-disable-next-line no-console
18-
console.log(token, 'find url by token');
19-
if (token.id) {
20-
id = token.id;
21-
// eslint-disable-next-line no-console
22-
console.log('id from token', id);
23-
} else {
24-
id = await tokenService.getIdFromToken(token);
25-
// eslint-disable-next-line no-console
26-
console.log('id from else', id);
27-
}
14+
public async findUrlByToken(token: string): Promise<string> {
15+
const id = await tokenService.getIdFromToken(token);
2816

2917
if (!id) {
3018
this.throwVideoNotFoundError();

frontend/src/bundles/common/api/public-video-api/public-videos-api.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ class PublicVideosApi extends BaseHttpApi {
1717
}
1818

1919
public async getVideoUrlFromJWT(jwt: string): Promise<string> {
20-
const headers = new Headers();
21-
headers.append('video_token', jwt.replaceAll('~', '.'));
22-
23-
// eslint-disable-next-line no-console
24-
console.log('headers', headers.get('video_token'));
20+
const updatedJwt = jwt.replaceAll('~', '.');
2521

2622
const options = {
27-
method: HTTPMethod.GET,
23+
method: HTTPMethod.POST,
2824
contentType: ContentType.JSON,
2925
hasAuth: true,
30-
customHeaders: headers,
26+
payload: JSON.stringify({ id: updatedJwt }),
3127
};
3228

3329
const response = await this.load(

0 commit comments

Comments
 (0)