@bytebrand/export-cars 1.21.53 → 1.21.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.21.53",
3
+ "version": "1.21.55",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -6,9 +6,7 @@ export class GoogleConfig extends Config {
6
6
  constructor(params: Params) {
7
7
  super(params);
8
8
  this.pathesConfig.localConvertedDirectory = `resources/${ExportType.GOOGLE}-export`;
9
- this.imageType = ImageType.marketing;
10
- this.marketingImageConfigId = this.environmentConfig[params.environment].criteoMarketingImagesConfigId;
11
-
9
+ this.imageType = ImageType.default;
12
10
  this.outputFiles = [
13
11
  `${this.pathesConfig.localConvertedDirectory}/api_export_cars_${ExportType.GOOGLE}.${FileType.XML}`,
14
12
  ];
@@ -95,6 +95,56 @@ export class ImagesService {
95
95
  }
96
96
  }
97
97
 
98
+ async getExtIntDefaultImages(car: DataSchemes.Car, images: ImboImageResponseInterface[], imageType: ImageType, ignoreDefImages: boolean): Promise<{
99
+ ext: any[];
100
+ int: any[];
101
+ feat: any[];
102
+ }> {
103
+ if (!isNotEmptyArray(images)) {
104
+ return { ext: [], int: [], feat: [] };
105
+ }
106
+
107
+ const categorizedImages = this.categorizeImages(images);
108
+
109
+ const sortedImages = {
110
+ ext: this.sortImages(categorizedImages.ext),
111
+ int: this.sortImages(categorizedImages.int),
112
+ feat: this.sortImages(categorizedImages.feat),
113
+ };
114
+
115
+ const transformedImages = {
116
+ ext: this.generateImageLinks(sortedImages.ext, car._id),
117
+ int: this.generateImageLinks(sortedImages.int, car._id),
118
+ feat: this.generateImageLinks(sortedImages.feat, car._id),
119
+ };
120
+
121
+ return transformedImages;
122
+ }
123
+
124
+ private categorizeImages(images: ImboImageResponseInterface[]): {
125
+ ext: ImboImageResponseInterface[];
126
+ int: ImboImageResponseInterface[];
127
+ feat: ImboImageResponseInterface[];
128
+ } {
129
+ const categorizedImages = {
130
+ ext: [] as ImboImageResponseInterface[],
131
+ int: [] as ImboImageResponseInterface[],
132
+ feat: [] as ImboImageResponseInterface[],
133
+ };
134
+
135
+ images.forEach((image) => {
136
+ if (image.imageCodePredicted.includes('_feat_') || /^conext/.test(image.imageCodePredicted)) {
137
+ categorizedImages.feat.push(image);
138
+ } else if (/^ext_[frlb]/.test(image.imageCodePredicted)) {
139
+ categorizedImages.ext.push(image);
140
+ } else if (/^int_[frlb]/.test(image.imageCodePredicted)) {
141
+ categorizedImages.int.push(image);
142
+ }
143
+ });
144
+
145
+ return categorizedImages;
146
+ }
147
+
98
148
  getDefaultImages(carId: string, images: ImboImageResponseInterface[], ignoreDefImages: boolean): Array<string> {
99
149
  if (!isNotEmptyArray(images)) {
100
150
  return this.DEFAULT_IMAGES;
@@ -31,13 +31,22 @@ export class GoogleTransformer {
31
31
  return null
32
32
 
33
33
  const carId = toString(get(car, '_id', ''));
34
- const transformedImages = await this.imageService.getImages(
34
+ const transformedImages = await this.imageService.getExtIntDefaultImages(
35
35
  car,
36
36
  images,
37
37
  this.configService.config.imageType,
38
38
  false,
39
39
  );
40
40
 
41
+ if (!transformedImages.ext.length)
42
+ return null
43
+
44
+ const allImages = [
45
+ ...transformedImages.ext,
46
+ ...transformedImages.int,
47
+ ...transformedImages.feat
48
+ ]
49
+
41
50
  console.log(car._id, transformedImages);
42
51
 
43
52
  return {
@@ -55,8 +64,8 @@ export class GoogleTransformer {
55
64
  product_type: this.getCategory(car),
56
65
  VIN: this.transformService.vinCode(car),
57
66
  id: carId,
58
- image_link: transformedImages[0],
59
- additional_image_link: transformedImages.slice(1, 10),
67
+ image_link: allImages[0],
68
+ additional_image_link: allImages.slice(1, 10),
60
69
  ads_redirect: this.getLink(car),
61
70
  link: this.getLink(car),
62
71
  link_template: `${this.getLink(car)}?store={store_code}`,