]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server.ts
Handle subtitles in player
[github/Chocobozzz/PeerTube.git] / server.ts
index ef89ff5f653dad11ef915af1dc13efc3c0e4032c..a7fea34da83d07599131f7f3d18968ef87a6db6a 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -1,5 +1,5 @@
 // FIXME: https://github.com/nodejs/node/pull/16853
-import { ScheduleVideoUpdateModel } from './server/models/video/schedule-video-update'
+import { VideosCaptionCache } from './server/lib/cache/videos-caption-cache'
 
 require('tls').DEFAULT_ECDH_CURVE = 'auto'
 
@@ -12,13 +12,9 @@ if (isTestInstance()) {
 // ----------- Node modules -----------
 import * as bodyParser from 'body-parser'
 import * as express from 'express'
-import * as http from 'http'
 import * as morgan from 'morgan'
-import * as bitTorrentTracker from 'bittorrent-tracker'
 import * as cors from 'cors'
-import { Server as WebSocketServer } from 'ws'
-
-const TrackerServer = bitTorrentTracker.Server
+import * as cookieParser from 'cookie-parser'
 
 process.title = 'peertube'
 
@@ -26,7 +22,7 @@ process.title = 'peertube'
 const app = express()
 
 // ----------- Core checker -----------
-import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker'
+import { checkMissedConfig, checkFFmpeg, checkConfig, checkActivityPubUrls } from './server/initializers/checker'
 
 // Do not use barrels because we don't want to load all modules here (we need to initialize database first)
 import { logger } from './server/helpers/logger'
@@ -77,7 +73,9 @@ import {
   feedsRouter,
   staticRouter,
   servicesRouter,
-  webfingerRouter
+  webfingerRouter,
+  trackerRouter,
+  createWebsocketServer
 } from './server/controllers'
 import { Redis } from './server/lib/redis'
 import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler'
@@ -94,7 +92,8 @@ if (isTestInstance()) {
     // These routes have already cors
     if (
       req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 &&
-      req.path.indexOf(STATIC_PATHS.WEBSEED) === -1
+      req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 &&
+      req.path.startsWith('/api/') === false
     ) {
       return (cors({
         origin: '*',
@@ -117,33 +116,8 @@ app.use(bodyParser.json({
   type: [ 'application/json', 'application/*+json' ],
   limit: '500kb'
 }))
-
-// ----------- Tracker -----------
-
-const trackerServer = new TrackerServer({
-  http: false,
-  udp: false,
-  ws: false,
-  dht: false
-})
-
-trackerServer.on('error', function (err) {
-  logger.error('Error in websocket tracker.', err)
-})
-
-trackerServer.on('warning', function (err) {
-  logger.error('Warning in websocket tracker.', err)
-})
-
-const server = http.createServer(app)
-const wss = new WebSocketServer({ server: server, path: '/tracker/socket' })
-wss.on('connection', function (ws) {
-  trackerServer.onWebSocketConnection(ws)
-})
-
-const onHttpRequest = trackerServer.onHttpRequest.bind(trackerServer)
-app.get('/tracker/announce', (req, res) => onHttpRequest(req, res, { action: 'announce' }))
-app.get('/tracker/scrape', (req, res) => onHttpRequest(req, res, { action: 'scrape' }))
+// Cookies
+app.use(cookieParser())
 
 // ----------- Views, routes and static files -----------
 
@@ -157,6 +131,7 @@ app.use('/services', servicesRouter)
 app.use('/', activityPubRouter)
 app.use('/', feedsRouter)
 app.use('/', webfingerRouter)
+app.use('/', trackerRouter)
 
 // Static files
 app.use('/', staticRouter)
@@ -183,6 +158,8 @@ app.use(function (err, req, res, next) {
   return res.status(err.status || 500).end()
 })
 
+const server = createWebsocketServer(app)
+
 // ----------- Run -----------
 
 async function startApplication () {
@@ -191,6 +168,13 @@ async function startApplication () {
 
   await installApplication()
 
+  // Check activity pub urls are valid
+  checkActivityPubUrls()
+    .catch(err => {
+      logger.error('Error in ActivityPub URLs checker.', { err })
+      process.exit(-1)
+    })
+
   // Email initialization
   Emailer.Instance.init()
   await Emailer.Instance.checkConnectionOrDie()
@@ -199,6 +183,7 @@ async function startApplication () {
 
   // Caches initializations
   VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
+  VideosCaptionCache.Instance.init(CONFIG.CACHE.VIDEO_CAPTIONS.SIZE)
 
   // Enable Schedulers
   BadActorFollowScheduler.Instance.enable()