defVideo 작업분 반영
This commit is contained in:
@@ -71,6 +71,15 @@ router.post('/:videoId/convert', async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
const outputDir = path.join(config.hlsDir, videoId.replace(/\.[^.]+$/, ''));
|
||||
|
||||
// 이미 디스크에 HLS가 생성돼 있으면 재인코딩하지 않고 즉시 완료 처리 (멱등)
|
||||
// jobs는 메모리라 서버 재시작 후 idle이 되지만, 산출물은 디스크에 남아있음
|
||||
if (fs.existsSync(path.join(outputDir, 'index.m3u8'))) {
|
||||
jobs.set(videoId, { status: 'done', percent: 100 });
|
||||
res.json({ status: 'done', message: 'Already converted (on disk)' });
|
||||
return;
|
||||
}
|
||||
|
||||
await fsp.mkdir(outputDir, { recursive: true });
|
||||
|
||||
const job: ConversionJob = { status: 'converting', percent: 0 };
|
||||
@@ -132,8 +141,18 @@ router.post('/:videoId/convert', async (req: Request, res: Response) => {
|
||||
// GET /api/hls/:videoId/status
|
||||
router.get('/:videoId/status', (req: Request, res: Response) => {
|
||||
const { videoId } = req.params;
|
||||
const job = jobs.get(videoId) || { status: 'idle' as HlsConversionStatus, percent: 0 };
|
||||
res.json(job);
|
||||
const job = jobs.get(videoId);
|
||||
if (job) {
|
||||
res.json(job);
|
||||
return;
|
||||
}
|
||||
// 메모리에 작업 기록이 없어도 디스크에 산출물이 있으면 done
|
||||
const m3u8Path = path.join(config.hlsDir, videoId.replace(/\.[^.]+$/, ''), 'index.m3u8');
|
||||
if (fs.existsSync(m3u8Path)) {
|
||||
res.json({ status: 'done' as HlsConversionStatus, percent: 100 });
|
||||
return;
|
||||
}
|
||||
res.json({ status: 'idle' as HlsConversionStatus, percent: 0 });
|
||||
});
|
||||
|
||||
// GET /api/hls/:videoId/index.m3u8
|
||||
|
||||
Reference in New Issue
Block a user