|
| 1 | +import express from 'express'; |
| 2 | +import { csfd } from './src'; |
| 3 | +import { CSFDFilmTypes } from './src/interfaces/global'; |
| 4 | + |
| 5 | +const app = express(); |
| 6 | +const port = process.env.PORT || 3000; |
| 7 | + |
| 8 | +app.get('/movie/:id', async (req, res) => { |
| 9 | + try { |
| 10 | + const movie = await csfd.movie(+req.params.id); |
| 11 | + res.json(movie); |
| 12 | + } catch (error) { |
| 13 | + res.status(500).json({ error: 'Failed to fetch movie data' }); |
| 14 | + } |
| 15 | +}); |
| 16 | + |
| 17 | +app.get('/creator/:id', async (req, res) => { |
| 18 | + try { |
| 19 | + const result = await csfd.creator(+req.params.id); |
| 20 | + res.json(result); |
| 21 | + } catch (error) { |
| 22 | + res.status(500).json({ error: 'Failed to fetch creator data: ' + error }); |
| 23 | + } |
| 24 | +}); |
| 25 | + |
| 26 | +app.get('/search/:query', async (req, res) => { |
| 27 | + try { |
| 28 | + const result = await csfd.search(req.params.query); |
| 29 | + res.json(result); |
| 30 | + } catch (error) { |
| 31 | + res.status(500).json({ error: 'Failed to fetch search data: ' + error }); |
| 32 | + } |
| 33 | +}); |
| 34 | + |
| 35 | +app.get('/user-ratings/:id', async (req, res) => { |
| 36 | + const { allPages, allPagesDelay, excludes, includesOnly } = req.query; |
| 37 | + try { |
| 38 | + const result = await csfd.userRatings(req.params.id, { |
| 39 | + allPages: allPages === 'true', |
| 40 | + allPagesDelay: allPagesDelay ? +allPagesDelay : undefined, |
| 41 | + excludes: excludes ? (excludes as string).split(',') as CSFDFilmTypes[] : undefined, |
| 42 | + includesOnly: includesOnly ? (includesOnly as string).split(',') as CSFDFilmTypes[] : undefined |
| 43 | + }); |
| 44 | + res.json(result); |
| 45 | + } catch (error) { |
| 46 | + res.status(500).json({ error: 'Failed to fetch user-ratings data: ' + error }); |
| 47 | + } |
| 48 | +}); |
| 49 | + |
| 50 | +app.listen(port, () => { |
| 51 | + console.log(`API is running on http://localhost:${port}`); |
| 52 | +}); |
0 commit comments