mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
added youtube util and cors middleware
This commit is contained in:
parent
5c3d18b0e2
commit
8543647cbc
5 changed files with 17 additions and 22 deletions
25
index.js
25
index.js
|
@ -4,14 +4,10 @@ var http = require('http');
|
|||
// Create a service (the app object is just a callback).
|
||||
var app = express();
|
||||
|
||||
|
||||
let config = JSON.parse(fs.readFileSync('config.json'));
|
||||
|
||||
|
||||
// Utils
|
||||
var getHash = require('./src/utils/getHash.js');
|
||||
var getIP = require('./src/utils/getIP.js');
|
||||
var getFormattedTime = require('./src/utils/getFormattedTime.js');
|
||||
// Routes
|
||||
var corsMiddleware = require('./src/routes/corsMiddleware.js');
|
||||
|
||||
// Routes
|
||||
var getVideoSponsorTimes = require('./src/routes/getVideoSponsorTimes.js');
|
||||
|
@ -35,26 +31,11 @@ YouTubeAPI.authenticate({
|
|||
key: config.youtubeAPIKey
|
||||
});
|
||||
|
||||
var Sqlite3 = require('better-sqlite3');
|
||||
|
||||
let options = {
|
||||
readonly: config.readOnly
|
||||
};
|
||||
|
||||
//load database
|
||||
var db = new Sqlite3(config.db, options);
|
||||
//where the more sensitive data such as IP addresses are stored
|
||||
var privateDB = new Sqlite3(config.privateDB, options);
|
||||
|
||||
// Create an HTTP service.
|
||||
http.createServer(app).listen(config.port);
|
||||
|
||||
//setup CORS correctly
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
next();
|
||||
});
|
||||
app.use(corsMiddleware);
|
||||
|
||||
//add the get function
|
||||
app.get('/api/getVideoSponsorTimes', getVideoSponsorTimes);
|
||||
|
|
5
src/middleware/cors.js
Normal file
5
src/middleware/cors.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = function corsMiddleware(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
next();
|
||||
}
|
|
@ -4,6 +4,7 @@ var config = JSON.parse(fs.readFileSync('config.json'));
|
|||
var databases = require('../databases/databases.js');
|
||||
var db = databases.db;
|
||||
var privateDB = databases.privateDB;
|
||||
var YouTubeAPI = require('../utils/youtubeAPI.js');
|
||||
|
||||
var getHash = require('../utils/getHash.js');
|
||||
var getIP = require('../utils/getIP.js');
|
||||
|
|
|
@ -7,6 +7,7 @@ var getIP = require('../utils/getIP.js');
|
|||
var databases = require('../databases/databases.js');
|
||||
var db = databases.db;
|
||||
var privateDB = databases.privateDB;
|
||||
var YouTubeAPI = require('../utils/youtubeAPI.js');
|
||||
|
||||
module.exports = async function voteOnSponsorTime(req, res) {
|
||||
let UUID = req.query.UUID;
|
||||
|
|
7
src/utils/youtubeAPI.js
Normal file
7
src/utils/youtubeAPI.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
// YouTube API
|
||||
const YouTubeAPI = require("youtube-api");
|
||||
YouTubeAPI.authenticate({
|
||||
type: "key",
|
||||
key: config.youtubeAPIKey
|
||||
});
|
||||
module.exports = YouTubeAPI;
|
Loading…
Reference in a new issue