aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/token.ts
blob: 009b6dfb653c56c5ed9a9b93f2ee34006c2d94b1 (plain) (blame)
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
import express from 'express'
import { VideoTokensManager } from '@server/lib/video-tokens-manager'
import { VideoToken } from '@shared/models'
import { asyncMiddleware, authenticate, videosCustomGetValidator } from '../../../middlewares'

const tokenRouter = express.Router()

tokenRouter.post('/:id/token',
  authenticate,
  asyncMiddleware(videosCustomGetValidator('only-video')),
  generateToken
)

// ---------------------------------------------------------------------------

export {
  tokenRouter
}

// ---------------------------------------------------------------------------

function generateToken (req: express.Request, res: express.Response) {
  const video = res.locals.onlyVideo

  const { token, expires } = VideoTokensManager.Instance.create(video.uuid)

  return res.json({
    files: {
      token,
      expires
    }
  } as VideoToken)
}