mikmc commited on
Commit
3b51fca
·
verified ·
1 Parent(s): 8f87312

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +67 -56
index.js CHANGED
@@ -1,58 +1,69 @@
1
- 'use strict'
2
-
3
- const axios = require('axios')
4
-
5
- const builder = require('./addon')
6
- const server = require('./server')
7
- const useCases = require('./use-cases')
8
- const handlers = require('./handlers')
9
-
10
- const {
11
- queryBuilder,
12
- transformModel,
13
- validate,
14
- parseTorrent,
15
- } = require('./commons')
16
- const { env } = require('./config')
17
-
18
- const { searchCatalog, getMeta, getStreams } = handlers({
19
- env,
20
- ...transformModel({ env, ...parseTorrent() }),
21
- ...validate({ env }),
22
- ...useCases({
23
- httpClient: axios,
24
- queryBuilder,
25
- env,
26
- }),
27
- })
28
-
29
- const addon = builder({ env })
30
-
31
- // Log the initialization of handlers
32
- console.log('Initializing Stremio addon handlers')
33
-
34
- // Define handlers for catalog, meta, and streams
35
- addon.defineCatalogHandler((request) => {
36
- console.log('Search catalog handler called with request:', request) // Log the request
37
- return searchCatalog(request)
38
- })
39
-
40
- addon.defineMetaHandler((request) => {
41
- console.log('Meta handler called with request:', request) // Log the request
42
- return getMeta(request)
43
- })
44
-
45
- addon.defineStreamHandler((request) => {
46
- console.log('Stream handler called with request:', request) // Log the request
47
- return getStreams(request)
48
- })
49
-
50
- console.log('Starting the server on port:', env.port) // Log the port the server is running on
51
 
52
- // Start the server
53
- server(addon).serve({
54
- port: env.port,
55
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- // Add a log for when the server has started
58
- console.log('Server started and listening on port:', env.port)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const bodyParser = require('body-parser');
3
+ const axios = require('axios');
4
+ const handlers = require('./handlers'); // Import handlers from the 'handlers' directory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ const app = express();
7
+ const port = 3000;
8
+
9
+ // Middleware to parse JSON bodies
10
+ app.use(bodyParser.json());
11
+
12
+ // Dependencies, e.g., API clients, services, etc.
13
+ const dependencies = {
14
+ axios,
15
+ // Add more dependencies here if necessary
16
+ };
17
+
18
+ // Initialize handlers with dependencies
19
+ const { searchCatalog, getMeta, getStreams } = handlers(dependencies);
20
+
21
+ // Define routes
22
+ app.get('/manifest.json', (req, res) => {
23
+ // Return the addon manifest
24
+ res.json({
25
+ id: 'stremio-addon',
26
+ version: '1.0.0',
27
+ name: 'Stremio Archive',
28
+ description: 'An addon for searching movies on Archive.org',
29
+ // other manifest fields
30
+ });
31
+ });
32
 
33
+ app.post('/searchCatalog', async (req, res) => {
34
+ try {
35
+ const { type, id, extra } = req.body;
36
+ const response = await searchCatalog({ type, id, extra });
37
+ res.json(response);
38
+ } catch (error) {
39
+ console.error('Error in searchCatalog:', error);
40
+ res.status(500).send('Internal Server Error');
41
+ }
42
+ });
43
+
44
+ app.post('/getMeta', async (req, res) => {
45
+ try {
46
+ const { identifier } = req.body;
47
+ const meta = await getMeta({ identifier });
48
+ res.json(meta);
49
+ } catch (error) {
50
+ console.error('Error in getMeta:', error);
51
+ res.status(500).send('Internal Server Error');
52
+ }
53
+ });
54
+
55
+ app.post('/getStreams', async (req, res) => {
56
+ try {
57
+ const { identifier } = req.body;
58
+ const streams = await getStreams({ identifier });
59
+ res.json(streams);
60
+ } catch (error) {
61
+ console.error('Error in getStreams:', error);
62
+ res.status(500).send('Internal Server Error');
63
+ }
64
+ });
65
+
66
+ // Start the server
67
+ app.listen(port, () => {
68
+ console.log(`Server started on http://localhost:${port}`);
69
+ });