Skip to content

Commit

Permalink
Merge pull request #463 from BinaryStudioAcademy/task/OV-00-add-logs
Browse files Browse the repository at this point in the history
OV-00: + body
  • Loading branch information
anton-otroshchenko authored Sep 28, 2024
2 parents 6a3e6db + 8644227 commit 4d81666
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
24 changes: 15 additions & 9 deletions backend/src/bundles/public-video/public-video.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@ class PublicVideoController extends BaseController {

this.addRoute({
path: PublicVideosApiPath.ROOT,
method: HTTPMethod.GET,
handler: (options) => this.findUrlByToken(options),
method: HTTPMethod.POST,
handler: (options) => {
return this.findUrlByToken(
options as ApiHandlerOptions<{
body: { id: string };
}>,
);
},
});
}

private async findUrlByToken(
options: ApiHandlerOptions,
options: ApiHandlerOptions<{
body: { id: string };
}>,
): Promise<ApiHandlerResponse> {
// eslint-disable-next-line no-console
console.log(options, 'options');
const headers = options.headers as Record<string, { value: string }>;
const videoTokenHeader = headers['video_token']?.toString() ?? '';
console.log(options.body, 'options.body');
const jwt = options.body.id;
// eslint-disable-next-line no-console
console.log(videoTokenHeader);
console.log(jwt, 'jwt');
return {
status: HTTPCode.OK,
payload:
await this.publicVideoService.findUrlByToken(videoTokenHeader),
payload: await this.publicVideoService.findUrlByToken(jwt),
};
}
}
Expand Down
16 changes: 2 additions & 14 deletions backend/src/bundles/public-video/public-video.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ class PublicVideoService {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async findUrlByToken(token: any): Promise<string> {
let id;

// eslint-disable-next-line no-console
console.log(token, 'find url by token');
if (token.id) {
id = token.id;
// eslint-disable-next-line no-console
console.log('id from token', id);
} else {
id = await tokenService.getIdFromToken(token);
// eslint-disable-next-line no-console
console.log('id from else', id);
}
public async findUrlByToken(token: string): Promise<string> {
const id = await tokenService.getIdFromToken(token);

if (!id) {
this.throwVideoNotFoundError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ class PublicVideosApi extends BaseHttpApi {
}

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.get('video_token'));
const updatedJwt = jwt.replaceAll('~', '.');

const options = {
method: HTTPMethod.GET,
method: HTTPMethod.POST,
contentType: ContentType.JSON,
hasAuth: true,
customHeaders: headers,
payload: JSON.stringify({ id: updatedJwt }),
};

const response = await this.load(
Expand Down

0 comments on commit 4d81666

Please sign in to comment.