diff options
Diffstat (limited to 'server/controllers/api/videos/token.ts')
-rw-r--r-- | server/controllers/api/videos/token.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/controllers/api/videos/token.ts b/server/controllers/api/videos/token.ts new file mode 100644 index 000000000..009b6dfb6 --- /dev/null +++ b/server/controllers/api/videos/token.ts | |||
@@ -0,0 +1,33 @@ | |||
1 | import express from 'express' | ||
2 | import { VideoTokensManager } from '@server/lib/video-tokens-manager' | ||
3 | import { VideoToken } from '@shared/models' | ||
4 | import { asyncMiddleware, authenticate, videosCustomGetValidator } from '../../../middlewares' | ||
5 | |||
6 | const tokenRouter = express.Router() | ||
7 | |||
8 | tokenRouter.post('/:id/token', | ||
9 | authenticate, | ||
10 | asyncMiddleware(videosCustomGetValidator('only-video')), | ||
11 | generateToken | ||
12 | ) | ||
13 | |||
14 | // --------------------------------------------------------------------------- | ||
15 | |||
16 | export { | ||
17 | tokenRouter | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | function generateToken (req: express.Request, res: express.Response) { | ||
23 | const video = res.locals.onlyVideo | ||
24 | |||
25 | const { token, expires } = VideoTokensManager.Instance.create(video.uuid) | ||
26 | |||
27 | return res.json({ | ||
28 | files: { | ||
29 | token, | ||
30 | expires | ||
31 | } | ||
32 | } as VideoToken) | ||
33 | } | ||