1
0
Fork 0
peertube/server/controllers/api/videos/token.ts
2022-12-20 09:15:49 +01:00

33 lines
912 B
TypeScript

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({ videoUUID: video.uuid, user: res.locals.oauth.token.User })
return res.json({
files: {
token,
expires
}
} as VideoToken)
}