Fix subtitle streamIndex zero parsing
@@ -10,6 +10,7 @@
10
10
- logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
11
11
12
12
## server/image-subtitles.js
13
- parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing.
13
14
- renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
14
15
15
16
## server/thumbnail-cache.js
@@ -10,6 +10,7 @@10
- logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
10
- logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
11
11
12
## server/image-subtitles.js
12
## server/image-subtitles.js
13
- parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing.
13
- renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
14
- renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
14
15
15
## server/thumbnail-cache.js
16
## server/thumbnail-cache.js
@@ -50,6 +50,11 @@
50
50
51
51
---
52
52
53
## `test/image-subtitles.test.js`
54
- `image subtitle option parsing`
55
56
---
57
53
58
## `test/page.load.test.js`
54
59
- `page load smoke test`
55
60
@@ -50,6 +50,11 @@50
50
51
---51
---52
52
53
## `test/image-subtitles.test.js`54
- `image subtitle option parsing`55
56
---57
53
## `test/page.load.test.js`58
## `test/page.load.test.js`54
- `page load smoke test`59
- `page load smoke test`55
60
@@ -373,15 +373,31 @@ async function renderEventFrame (event, canvasWidth, canvasHeight)
373
373
]).png().toBuffer();
374
374
}
375
375
376
function parseRenderOptions (options)
377
{
378
const input = options || {};
379
const filePath = String(input.filePath ?? '').trim();
380
const streamIndex = Number.parseInt(String(input.streamIndex ?? ''), 10);
381
const timeSeconds = Number.parseFloat(String(input.timeSeconds ?? ''), 10);
382
const canvasWidth = Math.max(1, Math.min(8192, toPositiveInt(input.canvasWidth ?? '', 1280)));
383
const canvasHeight = Math.max(1, Math.min(8192, toPositiveInt(input.canvasHeight ?? '', 720)));
384
385
return {
386
filePath,
387
streamIndex,
388
timeSeconds,
389
canvasWidth,
390
canvasHeight,
391
isValid: !!(filePath && Number.isInteger(streamIndex) && streamIndex >= 0 && Number.isFinite(timeSeconds) && timeSeconds >= 0),
392
};
393
}
394
376
395
async function renderImageSubtitleFrame (options)
377
396
{
378
const filePath = String(options.filePath || '').trim();
379
const streamIndex = Number.parseInt(String(options.streamIndex || ''), 10);
380
const timeSeconds = Number.parseFloat(String(options.timeSeconds || ''), 10);
381
const canvasWidth = Math.max(1, Math.min(8192, toPositiveInt(options.canvasWidth, 1280)));
382
const canvasHeight = Math.max(1, Math.min(8192, toPositiveInt(options.canvasHeight, 720)));
397
const parsed = parseRenderOptions(options);
398
const { filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight } = parsed;
383
399
384
if (!filePath || !Number.isInteger(streamIndex) || streamIndex < 0 || !Number.isFinite(timeSeconds) || timeSeconds < 0)
400
if (!parsed.isValid)
385
401
{
386
402
return null;
387
403
}
@@ -405,5 +421,6 @@ async function renderImageSubtitleFrame (options)
405
421
}
406
422
407
423
module.exports = {
424
parseRenderOptions,
408
425
renderImageSubtitleFrame,
409
426
};
@@ -373,15 +373,31 @@ async function renderEventFrame (event, canvasWidth, canvasHeight)373
]).png().toBuffer();373
]).png().toBuffer();374
}374
}375
375
376
function parseRenderOptions (options)377
{378
const input = options || {};379
const filePath = String(input.filePath ?? '').trim();380
const streamIndex = Number.parseInt(String(input.streamIndex ?? ''), 10);381
const timeSeconds = Number.parseFloat(String(input.timeSeconds ?? ''), 10);382
const canvasWidth = Math.max(1, Math.min(8192, toPositiveInt(input.canvasWidth ?? '', 1280)));383
const canvasHeight = Math.max(1, Math.min(8192, toPositiveInt(input.canvasHeight ?? '', 720)));384
385
return {386
filePath,387
streamIndex,388
timeSeconds,389
canvasWidth,390
canvasHeight,391
isValid: !!(filePath && Number.isInteger(streamIndex) && streamIndex >= 0 && Number.isFinite(timeSeconds) && timeSeconds >= 0),392
};393
}394
376
async function renderImageSubtitleFrame (options)395
async function renderImageSubtitleFrame (options)377
{396
{378
const filePath = String(options.filePath || '').trim();397
const parsed = parseRenderOptions(options);379
const streamIndex = Number.parseInt(String(options.streamIndex || ''), 10);398
const { filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight } = parsed;380
const timeSeconds = Number.parseFloat(String(options.timeSeconds || ''), 10);381
const canvasWidth = Math.max(1, Math.min(8192, toPositiveInt(options.canvasWidth, 1280)));382
const canvasHeight = Math.max(1, Math.min(8192, toPositiveInt(options.canvasHeight, 720)));383
399
384
if (!filePath || !Number.isInteger(streamIndex) || streamIndex < 0 || !Number.isFinite(timeSeconds) || timeSeconds < 0)400
if (!parsed.isValid)385
{401
{386
return null;402
return null;387
}403
}@@ -405,5 +421,6 @@ async function renderImageSubtitleFrame (options)405
}421
}406
422
407
module.exports = {423
module.exports = {424
parseRenderOptions,408
renderImageSubtitleFrame,425
renderImageSubtitleFrame,409
};426
};@@ -0,0 +1,32 @@
1
'use strict';
2
3
const { parseRenderOptions } = require('../server/image-subtitles');
4
5
describe('image subtitle option parsing', () =>
6
{
7
test('accepts streamIndex 0 as a valid value', () =>
8
{
9
const parsed = parseRenderOptions({
10
filePath: '/tmp/example.mkv',
11
streamIndex: 0,
12
timeSeconds: 24.5,
13
canvasWidth: 1920,
14
canvasHeight: 1080,
15
});
16
17
expect(parsed.streamIndex).toBe(0);
18
expect(parsed.timeSeconds).toBeCloseTo(24.5, 3);
19
expect(parsed.isValid).toBe(true);
20
});
21
22
test('rejects non-numeric streamIndex values', () =>
23
{
24
const parsed = parseRenderOptions({
25
filePath: '/tmp/example.mkv',
26
streamIndex: '',
27
timeSeconds: 24.5,
28
});
29
30
expect(parsed.isValid).toBe(false);
31
});
32
});
@@ -0,0 +1,32 @@1
'use strict';2
3
const { parseRenderOptions } = require('../server/image-subtitles');4
5
describe('image subtitle option parsing', () =>6
{7
test('accepts streamIndex 0 as a valid value', () =>8
{9
const parsed = parseRenderOptions({10
filePath: '/tmp/example.mkv',11
streamIndex: 0,12
timeSeconds: 24.5,13
canvasWidth: 1920,14
canvasHeight: 1080,15
});16
17
expect(parsed.streamIndex).toBe(0);18
expect(parsed.timeSeconds).toBeCloseTo(24.5, 3);19
expect(parsed.isValid).toBe(true);20
});21
22
test('rejects non-numeric streamIndex values', () =>23
{24
const parsed = parseRenderOptions({25
filePath: '/tmp/example.mkv',26
streamIndex: '',27
timeSeconds: 24.5,28
});29
30
expect(parsed.isValid).toBe(false);31
});32
});