Spaces:
Paused
Paused
Download index.js from mikmc/Internet_Archive: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/mikmc/Internet_Archive/resolve/main/index.js
- Command line
-
hf download hf://spaces/mikmc/Internet_Archive/index.js
-
curl -L -o index.js https://huggingface.co/spaces/mikmc/Internet_Archive/resolve/main/index.js
1.6 kB
| const express = require('express'); | |
| const bodyParser = require('body-parser'); | |
| const { searchCatalog, getMeta, getStreams } = require('./handlers'); // Import the handlers | |
| const addonManifest = require('./addon'); // Import the manifest | |
| const app = express(); | |
| const port = 3000; | |
| // Middleware to parse JSON bodies | |
| app.use(bodyParser.json()); | |
| // Initialize the addon manifest | |
| const manifest = addonManifest({ | |
| env: { | |
| addonContentIdPrefix: 'archive-org', | |
| }, | |
| }); | |
| // Define routes | |
| app.get('/manifest.json', (req, res) => { | |
| // Return the addon manifest | |
| res.json(manifest); | |
| }); | |
| app.post('/searchCatalog', async (req, res) => { | |
| try { | |
| const { type, id, extra } = req.body; | |
| const response = await searchCatalog({ type, id, extra }); | |
| res.json(response); | |
| } catch (error) { | |
| console.error('Error in searchCatalog:', error); | |
| res.status(500).send('Internal Server Error'); | |
| } | |
| }); | |
| app.post('/getMeta', async (req, res) => { | |
| try { | |
| const { identifier } = req.body; | |
| const meta = await getMeta({ identifier }); | |
| res.json(meta); | |
| } catch (error) { | |
| console.error('Error in getMeta:', error); | |
| res.status(500).send('Internal Server Error'); | |
| } | |
| }); | |
| app.post('/getStreams', async (req, res) => { | |
| try { | |
| const { identifier } = req.body; | |
| const streams = await getStreams({ identifier }); | |
| res.json(streams); | |
| } catch (error) { | |
| console.error('Error in getStreams:', error); | |
| res.status(500).send('Internal Server Error'); | |
| } | |
| }); | |
| // Start the server | |
| app.listen(port, () => { | |
| console.log(`Server started on http://localhost:${port}`); | |
| }); | |