@financial-times/cp-content-pipeline-schema 3.5.1 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lib/model/Image.js +11 -32
- package/lib/model/Image.js.map +1 -1
- package/lib/model/Image.test.js +24 -54
- package/lib/model/Image.test.js.map +1 -1
- package/package.json +1 -1
- package/src/model/Image.test.ts +37 -60
- package/src/model/Image.ts +12 -36
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.5.2](https://github.com/Financial-Times/cp-content-pipeline/compare/cp-content-pipeline-schema-v3.5.1...cp-content-pipeline-schema-v3.5.2) (2024-10-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* don't call image service for any images with missing dimensions ([b3bab4b](https://github.com/Financial-Times/cp-content-pipeline/commit/b3bab4b7c30098e83bc5e1e99a953b741b3a46b6))
|
|
9
|
+
* set max image DPR to 2 when no dimensions ([d556e0b](https://github.com/Financial-Times/cp-content-pipeline/commit/d556e0bd6862c23f3279db717b2cab1617e98c0f))
|
|
10
|
+
|
|
3
11
|
## [3.5.1](https://github.com/Financial-Times/cp-content-pipeline/compare/cp-content-pipeline-schema-v3.5.0...cp-content-pipeline-schema-v3.5.1) (2024-10-29)
|
|
4
12
|
|
|
5
13
|
|
package/lib/model/Image.js
CHANGED
|
@@ -8,7 +8,6 @@ const metadata_1 = require("../helpers/metadata");
|
|
|
8
8
|
const imageService_1 = __importDefault(require("../helpers/imageService"));
|
|
9
9
|
const literal_union_1 = require("../resolvers/literal-union");
|
|
10
10
|
const scalars_1 = require("../resolvers/scalars");
|
|
11
|
-
const isError_1 = __importDefault(require("../helpers/isError"));
|
|
12
11
|
const errors_1 = require("@dotcom-reliability-kit/errors");
|
|
13
12
|
class CAPIImage {
|
|
14
13
|
capiImage;
|
|
@@ -84,7 +83,7 @@ class CAPIImage {
|
|
|
84
83
|
maxAllowedWidth = Math.min(requestedWidth, dimensions?.width || Infinity);
|
|
85
84
|
maxDpr = dimensions
|
|
86
85
|
? Math.min(args.maxDpr || Infinity, Math.floor(dimensions.width / maxAllowedWidth))
|
|
87
|
-
:
|
|
86
|
+
: 2;
|
|
88
87
|
const resolutions = [...Array(maxDpr + 1).keys()].slice(1);
|
|
89
88
|
return resolutions.map((dpr) => ({
|
|
90
89
|
url: (0, imageService_1.default)({
|
|
@@ -111,36 +110,16 @@ class CAPIImage {
|
|
|
111
110
|
height: this.capiImage.pixelHeight,
|
|
112
111
|
};
|
|
113
112
|
}
|
|
114
|
-
// HACK:KB:20241029 graphics don't
|
|
115
|
-
//
|
|
116
|
-
// performance. skip calling Image Service for
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
const imageMetadata = await this.#dataSources.origami.getImageMetadata(this.capiImage.binaryUrl);
|
|
128
|
-
return imageMetadata;
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
if ((0, isError_1.default)(error)) {
|
|
132
|
-
this.context.logger.warn({
|
|
133
|
-
event: 'RECOVERABLE_ERROR',
|
|
134
|
-
error: new errors_1.OperationalError({
|
|
135
|
-
code: 'IMAGE_DIMENSIONS_ERROR',
|
|
136
|
-
message: `Failed to get dimensions for ${this.capiImage.binaryUrl}`,
|
|
137
|
-
url: this.capiImage.binaryUrl,
|
|
138
|
-
cause: error,
|
|
139
|
-
}),
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
113
|
+
// HACK:KB:20241029 graphics and images in layouts don't have pixelWidth/
|
|
114
|
+
// pixelHeight because of reasons. we want to avoid calling Image Service
|
|
115
|
+
// to improve performance. skip calling Image Service for the time being
|
|
116
|
+
this.context.logger.warn({
|
|
117
|
+
event: 'SKIPPING_IMAGE_DIMENSIONS',
|
|
118
|
+
message: 'Not calling Image Service to get graphics dimensions',
|
|
119
|
+
url: this.capiImage.binaryUrl,
|
|
120
|
+
type: this.type(),
|
|
121
|
+
});
|
|
122
|
+
return null;
|
|
144
123
|
}
|
|
145
124
|
credit() {
|
|
146
125
|
return this.capiImage.copyright?.notice ?? null;
|
package/lib/model/Image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../src/model/Image.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AACjD,2EAAqD;AAOrD,8DAGmC;AACnC,kDAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../src/model/Image.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AACjD,2EAAqD;AAOrD,8DAGmC;AACnC,kDAA6D;AAC7D,2DAA0D;AAoB1D,MAAa,SAAS;IAKV;IACA;IACA;IANV,WAAW,CAAQ;IACnB,YAAY,CAAa;IAEzB,YACU,SAA+B,EAC/B,OAAqB,EACrB,SAAqB;QAFrB,cAAS,GAAT,SAAS,CAAsB;QAC/B,YAAO,GAAP,OAAO,CAAc;QACrB,cAAS,GAAT,SAAS,CAAY;QAE7B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,qBAAqB,CAAA;QAC9D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAA;IACzC,CAAC;IAED,IAAI;QACF,QAAQ,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YAC5B,KAAK,4CAA4C;gBAC/C,OAAO,SAAS,CAAA;YAClB,KAAK,0CAA0C;gBAC7C,OAAO,OAAO,CAAA;QAClB,CAAC;QAED,0CAA0C;QAC1C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;YAC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
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const Image_1 = require("./Image");
|
|
4
|
-
const
|
|
7
|
+
const logger_1 = __importDefault(require("@dotcom-reliability-kit/logger"));
|
|
5
8
|
const imageService_1 = require("../helpers/imageService");
|
|
6
9
|
describe('Image', () => {
|
|
7
10
|
const mockImage = {
|
|
@@ -10,40 +13,32 @@ describe('Image', () => {
|
|
|
10
13
|
title: 'title',
|
|
11
14
|
description: 'description',
|
|
12
15
|
binaryUrl: 'cloudfront.com/image',
|
|
16
|
+
pixelWidth: 5000,
|
|
17
|
+
pixelHeight: 1000,
|
|
13
18
|
};
|
|
14
19
|
const graphic = {
|
|
15
20
|
...mockImage,
|
|
16
21
|
type: 'http://www.ft.com/ontology/content/Graphic',
|
|
17
22
|
};
|
|
18
|
-
const getImageMetadata = globals_1.jest.fn();
|
|
19
23
|
const context = {
|
|
20
|
-
|
|
21
|
-
origami: {
|
|
22
|
-
getImageMetadata,
|
|
23
|
-
},
|
|
24
|
-
capi: {},
|
|
25
|
-
vanityUrls: {},
|
|
26
|
-
},
|
|
24
|
+
logger: logger_1.default,
|
|
27
25
|
systemCode: 'image-test',
|
|
28
26
|
};
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
getImageMetadata.mockReset();
|
|
31
|
-
});
|
|
32
27
|
describe('sourceSet', () => {
|
|
33
28
|
describe('An image that is provided with a high resolution', () => {
|
|
34
|
-
|
|
35
|
-
beforeAll(async () => {
|
|
36
|
-
getImageMetadata.mockResolvedValue({ width: 5000, height: 1000 });
|
|
29
|
+
it('transforms the URL to use the Origami Image Service', async () => {
|
|
37
30
|
const model = new Image_1.CAPIImage(mockImage, context);
|
|
38
|
-
sourceSet = await model.sourceSet({ width: 1000 });
|
|
39
|
-
});
|
|
40
|
-
it('transforms the URL to use the Origami Image Service', () => {
|
|
31
|
+
const sourceSet = await model.sourceSet({ width: 1000 });
|
|
41
32
|
expect(sourceSet.every((source) => source.url.startsWith('https://www.ft.com/__origami/service/image/v2'))).toBeTruthy();
|
|
42
33
|
});
|
|
43
|
-
it('resizes the image to the requested width', () => {
|
|
34
|
+
it('resizes the image to the requested width', async () => {
|
|
35
|
+
const model = new Image_1.CAPIImage(mockImage, context);
|
|
36
|
+
const sourceSet = await model.sourceSet({ width: 1000 });
|
|
44
37
|
expect(sourceSet.every((source) => source.width === 1000 && source.url.includes('width=1000'))).toBeTruthy();
|
|
45
38
|
});
|
|
46
|
-
it('includes sourceSet for all the possible resolutions we can display the image at, given the requested width and the original source width', () => {
|
|
39
|
+
it('includes sourceSet for all the possible resolutions we can display the image at, given the requested width and the original source width', async () => {
|
|
40
|
+
const model = new Image_1.CAPIImage(mockImage, context);
|
|
41
|
+
const sourceSet = await model.sourceSet({ width: 1000 });
|
|
47
42
|
expect(sourceSet.length).toEqual(5);
|
|
48
43
|
expect(sourceSet[0]?.dpr).toEqual(1);
|
|
49
44
|
expect(sourceSet[0]?.url).toMatch(/dpr=1/);
|
|
@@ -53,8 +48,7 @@ describe('Image', () => {
|
|
|
53
48
|
});
|
|
54
49
|
describe("An image that that isn't wide enough to generate high-resolution sourceSet for", () => {
|
|
55
50
|
it('returns an array with a single resolution iamge service UR', async () => {
|
|
56
|
-
|
|
57
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
51
|
+
const model = new Image_1.CAPIImage({ ...mockImage, pixelWidth: 1500, pixelHeight: 500 }, context);
|
|
58
52
|
const sourceSet = await model.sourceSet({ width: 1000 });
|
|
59
53
|
expect(sourceSet.length).toEqual(1);
|
|
60
54
|
expect(sourceSet[0]).toEqual({
|
|
@@ -66,8 +60,7 @@ describe('Image', () => {
|
|
|
66
60
|
});
|
|
67
61
|
describe('An image that that is smaller than the width that was requested', () => {
|
|
68
62
|
it('returns the image at the same width as the original', async () => {
|
|
69
|
-
|
|
70
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
63
|
+
const model = new Image_1.CAPIImage({ ...mockImage, pixelWidth: 500, pixelHeight: 500 }, context);
|
|
71
64
|
const sourceSet = await model.sourceSet({ width: 1000 });
|
|
72
65
|
expect(sourceSet.length).toEqual(1);
|
|
73
66
|
expect(sourceSet[0]).toEqual({
|
|
@@ -79,8 +72,7 @@ describe('Image', () => {
|
|
|
79
72
|
});
|
|
80
73
|
describe('An image that that is bigger than the maximum width that was requested', () => {
|
|
81
74
|
it('returns the image at the same width as the maximum width', async () => {
|
|
82
|
-
|
|
83
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
75
|
+
const model = new Image_1.CAPIImage({ ...mockImage, pixelWidth: 4000, pixelHeight: 4000 }, context);
|
|
84
76
|
const sourceSet = await model.sourceSet({ width: imageService_1.MAX_IMAGE_WIDTH });
|
|
85
77
|
expect(sourceSet.length).toEqual(1);
|
|
86
78
|
expect(sourceSet[0]?.width).toEqual(imageService_1.MAX_IMAGE_WIDTH);
|
|
@@ -88,8 +80,7 @@ describe('Image', () => {
|
|
|
88
80
|
});
|
|
89
81
|
describe('A large image with the maxDpr argumet passed', () => {
|
|
90
82
|
it('only returns sourceSet up to and including the maxDpr', async () => {
|
|
91
|
-
|
|
92
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
83
|
+
const model = new Image_1.CAPIImage({ ...mockImage, pixelWidth: 5000, pixelHeight: 500 }, context);
|
|
93
84
|
const sourceSet = await model.sourceSet({ width: 1000, maxDpr: 2 });
|
|
94
85
|
expect(sourceSet.length).toEqual(2);
|
|
95
86
|
expect(sourceSet[0]?.dpr).toEqual(1);
|
|
@@ -107,25 +98,6 @@ describe('Image', () => {
|
|
|
107
98
|
};
|
|
108
99
|
const model = new Image_1.CAPIImage(invalidImage, context);
|
|
109
100
|
await expect(model.sourceSet({ width: 1000, maxDpr: 2 })).rejects.toThrow('not-a-uuid is not a valid Content API Image ID');
|
|
110
|
-
expect(getImageMetadata).not.toHaveBeenCalled();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe('When the image service fails to return metadata', () => {
|
|
114
|
-
let sourceSet;
|
|
115
|
-
beforeEach(async () => {
|
|
116
|
-
getImageMetadata.mockRejectedValue(null);
|
|
117
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
118
|
-
sourceSet = await model.sourceSet({ width: 3000 });
|
|
119
|
-
});
|
|
120
|
-
it('passes the requested width to the image service', async () => {
|
|
121
|
-
expect(sourceSet.length).toEqual(1);
|
|
122
|
-
expect(sourceSet[0]?.width).toEqual(3000);
|
|
123
|
-
expect(sourceSet[0]?.url).toMatch(/width=3000/);
|
|
124
|
-
});
|
|
125
|
-
it('falls back to a single DPR source', async () => {
|
|
126
|
-
expect(sourceSet.length).toEqual(1);
|
|
127
|
-
expect(sourceSet[0]?.dpr).toEqual(1);
|
|
128
|
-
expect(sourceSet[0]?.url).toMatch(/dpr=1/);
|
|
129
101
|
});
|
|
130
102
|
});
|
|
131
103
|
});
|
|
@@ -173,16 +145,14 @@ describe('Image', () => {
|
|
|
173
145
|
});
|
|
174
146
|
});
|
|
175
147
|
describe('width/height', () => {
|
|
176
|
-
it('returns the original width and height from
|
|
177
|
-
getImageMetadata.mockResolvedValue({ width: 100, height: 200 });
|
|
148
|
+
it('returns the original width and height from capi data', async () => {
|
|
178
149
|
const model = new Image_1.CAPIImage(mockImage, context);
|
|
179
150
|
const { width, height } = (await model.dimensions()) || {};
|
|
180
|
-
expect(width).toEqual(
|
|
181
|
-
expect(height).toEqual(
|
|
151
|
+
expect(width).toEqual(5000);
|
|
152
|
+
expect(height).toEqual(1000);
|
|
182
153
|
});
|
|
183
|
-
it('returns null if
|
|
184
|
-
|
|
185
|
-
const model = new Image_1.CAPIImage(mockImage, context);
|
|
154
|
+
it('returns null if no width and height in capi data', async () => {
|
|
155
|
+
const model = new Image_1.CAPIImage({ ...mockImage, pixelHeight: undefined, pixelWidth: undefined }, context);
|
|
186
156
|
const dimensions = await model.dimensions();
|
|
187
157
|
expect(dimensions).toEqual(null);
|
|
188
158
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.test.js","sourceRoot":"","sources":["../../src/model/Image.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Image.test.js","sourceRoot":"","sources":["../../src/model/Image.test.ts"],"names":[],"mappings":";;;;;AAAA,mCAAmC;AACnC,4EAAmD;AAGnD,0DAAyD;AAEzD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,MAAM,SAAS,GAAG;QAChB,EAAE,EAAE,iEAAiE;QACrE,IAAI,EAAE,0CAAmD;QACzD,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,aAAa;QAC1B,SAAS,EAAE,sBAAsB;QACjC,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,IAAI;KAClB,CAAA;IAED,MAAM,OAAO,GAAG;QACd,GAAG,SAAS;QACZ,IAAI,EAAE,4CAAqD;KAC5D,CAAA;IAED,MAAM,OAAO,GAAG;QACd,MAAM,EAAN,gBAAM;QACN,UAAU,EAAE,YAAY;KACE,CAAA;IAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAChE,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;gBACnE,MAAM,KAAK,GAAG,IAAI,iBAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;gBAC/C,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;gBAExD,MAAM,CACJ,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CACzB,MAAM,CAAC,GAAG,CAAC,UAAU,CACnB,+CAA+C,CAChD,CACF,CACF,CAAC,UAAU,EAAE,CAAA;YAChB,CAAC,CAAC,CAAA;YAEF,EA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,MAAM,GAAG,GAAG,IAAI,iBAAS,CACvB;gBACE,GAAG,OAAO;gBACV,WAAW,EAAE,EAAE;aAChB,EACD,OAAO,CACR,CAAC,GAAG,EAAE,CAAA;YACP,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/model/Image.test.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { CAPIImage } from './Image'
|
|
2
|
-
import
|
|
2
|
+
import logger from '@dotcom-reliability-kit/logger'
|
|
3
3
|
import type { QueryContext } from '..'
|
|
4
4
|
import { Image } from './schemas/capi/internal-content'
|
|
5
|
-
import { OrigamiImageDataSource } from '../datasources/origami-image'
|
|
6
5
|
import { MAX_IMAGE_WIDTH } from '../helpers/imageService'
|
|
7
|
-
import type { ImageSource } from '../generated'
|
|
8
6
|
|
|
9
7
|
describe('Image', () => {
|
|
10
8
|
const mockImage = {
|
|
@@ -13,6 +11,8 @@ describe('Image', () => {
|
|
|
13
11
|
title: 'title',
|
|
14
12
|
description: 'description',
|
|
15
13
|
binaryUrl: 'cloudfront.com/image',
|
|
14
|
+
pixelWidth: 5000,
|
|
15
|
+
pixelHeight: 1000,
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const graphic = {
|
|
@@ -20,34 +20,17 @@ describe('Image', () => {
|
|
|
20
20
|
type: 'http://www.ft.com/ontology/content/Graphic' as const,
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const getImageMetadata = jest.fn<OrigamiImageDataSource['getImageMetadata']>()
|
|
24
|
-
|
|
25
23
|
const context = {
|
|
26
|
-
|
|
27
|
-
origami: {
|
|
28
|
-
getImageMetadata,
|
|
29
|
-
},
|
|
30
|
-
capi: {},
|
|
31
|
-
vanityUrls: {},
|
|
32
|
-
},
|
|
24
|
+
logger,
|
|
33
25
|
systemCode: 'image-test',
|
|
34
26
|
} as unknown as QueryContext
|
|
35
27
|
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
getImageMetadata.mockReset()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
28
|
describe('sourceSet', () => {
|
|
41
29
|
describe('An image that is provided with a high resolution', () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
beforeAll(async () => {
|
|
45
|
-
getImageMetadata.mockResolvedValue({ width: 5000, height: 1000 })
|
|
30
|
+
it('transforms the URL to use the Origami Image Service', async () => {
|
|
46
31
|
const model = new CAPIImage(mockImage, context)
|
|
47
|
-
sourceSet = await model.sourceSet({ width: 1000 })
|
|
48
|
-
})
|
|
32
|
+
const sourceSet = await model.sourceSet({ width: 1000 })
|
|
49
33
|
|
|
50
|
-
it('transforms the URL to use the Origami Image Service', () => {
|
|
51
34
|
expect(
|
|
52
35
|
sourceSet.every((source) =>
|
|
53
36
|
source.url.startsWith(
|
|
@@ -57,7 +40,10 @@ describe('Image', () => {
|
|
|
57
40
|
).toBeTruthy()
|
|
58
41
|
})
|
|
59
42
|
|
|
60
|
-
it('resizes the image to the requested width', () => {
|
|
43
|
+
it('resizes the image to the requested width', async () => {
|
|
44
|
+
const model = new CAPIImage(mockImage, context)
|
|
45
|
+
const sourceSet = await model.sourceSet({ width: 1000 })
|
|
46
|
+
|
|
61
47
|
expect(
|
|
62
48
|
sourceSet.every(
|
|
63
49
|
(source) =>
|
|
@@ -66,7 +52,9 @@ describe('Image', () => {
|
|
|
66
52
|
).toBeTruthy()
|
|
67
53
|
})
|
|
68
54
|
|
|
69
|
-
it('includes sourceSet for all the possible resolutions we can display the image at, given the requested width and the original source width', () => {
|
|
55
|
+
it('includes sourceSet for all the possible resolutions we can display the image at, given the requested width and the original source width', async () => {
|
|
56
|
+
const model = new CAPIImage(mockImage, context)
|
|
57
|
+
const sourceSet = await model.sourceSet({ width: 1000 })
|
|
70
58
|
expect(sourceSet.length).toEqual(5)
|
|
71
59
|
expect(sourceSet[0]?.dpr).toEqual(1)
|
|
72
60
|
expect(sourceSet[0]?.url).toMatch(/dpr=1/)
|
|
@@ -77,8 +65,10 @@ describe('Image', () => {
|
|
|
77
65
|
|
|
78
66
|
describe("An image that that isn't wide enough to generate high-resolution sourceSet for", () => {
|
|
79
67
|
it('returns an array with a single resolution iamge service UR', async () => {
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const model = new CAPIImage(
|
|
69
|
+
{ ...mockImage, pixelWidth: 1500, pixelHeight: 500 },
|
|
70
|
+
context
|
|
71
|
+
)
|
|
82
72
|
const sourceSet = await model.sourceSet({ width: 1000 })
|
|
83
73
|
expect(sourceSet.length).toEqual(1)
|
|
84
74
|
expect(sourceSet[0]).toEqual({
|
|
@@ -91,8 +81,10 @@ describe('Image', () => {
|
|
|
91
81
|
|
|
92
82
|
describe('An image that that is smaller than the width that was requested', () => {
|
|
93
83
|
it('returns the image at the same width as the original', async () => {
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
const model = new CAPIImage(
|
|
85
|
+
{ ...mockImage, pixelWidth: 500, pixelHeight: 500 },
|
|
86
|
+
context
|
|
87
|
+
)
|
|
96
88
|
const sourceSet = await model.sourceSet({ width: 1000 })
|
|
97
89
|
expect(sourceSet.length).toEqual(1)
|
|
98
90
|
expect(sourceSet[0]).toEqual({
|
|
@@ -105,8 +97,10 @@ describe('Image', () => {
|
|
|
105
97
|
|
|
106
98
|
describe('An image that that is bigger than the maximum width that was requested', () => {
|
|
107
99
|
it('returns the image at the same width as the maximum width', async () => {
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
const model = new CAPIImage(
|
|
101
|
+
{ ...mockImage, pixelWidth: 4000, pixelHeight: 4000 },
|
|
102
|
+
context
|
|
103
|
+
)
|
|
110
104
|
const sourceSet = await model.sourceSet({ width: MAX_IMAGE_WIDTH })
|
|
111
105
|
expect(sourceSet.length).toEqual(1)
|
|
112
106
|
expect(sourceSet[0]?.width).toEqual(MAX_IMAGE_WIDTH)
|
|
@@ -115,8 +109,10 @@ describe('Image', () => {
|
|
|
115
109
|
|
|
116
110
|
describe('A large image with the maxDpr argumet passed', () => {
|
|
117
111
|
it('only returns sourceSet up to and including the maxDpr', async () => {
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
const model = new CAPIImage(
|
|
113
|
+
{ ...mockImage, pixelWidth: 5000, pixelHeight: 500 },
|
|
114
|
+
context
|
|
115
|
+
)
|
|
120
116
|
const sourceSet = await model.sourceSet({ width: 1000, maxDpr: 2 })
|
|
121
117
|
expect(sourceSet.length).toEqual(2)
|
|
122
118
|
expect(sourceSet[0]?.dpr).toEqual(1)
|
|
@@ -137,26 +133,6 @@ describe('Image', () => {
|
|
|
137
133
|
await expect(
|
|
138
134
|
model.sourceSet({ width: 1000, maxDpr: 2 })
|
|
139
135
|
).rejects.toThrow('not-a-uuid is not a valid Content API Image ID')
|
|
140
|
-
expect(getImageMetadata).not.toHaveBeenCalled()
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
describe('When the image service fails to return metadata', () => {
|
|
145
|
-
let sourceSet: ImageSource[]
|
|
146
|
-
beforeEach(async () => {
|
|
147
|
-
getImageMetadata.mockRejectedValue(null)
|
|
148
|
-
const model = new CAPIImage(mockImage, context)
|
|
149
|
-
sourceSet = await model.sourceSet({ width: 3000 })
|
|
150
|
-
})
|
|
151
|
-
it('passes the requested width to the image service', async () => {
|
|
152
|
-
expect(sourceSet.length).toEqual(1)
|
|
153
|
-
expect(sourceSet[0]?.width).toEqual(3000)
|
|
154
|
-
expect(sourceSet[0]?.url).toMatch(/width=3000/)
|
|
155
|
-
})
|
|
156
|
-
it('falls back to a single DPR source', async () => {
|
|
157
|
-
expect(sourceSet.length).toEqual(1)
|
|
158
|
-
expect(sourceSet[0]?.dpr).toEqual(1)
|
|
159
|
-
expect(sourceSet[0]?.url).toMatch(/dpr=1/)
|
|
160
136
|
})
|
|
161
137
|
})
|
|
162
138
|
})
|
|
@@ -235,17 +211,18 @@ describe('Image', () => {
|
|
|
235
211
|
})
|
|
236
212
|
|
|
237
213
|
describe('width/height', () => {
|
|
238
|
-
it('returns the original width and height from
|
|
239
|
-
getImageMetadata.mockResolvedValue({ width: 100, height: 200 })
|
|
214
|
+
it('returns the original width and height from capi data', async () => {
|
|
240
215
|
const model = new CAPIImage(mockImage, context)
|
|
241
216
|
const { width, height } = (await model.dimensions()) || {}
|
|
242
|
-
expect(width).toEqual(
|
|
243
|
-
expect(height).toEqual(
|
|
217
|
+
expect(width).toEqual(5000)
|
|
218
|
+
expect(height).toEqual(1000)
|
|
244
219
|
})
|
|
245
220
|
|
|
246
|
-
it('returns null if
|
|
247
|
-
|
|
248
|
-
|
|
221
|
+
it('returns null if no width and height in capi data', async () => {
|
|
222
|
+
const model = new CAPIImage(
|
|
223
|
+
{ ...mockImage, pixelHeight: undefined, pixelWidth: undefined },
|
|
224
|
+
context
|
|
225
|
+
)
|
|
249
226
|
const dimensions = await model.dimensions()
|
|
250
227
|
expect(dimensions).toEqual(null)
|
|
251
228
|
})
|
package/src/model/Image.ts
CHANGED
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
validLiteralUnionValue,
|
|
12
12
|
} from '../resolvers/literal-union'
|
|
13
13
|
import { ImageFormat, ImageType } from '../resolvers/scalars'
|
|
14
|
-
import
|
|
15
|
-
import { BaseError, OperationalError } from '@dotcom-reliability-kit/errors'
|
|
14
|
+
import { BaseError } from '@dotcom-reliability-kit/errors'
|
|
16
15
|
import type { ImageSource } from '../generated'
|
|
17
16
|
|
|
18
17
|
export type ImageSourceArgs = {
|
|
@@ -126,7 +125,7 @@ export class CAPIImage implements Image {
|
|
|
126
125
|
args.maxDpr || Infinity,
|
|
127
126
|
Math.floor(dimensions.width / maxAllowedWidth)
|
|
128
127
|
)
|
|
129
|
-
:
|
|
128
|
+
: 2
|
|
130
129
|
|
|
131
130
|
const resolutions = [...Array(maxDpr + 1).keys()].slice(1)
|
|
132
131
|
|
|
@@ -158,40 +157,17 @@ export class CAPIImage implements Image {
|
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
// HACK:KB:20241029 graphics don't
|
|
162
|
-
//
|
|
163
|
-
// performance. skip calling Image Service for
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
return null
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
const imageMetadata = await this.#dataSources.origami.getImageMetadata(
|
|
177
|
-
this.capiImage.binaryUrl
|
|
178
|
-
)
|
|
179
|
-
return imageMetadata
|
|
180
|
-
} catch (error) {
|
|
181
|
-
if (isError(error)) {
|
|
182
|
-
this.context.logger.warn({
|
|
183
|
-
event: 'RECOVERABLE_ERROR',
|
|
184
|
-
error: new OperationalError({
|
|
185
|
-
code: 'IMAGE_DIMENSIONS_ERROR',
|
|
186
|
-
message: `Failed to get dimensions for ${this.capiImage.binaryUrl}`,
|
|
187
|
-
url: this.capiImage.binaryUrl,
|
|
188
|
-
cause: error,
|
|
189
|
-
}),
|
|
190
|
-
})
|
|
191
|
-
}
|
|
160
|
+
// HACK:KB:20241029 graphics and images in layouts don't have pixelWidth/
|
|
161
|
+
// pixelHeight because of reasons. we want to avoid calling Image Service
|
|
162
|
+
// to improve performance. skip calling Image Service for the time being
|
|
163
|
+
this.context.logger.warn({
|
|
164
|
+
event: 'SKIPPING_IMAGE_DIMENSIONS',
|
|
165
|
+
message: 'Not calling Image Service to get graphics dimensions',
|
|
166
|
+
url: this.capiImage.binaryUrl,
|
|
167
|
+
type: this.type(),
|
|
168
|
+
})
|
|
192
169
|
|
|
193
|
-
|
|
194
|
-
}
|
|
170
|
+
return null
|
|
195
171
|
}
|
|
196
172
|
|
|
197
173
|
credit() {
|