File size: 1,210 Bytes
6379e9f
 
 
 
c49e0fd
6379e9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}`);
});