forked from csmit195/gptdarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (57 loc) · 2.19 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import express from 'express';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import ipRangeCheck from 'ip-range-check';
import addSeriesRouter from './routes/addSeries.js';
import addMoviesRouter from './routes/addMovies.js';
import lookupRouter from './routes/lookup.js';
// Import the Overseerr module
import Overseerr from './overseerr.js';
dotenv.config();
const app = express();
const port = 8195;
// API Key Validation Middleware
app.use((req, res, next) => {
console.log(`${req.method} ${req.path}`);
// OpenAI Only Block # https://platform.openai.com/docs/plugins/production/ip-egress-ranges
if (process.env.ONLY_ALLOW_OPENAI === 'true') {
const allowedRanges = ['23.102.140.112/28', '13.66.11.96/28'];
const ip = req.header('CF-Connecting-IP') || req.header('X-Forwarded-For') || req.ip;
if (!ipRangeCheck(ip, allowedRanges)) {
console.log(`Access denied for IP: ${ip}`);
return res.status(403).send('Access denied');
}
}
if (req.path === '/privacy-policy') {
return next();
}
const apiKey = req.header('X-Api-Key');
if (!apiKey || apiKey !== process.env.PROXY_API_KEY) {
return res.status(401).json({ message: 'Invalid or missing API key' });
}
next();
});
app.use(bodyParser.json());
// Routes
app.use('/addSeries', addSeriesRouter);
// Adjusted addMoviesRouter to handle Overseerr
app.use('/addMovies', (req, res) => {
const { service } = req.query; // Assume a query parameter to choose the service (radarr, sonarr, overseerr)
if (service === 'overseerr') {
// Call the Overseerr module for adding movies
Overseerr.add(req.body.title, req.body.year)
.then(result => res.json(result))
.catch(error => res.status(500).json({ error: error.message }));
} else {
// Fallback to the original addMoviesRouter for Radarr or Sonarr
addMoviesRouter(req, res);
}
});
// Lookup:
app.use('/BulkSearchForMovieAndSeries', lookupRouter);
app.use('/privacy-policy', (req, res) => {
res.sendFile('public/privacy-policy.html', { root: '.' });
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});