-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathyoutube.controller.ts
More file actions
48 lines (42 loc) · 1.57 KB
/
youtube.controller.ts
File metadata and controls
48 lines (42 loc) · 1.57 KB
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
import { Controller, Get, Post, Body, ParseBoolPipe, Query, Req, UseGuards } from '@nestjs/common';
import { SupabaseAuthGuard } from '../guards/auth.guard';
import { YoutubeService } from './youtube.service';
import type { AuthRequest } from '../common/interfaces/auth-request.interface';
import { getUserId } from '../common/get-user-id';
@Controller('youtube')
@UseGuards(SupabaseAuthGuard)
export class YoutubeController {
constructor(private readonly youtubeService: YoutubeService) { }
@Get('video-metadata')
getVideoMetadata(@Query('videoUrl') videoUrl: string) {
return this.youtubeService.getVideoMetadata(videoUrl);
}
@Get('channel-videos')
getChannelVideos(
@Req() req: AuthRequest,
@Query('pageToken') pageToken?: string,
@Query('maxResults') maxResults?: string,
) {
const userId = getUserId(req);
return this.youtubeService.getChannelVideos(
userId,
pageToken,
maxResults ? Math.min(parseInt(maxResults, 10), 24) : 6,
);
}
@Get('trained-videos')
getTrainedVideos(@Req() req: AuthRequest) {
const userId = getUserId(req);
return this.youtubeService.getTrainedVideos(userId);
}
@Post('trained-videos')
saveTrainedVideos(@Req() req: AuthRequest, @Body() data: any) {
const userId = getUserId(req);
return this.youtubeService.saveTrainedVideos(userId, data.videos);
}
@Get('channel-stats')
getChannelStats(@Req() req: AuthRequest, @Query('forceSync', ParseBoolPipe) forceSync?: boolean) {
const userId = getUserId(req);
return this.youtubeService.getChannelStats(userId, forceSync);
}
}