Skip to content

Commit 451fea5

Browse files
author
Nir Maoz
authored
Feat/legacy url so eo params (#532)
1 parent 81229ac commit 451fea5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

__TESTS__/backwardsComaptibility/generateTransformationString.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,42 @@ describe('it works?', () => {
180180
const t = generateTransformationString(options);
181181
expect(t).toEqual("r_max");
182182
});
183+
it("should support start_offset", function () {
184+
const t = generateTransformationString({
185+
start_offset: "1"
186+
});
187+
188+
expect(t).toBe('so_1');
189+
});
190+
it("should support end_offset", function () {
191+
const t = generateTransformationString({
192+
end_offset: "0"
193+
});
194+
195+
expect(t).toBe('eo_0');
196+
});
197+
it("should support start_offset & end_offset", function () {
198+
const t = generateTransformationString({
199+
start_offset: "0",
200+
end_offset: 1
201+
});
183202

203+
expect(t).toBe('eo_1,so_0');
204+
});
205+
it("should support offset", function () {
206+
const t = generateTransformationString({
207+
offset: '0..1'
208+
});
209+
210+
expect(t).toBe('eo_1,so_0');
211+
});
212+
it("should prefer start_offset & end_offset over offset", function () {
213+
const t = generateTransformationString({
214+
offset: '0..1',
215+
start_offset: 2,
216+
end_offset: 3
217+
});
218+
219+
expect(t).toBe('eo_3,so_2');
220+
});
184221
});

src/backwards/generateTransformationString.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {normRangeValues} from "./utils/norm_range_values.js";
1313
import {processVideoParams} from "./transformationProcessing/processVideoParams.js";
1414
import Transformation from "./transformation.js";
1515
import {processDpr} from "./transformationProcessing/processDpr.js";
16+
import {isNumberLike} from "./utils/isNumberLike";
1617

1718

1819

@@ -171,12 +172,12 @@ export function generateTransformationString(transformationOptions: LegacyITrans
171172
dl: transformationOptions.delay,
172173
dn: transformationOptions.density,
173174
du: normRangeValues(transformationOptions.duration),
174-
eo: normRangeValues(splitRange(transformationOptions.offset)[1]),
175+
eo: normRangeValues(transformationOptions.end_offset || isNumberLike(transformationOptions.end_offset) ? transformationOptions.end_offset : splitRange(transformationOptions.offset)[1]),
175176
f: transformationOptions.fetch_format,
176177
g: transformationOptions.gravity,
177178
pg: transformationOptions.page,
178179
p: transformationOptions.prefix,
179-
so: normRangeValues(splitRange(transformationOptions.offset)[0]),
180+
so: normRangeValues(transformationOptions.start_offset || isNumberLike(transformationOptions.start_offset) ? transformationOptions.start_offset : splitRange(transformationOptions.offset)[0]),
180181
sp: transformationOptions.streaming_profile,
181182
vc: processVideoParams(transformationOptions.video_codec),
182183
vs: transformationOptions.video_sampling

0 commit comments

Comments
 (0)