@@ -7,6 +7,7 @@ import { dirname, join } from 'path';
77import { fileURLToPath } from 'url' ;
88import { csfd } from './src' ;
99import { CSFDFilmTypes } from './src/dto/global' ;
10+ import { CSFDLanguage } from './src/types' ;
1011
1112const __filename = fileURLToPath ( import . meta. url ) ;
1213const __dirname = dirname ( __filename ) ;
@@ -93,13 +94,23 @@ const port = process.env.PORT || 3000;
9394// --- Config ---
9495const API_KEY_NAME = process . env . API_KEY_NAME || 'x-api-key' ;
9596const API_KEY = process . env . API_KEY ;
97+ const RAW_LANGUAGE = process . env . LANGUAGE ;
98+ const isSupportedLanguage = ( value : unknown ) : value is CSFDLanguage =>
99+ value === 'cs' || value === 'en' || value === 'sk' ;
100+
101+ const BASE_LANGUAGE = isSupportedLanguage ( RAW_LANGUAGE ) ? RAW_LANGUAGE : undefined ;
96102
97103const API_KEYS_LIST = API_KEY
98104 ? API_KEY . split ( / [ , ; \s ] + / )
99- . map ( ( k ) => k . trim ( ) )
100- . filter ( Boolean )
105+ . map ( ( k ) => k . trim ( ) )
106+ . filter ( Boolean )
101107 : [ ] ;
102108
109+ // Configure base URL if provided
110+ if ( BASE_LANGUAGE ) {
111+ csfd . setOptions ( { language : BASE_LANGUAGE } ) ;
112+ }
113+
103114// const limiterMinutes = 15;
104115
105116// const LIMITER = rateLimit({
@@ -170,10 +181,15 @@ app.get(['/movie/', '/creator/', '/search/', '/user-ratings/', '/user-reviews/']
170181} ) ;
171182
172183app . get ( Endpoint . MOVIE , async ( req , res ) => {
184+ const rawLanguage = req . query . language ;
185+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
186+
173187 try {
174- const movie = await csfd . movie ( + req . params . id ) ;
188+ const movie = await csfd . movie ( + req . params . id , {
189+ language
190+ } ) ;
175191 res . json ( movie ) ;
176- logMessage ( 'success' , { error : null , message : `${ Endpoint . MOVIE } : ${ req . params . id } ` } , req ) ;
192+ logMessage ( 'success' , { error : null , message : `${ Endpoint . MOVIE } : ${ req . params . id } ${ language ? ` [ ${ language } ]` : '' } ` } , req ) ;
177193 } catch ( error ) {
178194 const log : ErrorLog = {
179195 error : Errors . MOVIE_FETCH_FAILED ,
@@ -185,10 +201,14 @@ app.get(Endpoint.MOVIE, async (req, res) => {
185201} ) ;
186202
187203app . get ( Endpoint . CREATOR , async ( req , res ) => {
204+ const rawLanguage = req . query . language ;
205+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
188206 try {
189- const result = await csfd . creator ( + req . params . id ) ;
207+ const result = await csfd . creator ( + req . params . id , {
208+ language
209+ } ) ;
190210 res . json ( result ) ;
191- logMessage ( 'success' , { error : null , message : `${ Endpoint . CREATOR } : ${ req . params . id } ` } , req ) ;
211+ logMessage ( 'success' , { error : null , message : `${ Endpoint . CREATOR } : ${ req . params . id } ${ language ? ` [ ${ language } ]` : '' } ` } , req ) ;
192212 } catch ( error ) {
193213 const log : ErrorLog = {
194214 error : Errors . CREATOR_FETCH_FAILED ,
@@ -200,10 +220,14 @@ app.get(Endpoint.CREATOR, async (req, res) => {
200220} ) ;
201221
202222app . get ( Endpoint . SEARCH , async ( req , res ) => {
223+ const rawLanguage = req . query . language ;
224+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
203225 try {
204- const result = await csfd . search ( req . params . query ) ;
226+ const result = await csfd . search ( req . params . query , {
227+ language
228+ } ) ;
205229 res . json ( result ) ;
206- logMessage ( 'success' , { error : null , message : `${ Endpoint . SEARCH } : ${ req . params . query } ` } , req ) ;
230+ logMessage ( 'success' , { error : null , message : `${ Endpoint . SEARCH } : ${ req . params . query } ${ language ? ` [ ${ language } ]` : '' } ` } , req ) ;
207231 } catch ( error ) {
208232 const log : ErrorLog = {
209233 error : Errors . SEARCH_FETCH_FAILED ,
@@ -216,6 +240,9 @@ app.get(Endpoint.SEARCH, async (req, res) => {
216240
217241app . get ( Endpoint . USER_RATINGS , async ( req , res ) => {
218242 const { allPages, allPagesDelay, excludes, includesOnly, page } = req . query ;
243+ const rawLanguage = req . query . language ;
244+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
245+
219246 try {
220247 const result = await csfd . userRatings ( req . params . id , {
221248 allPages : allPages === 'true' ,
@@ -225,11 +252,13 @@ app.get(Endpoint.USER_RATINGS, async (req, res) => {
225252 ? ( ( includesOnly as string ) . split ( ',' ) as CSFDFilmTypes [ ] )
226253 : undefined ,
227254 page : page ? + page : undefined
255+ } , {
256+ language
228257 } ) ;
229258 res . json ( result ) ;
230259 logMessage (
231260 'success' ,
232- { error : null , message : `${ Endpoint . USER_RATINGS } : ${ req . params . id } ` } ,
261+ { error : null , message : `${ Endpoint . USER_RATINGS } : ${ req . params . id } ${ language ? ` [ ${ language } ]` : '' } ` } ,
233262 req
234263 ) ;
235264 } catch ( error ) {
@@ -244,6 +273,9 @@ app.get(Endpoint.USER_RATINGS, async (req, res) => {
244273
245274app . get ( Endpoint . USER_REVIEWS , async ( req , res ) => {
246275 const { allPages, allPagesDelay, excludes, includesOnly, page } = req . query ;
276+ const rawLanguage = req . query . language ;
277+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
278+
247279 try {
248280 const result = await csfd . userReviews ( req . params . id , {
249281 allPages : allPages === 'true' ,
@@ -253,11 +285,13 @@ app.get(Endpoint.USER_REVIEWS, async (req, res) => {
253285 ? ( ( includesOnly as string ) . split ( ',' ) as CSFDFilmTypes [ ] )
254286 : undefined ,
255287 page : page ? + page : undefined
288+ } , {
289+ language
256290 } ) ;
257291 res . json ( result ) ;
258292 logMessage (
259293 'success' ,
260- { error : null , message : `${ Endpoint . USER_REVIEWS } : ${ req . params . id } ` } ,
294+ { error : null , message : `${ Endpoint . USER_REVIEWS } : ${ req . params . id } ${ language ? ` [ ${ language } ]` : '' } ` } ,
261295 req
262296 ) ;
263297 } catch ( error ) {
@@ -271,9 +305,14 @@ app.get(Endpoint.USER_REVIEWS, async (req, res) => {
271305} ) ;
272306
273307app . get ( Endpoint . CINEMAS , async ( req , res ) => {
308+ const rawLanguage = req . query . language ;
309+ const language = isSupportedLanguage ( rawLanguage ) ? rawLanguage : undefined ;
310+
274311 try {
275- const result = await csfd . cinema ( 1 , 'today' ) ;
276- logMessage ( 'success' , { error : null , message : `${ Endpoint . CINEMAS } ` } , req ) ;
312+ const result = await csfd . cinema ( 1 , 'today' , {
313+ language
314+ } ) ;
315+ logMessage ( 'success' , { error : null , message : `${ Endpoint . CINEMAS } ${ language ? ` [${ language } ]` : '' } ` } , req ) ;
277316 res . json ( result ) ;
278317 } catch ( error ) {
279318 const log : ErrorLog = {
@@ -310,12 +349,15 @@ app.listen(port, () => {
310349 console . log ( `Docs: ${ packageJson . homepage } ` ) ;
311350 console . log ( `Endpoints: ${ Object . values ( Endpoint ) . join ( ', ' ) } \n` ) ;
312351
313- console . log ( `API is running on: http://localhost:${ port } \n` ) ;
352+ console . log ( `API is running on: http://localhost:${ port } ` ) ;
353+ if ( BASE_LANGUAGE ) {
354+ console . log ( `Base language configured: ${ BASE_LANGUAGE } \n` ) ;
355+ }
314356 if ( API_KEYS_LIST . length === 0 ) {
315357 console . log (
316358 '\x1b[31m%s\x1b[0m' ,
317359 '⚠️ Server is OPEN!\n- Your server will be open to the world and potentially everyone can use it without any restriction.\n- To enable some basic protection, set API_KEY environment variable (single value or comma-separated list) and provide the same value in request header: ' +
318- API_KEY_NAME
360+ API_KEY_NAME
319361 ) ;
320362 } else {
321363 console . log (
0 commit comments