2024-07-23 16:38:51 +02:00
|
|
|
import { FileStorage, RunnerJobState, VideoFileStream } from '@peertube/peertube-models'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
|
|
|
import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage/index.js'
|
|
|
|
import { VideoPathManager } from '@server/lib/video-path-manager.js'
|
|
|
|
import { getStudioTaskFilePath } from '@server/lib/video-studio.js'
|
|
|
|
import { apiRateLimiter, asyncMiddleware } from '@server/middlewares/index.js'
|
|
|
|
import { jobOfRunnerGetValidatorFactory } from '@server/middlewares/validators/runners/index.js'
|
2023-05-04 15:29:34 +02:00
|
|
|
import {
|
|
|
|
runnerJobGetVideoStudioTaskFileValidator,
|
|
|
|
runnerJobGetVideoTranscodingFileValidator
|
2023-07-31 14:34:36 +02:00
|
|
|
} from '@server/middlewares/validators/runners/job-files.js'
|
2024-07-23 16:38:51 +02:00
|
|
|
import { MVideoFileStreamingPlaylistVideo, MVideoFileVideo, MVideoFullLight } from '@server/types/models/index.js'
|
|
|
|
import express from 'express'
|
2023-04-21 14:55:10 +02:00
|
|
|
|
|
|
|
const lTags = loggerTagsFactory('api', 'runner')
|
|
|
|
|
|
|
|
const runnerJobFilesRouter = express.Router()
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality/audio',
|
|
|
|
apiRateLimiter,
|
|
|
|
asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
|
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
asyncMiddleware(getMaxQualitySeparatedAudioFile)
|
|
|
|
)
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality',
|
2023-06-20 14:17:34 +02:00
|
|
|
apiRateLimiter,
|
2023-07-12 11:09:29 +02:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
|
2023-04-21 14:55:10 +02:00
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
asyncMiddleware(getMaxQualityVideoFile)
|
|
|
|
)
|
|
|
|
|
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality',
|
2023-06-20 14:17:34 +02:00
|
|
|
apiRateLimiter,
|
2023-07-12 11:09:29 +02:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
|
2023-04-21 14:55:10 +02:00
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
getMaxQualityVideoPreview
|
|
|
|
)
|
|
|
|
|
2023-05-04 15:29:34 +02:00
|
|
|
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename',
|
2023-06-20 14:17:34 +02:00
|
|
|
apiRateLimiter,
|
2023-07-12 11:09:29 +02:00
|
|
|
asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
|
2023-05-04 15:29:34 +02:00
|
|
|
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
|
|
|
|
runnerJobGetVideoStudioTaskFileValidator,
|
2023-05-04 15:55:51 +02:00
|
|
|
getVideoStudioTaskFile
|
2023-05-04 15:29:34 +02:00
|
|
|
)
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
runnerJobFilesRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
async function getMaxQualitySeparatedAudioFile (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 separated audio 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(VideoFileStream.AUDIO) || video.getMaxQualityFile(VideoFileStream.VIDEO)
|
|
|
|
|
|
|
|
return serveVideoFile({ video, file, req, res })
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
const file = video.getMaxQualityFile(VideoFileStream.VIDEO) || video.getMaxQualityFile(VideoFileStream.AUDIO)
|
|
|
|
|
|
|
|
return serveVideoFile({ video, file, req, res })
|
|
|
|
}
|
|
|
|
|
|
|
|
async function serveVideoFile (options: {
|
|
|
|
video: MVideoFullLight
|
|
|
|
file: MVideoFileVideo | MVideoFileStreamingPlaylistVideo
|
|
|
|
req: express.Request
|
|
|
|
res: express.Response
|
|
|
|
}) {
|
|
|
|
const { video, file, req, res } = options
|
2023-04-21 14:55:10 +02:00
|
|
|
|
2024-02-12 10:47:52 +01:00
|
|
|
if (file.storage === FileStorage.OBJECT_STORAGE) {
|
2023-04-21 14:55:10 +02:00
|
|
|
if (file.isHLS()) {
|
|
|
|
return proxifyHLS({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
filename: file.filename,
|
|
|
|
playlist: video.getHLSPlaylist(),
|
|
|
|
reinjectVideoFileToken: false,
|
|
|
|
video
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Web video
|
2023-07-11 09:21:13 +02:00
|
|
|
return proxifyWebVideoFile({
|
2023-04-21 14:55:10 +02:00
|
|
|
req,
|
|
|
|
res,
|
|
|
|
filename: file.filename
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return VideoPathManager.Instance.makeAvailableVideoFile(file, videoPath => {
|
|
|
|
return res.sendFile(videoPath)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
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 15:29:34 +02:00
|
|
|
|
2023-05-04 15:55:51 +02:00
|
|
|
function getVideoStudioTaskFile (req: express.Request, res: express.Response) {
|
2023-05-04 15:29:34 +02: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 15:55:51 +02: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 15:29:34 +02:00
|
|
|
lTags(runner.name, runnerJob.id, runnerJob.type)
|
|
|
|
)
|
|
|
|
|
|
|
|
return res.sendFile(getStudioTaskFilePath(filename))
|
|
|
|
}
|