File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,28 @@ const routes = async (fastify: FastifyInstance, options: RegisterOptions) => {
40
40
reply . status ( 200 ) . send ( res ) ;
41
41
} ) ;
42
42
43
+ fastify . get ( '/trending' , async ( request : FastifyRequest , reply : FastifyReply ) => {
44
+ const validTimePeriods = new Set ( [ 'day' , 'week' ] as const ) ;
45
+ type validTimeType = typeof validTimePeriods extends Set < infer T > ? T : undefined
46
+
47
+ const type = ( request . query as { type ?: string } ) . type || 'all' ;
48
+ let timePeriod = ( request . query as { timePeriod ?: validTimeType } ) . timePeriod || 'day' ;
49
+
50
+ // make day as default time period
51
+ if ( ! validTimePeriods . has ( timePeriod ) ) timePeriod = 'day' ;
52
+
53
+ const page = ( request . query as { page ?: number } ) . page || 1 ;
54
+
55
+ const tmdb = new META . TMDB ( tmdbApi ) ;
56
+
57
+ try {
58
+ const res = await tmdb . fetchTrending ( type , timePeriod , page ) ;
59
+ reply . status ( 200 ) . send ( res ) ;
60
+ } catch ( err ) {
61
+ reply . status ( 500 ) . send ( { message : 'Failed to fetch trending media.' } ) ;
62
+ }
63
+ } ) ;
64
+
43
65
fastify . get (
44
66
'/watch/:episodeId' ,
45
67
async ( request : FastifyRequest , reply : FastifyReply ) => {
You can’t perform that action at this time.
0 commit comments