]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/client.ts
Convert scripts to typescript
[github/Chocobozzz/PeerTube.git] / server / controllers / client.ts
index ce5608c9b7145e5f78d58a82424c6f9842b13f83..503eff75013ab5c58bf80869e3b0b0c24ecde67e 100644 (file)
@@ -1,10 +1,8 @@
 import { parallel } from 'async'
-import express = require('express')
-import fs = require('fs')
+import * as express from 'express'
+import * as fs from 'fs'
 import { join } from 'path'
-import expressValidator = require('express-validator')
-// TODO: use .validator when express-validator typing will have validator field
-const validator = expressValidator['validator']
+import * as validator from 'validator'
 
 import { database as db } from '../initializers/database'
 import {
@@ -14,6 +12,7 @@ import {
   STATIC_MAX_AGE
 } from '../initializers'
 import { root } from '../helpers'
+import { VideoInstance } from '../models'
 
 const clientsRouter = express.Router()
 
@@ -27,7 +26,7 @@ const indexPath = join(distPath, 'index.html')
 // Do not use a template engine for a so little thing
 clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage)
 
-clientsRouter.use('/videos/embed', function (req, res, next) {
+clientsRouter.use('/videos/embed', function (req: express.Request, res: express.Response, next: express.NextFunction) {
   res.sendFile(embedPath)
 })
 
@@ -35,7 +34,7 @@ clientsRouter.use('/videos/embed', function (req, res, next) {
 clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
 
 // 404 for static files not found
-clientsRouter.use('/client/*', function (req, res, next) {
+clientsRouter.use('/client/*', function (req: express.Request, res: express.Response, next: express.NextFunction) {
   res.sendStatus(404)
 })
 
@@ -47,7 +46,7 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function addOpenGraphTags (htmlStringPage, video) {
+function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) {
   let basePreviewUrlHttp
 
   if (video.isOwned()) {
@@ -90,8 +89,8 @@ function addOpenGraphTags (htmlStringPage, video) {
   return htmlStringPage.replace(opengraphComment, tagsString)
 }
 
-function generateWatchHtmlPage (req, res, next) {
-  const videoId = req.params.id
+function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const videoId = '' + req.params.id
 
   // Let Angular application handle errors
   if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath)
@@ -104,7 +103,7 @@ function generateWatchHtmlPage (req, res, next) {
     video: function (callback) {
       db.Video.loadAndPopulateAuthorAndPodAndTags(videoId, callback)
     }
-  }, function (err, result: any) {
+  }, function (err: Error, result: { file: Buffer, video: VideoInstance }) {
     if (err) return next(err)
 
     const html = result.file.toString()