Spaces:
Sleeping
Sleeping
| const express = require('express'); | |
| const { getFinalDownloadLink } = require('reikeranidl'); | |
| const app = express(); | |
| const PORT = 7860; | |
| // Middleware to parse JSON request body (not required for query params) | |
| app.use(express.json()); | |
| // Endpoint to get download links by passing the download page URL as a query parameter | |
| app.get('/api/anime/download', async (req, res) => { | |
| const { url } = req.query; // Extract URL from query parameters | |
| if (!url) { | |
| return res.status(400).json({ error: 'Download URL is required' }); | |
| } | |
| try { | |
| // Get the final download links from the provided URL | |
| const downloadLinks = await getFinalDownloadLink(url); | |
| if (downloadLinks.error) { | |
| return res.status(500).json({ error: 'Failed to retrieve download links' }); | |
| } | |
| // Return the download links | |
| res.json(downloadLinks); | |
| } catch (error) { | |
| console.error("Error fetching download links:", error.message); | |
| res.status(500).json({ error: 'An error occurred while fetching the download links' }); | |
| } | |
| }); | |
| // Start the server | |
| app.listen(PORT, () => { | |
| console.log(`Server is running on http://localhost:${PORT}`); | |
| }); |