2023-04-21 07:55:10 -05:00
|
|
|
import express from 'express'
|
|
|
|
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
|
|
|
import { proxifyHLS, proxifyWebTorrentFile } from '@server/lib/object-storage'
|
|
|
|
import { VideoPathManager } from '@server/lib/video-path-manager'
|
2023-05-04 08:29:34 -05:00
|
|
|
import { getStudioTaskFilePath } from '@server/lib/video-studio'
|
2023-06-20 07:17:34 -05:00
|
|
|
import { apiRateLimiter, asyncMiddleware } from '@server/middlewares'
|
2023-04-21 07:55:10 -05:00
|
|
|
import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners'
|
2023-05-04 08:29:34 -05:00
|
|
|
import {
|
|
|
|
runnerJobGetVideoStudioTaskFileValidator,
|
|
|
|
runnerJobGetVideoTranscodingFileValidator
|
|
|
|
} from '@server/middlewares/validators/runners/job-files'
|
2023-04-21 07:55:10 -05:00
|
|
|
import { VideoStorage } from '@shared/models'
|
|
|
|
|
|
|
|
const lTags = loggerTagsFactory('api', 'runner')
|
|
|
|
|
|
|
|
const runnerJobFilesRouter = express.Router()
|
|
|
|
|
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality',
|
2023-06-20 07:17:34 -05:00
|
|
|
apiRateLimiter,
|
2023-04-21 07:55:10 -05:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidator),
|
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
asyncMiddleware(getMaxQualityVideoFile)
|
|
|
|
)
|
|
|
|
|
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality',
|
2023-06-20 07:17:34 -05:00
|
|
|
apiRateLimiter,
|
2023-04-21 07:55:10 -05:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidator),
|
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
getMaxQualityVideoPreview
|
|
|
|
)
|
|
|
|
|
2023-05-04 08:29:34 -05:00
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename',
|
2023-06-20 07:17:34 -05:00
|
|
|
apiRateLimiter,
|
2023-05-04 08:29:34 -05:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidator),
|
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
runnerJobGetVideoStudioTaskFileValidator,
|
2023-05-04 08:55:51 -05:00
|
|
|
getVideoStudioTaskFile
|
2023-05-04 08:29:34 -05:00
|
|
|
)
|
|
|
|
|
2023-04-21 07:55:10 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
runnerJobFilesRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function getMaxQualityVideoFile (req: express.Request, res: express.Response) {
|
|
|
|
const runnerJob = res.locals.runnerJob
|
|
|
|
const runner = runnerJob.Runner
|
|
|
|
const video = res.locals.videoAll
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
'Get max quality file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name,
|
|
|
|
lTags(runner.name, runnerJob.id, runnerJob.type)
|
|
|
|
)
|
|
|
|
|
|
|
|
const file = video.getMaxQualityFile()
|
|
|
|
|
|
|
|
if (file.storage === VideoStorage.OBJECT_STORAGE) {
|
|
|
|
if (file.isHLS()) {
|
|
|
|
return proxifyHLS({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
filename: file.filename,
|
|
|
|
playlist: video.getHLSPlaylist(),
|
|
|
|
reinjectVideoFileToken: false,
|
|
|
|
video
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Web video
|
|
|
|
return proxifyWebTorrentFile({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
filename: file.filename
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return VideoPathManager.Instance.makeAvailableVideoFile(file, videoPath => {
|
|
|
|
return res.sendFile(videoPath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMaxQualityVideoPreview (req: express.Request, res: express.Response) {
|
|
|
|
const runnerJob = res.locals.runnerJob
|
|
|
|
const runner = runnerJob.Runner
|
|
|
|
const video = res.locals.videoAll
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
'Get max quality preview file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name,
|
|
|
|
lTags(runner.name, runnerJob.id, runnerJob.type)
|
|
|
|
)
|
|
|
|
|
|
|
|
const file = video.getPreview()
|
|
|
|
|
|
|
|
return res.sendFile(file.getPath())
|
|
|
|
}
|
2023-05-04 08:29:34 -05:00
|
|
|
|
2023-05-04 08:55:51 -05:00
|
|
|
function getVideoStudioTaskFile (req: express.Request, res: express.Response) {
|
2023-05-04 08:29:34 -05:00
|
|
|
const runnerJob = res.locals.runnerJob
|
|
|
|
const runner = runnerJob.Runner
|
|
|
|
const video = res.locals.videoAll
|
|
|
|
const filename = req.params.filename
|
|
|
|
|
|
|
|
logger.info(
|
2023-05-04 08:55:51 -05:00
|
|
|
'Get video studio task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name,
|
2023-05-04 08:29:34 -05:00
|
|
|
lTags(runner.name, runnerJob.id, runnerJob.type)
|
|
|
|
)
|
|
|
|
|
|
|
|
return res.sendFile(getStudioTaskFilePath(filename))
|
|
|
|
}
|