2022-10-12 16:09:02 +02:00
|
|
|
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
|
|
|
|
|
2022-12-20 09:15:49 +01:00
|
|
|
const { token, expires } = VideoTokensManager.Instance.create({ videoUUID: video.uuid, user: res.locals.oauth.token.User })
|
2022-10-12 16:09:02 +02:00
|
|
|
|
|
|
|
return res.json({
|
|
|
|
files: {
|
|
|
|
token,
|
|
|
|
expires
|
|
|
|
}
|
|
|
|
} as VideoToken)
|
|
|
|
}
|