@bytebrand/export-cars 1.10.6 → 1.10.8
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/dist/services/images.service.d.ts +4 -2
- package/dist/services/images.service.js +39 -52
- package/dist/services/images.service.js.map +1 -1
- package/dist/transformers/facebook-shop.transformer.js +1 -3
- package/dist/transformers/facebook-shop.transformer.js.map +1 -1
- package/dist/transformers/mobile.transformer.d.ts +4 -7
- package/dist/transformers/mobile.transformer.js +13 -45
- package/dist/transformers/mobile.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/services/images.service.ts +47 -61
- package/src/transformers/facebook-shop.transformer.ts +1 -3
- package/src/transformers/mobile.transformer.ts +7 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebrand/export-cars",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "bytebrand",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=14.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "26ce620428ff47711dc8142af5da04b9ddf380f0"
|
|
64
64
|
}
|
|
@@ -14,6 +14,12 @@ import { ImageType } from '../enums';
|
|
|
14
14
|
|
|
15
15
|
@Injectable()
|
|
16
16
|
export class ImagesService {
|
|
17
|
+
private readonly DEFAULT_IMAGES = [
|
|
18
|
+
'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg',
|
|
19
|
+
'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg',
|
|
20
|
+
'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg',
|
|
21
|
+
];
|
|
22
|
+
|
|
17
23
|
constructor(private readonly configService: ConfigService, private readonly userService: UserService) { }
|
|
18
24
|
|
|
19
25
|
async getImages(
|
|
@@ -24,63 +30,22 @@ export class ImagesService {
|
|
|
24
30
|
if (imageType === ImageType.default) {
|
|
25
31
|
return this.getDefaultImages(car, images);
|
|
26
32
|
} else {
|
|
27
|
-
|
|
28
|
-
return await this.getMarketingImages(images, carId);
|
|
33
|
+
return await this.getMarketingImages(car, images);
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
getDefaultImages(car: DataSchemes.Car, images: ImboImageResponseInterface[]): Array<string> {
|
|
33
|
-
const defaultImages = [
|
|
34
|
-
'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg',
|
|
35
|
-
'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg',
|
|
36
|
-
'https://images.auto.de/carimage/noimage/gY1zF8PXzH2W/large-cached.jpeg',
|
|
37
|
-
'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg',
|
|
38
|
-
];
|
|
39
|
-
|
|
40
38
|
if (!isNotEmptyArray(images)) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const firstImageId = get(car, 'metaData.mainImageId', null);
|
|
45
|
-
const secondImageId = get(car, 'metaData.secImageId', null);
|
|
46
|
-
const thirdImageId = get(car, 'metaData.thirdImageId', null);
|
|
47
|
-
|
|
48
|
-
if (firstImageId) {
|
|
49
|
-
images.forEach((image, index) => {
|
|
50
|
-
if (firstImageId === image.imageIdentifier) {
|
|
51
|
-
const tmp = images[index];
|
|
52
|
-
images[index] = images[0];
|
|
53
|
-
images[0] = tmp;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (secondImageId) {
|
|
59
|
-
images.forEach((image, index) => {
|
|
60
|
-
if (secondImageId === image.imageIdentifier) {
|
|
61
|
-
const tmp = images[index];
|
|
62
|
-
images[index] = images[1];
|
|
63
|
-
images[1] = tmp;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (thirdImageId) {
|
|
69
|
-
images.forEach((image, index) => {
|
|
70
|
-
if (thirdImageId === image.imageIdentifier) {
|
|
71
|
-
const tmp = images[index];
|
|
72
|
-
images[index] = images[2];
|
|
73
|
-
images[2] = tmp;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
39
|
+
return this.DEFAULT_IMAGES;
|
|
76
40
|
}
|
|
77
41
|
|
|
78
|
-
|
|
42
|
+
this.sortImages(images, car);
|
|
43
|
+
const transformedImages = this.generateImageLinks(images, get(car, '_id'));
|
|
79
44
|
|
|
80
|
-
const transformedImages = this.generateImageLinks(images.filter(i => i), carId);
|
|
81
45
|
if (transformedImages.length < 17) {
|
|
82
|
-
transformedImages.push(...
|
|
46
|
+
transformedImages.push(...this.DEFAULT_IMAGES);
|
|
83
47
|
}
|
|
48
|
+
|
|
84
49
|
return transformedImages;
|
|
85
50
|
}
|
|
86
51
|
|
|
@@ -90,40 +55,34 @@ export class ImagesService {
|
|
|
90
55
|
});
|
|
91
56
|
}
|
|
92
57
|
|
|
93
|
-
async getMarketingImages(
|
|
58
|
+
async getMarketingImages(car: DataSchemes.Car, images: ImboImageResponseInterface[]): Promise<string[]> {
|
|
94
59
|
const imageUrl = this.configService.config.marketingImageUrl;
|
|
95
|
-
const transformedImages = this.transformImagesArrayIntoObject(images);
|
|
96
60
|
|
|
61
|
+
const transformedImages = this.transformImagesArrayIntoObject(images);
|
|
97
62
|
const config = await this.userService.getMarketingImageConfig(this.configService.config.marketingImageConfigId);
|
|
98
63
|
const marketingImageConfigs = config.marketingImages.map(i => ({ marketingImageCodes: i.imageCodes }));
|
|
99
64
|
|
|
100
|
-
const defImages = [
|
|
101
|
-
'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg',
|
|
102
|
-
'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg',
|
|
103
|
-
'https://images.auto.de/carimage/noimage/gY1zF8PXzH2W/large-cached.jpeg',
|
|
104
|
-
'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg',
|
|
105
|
-
];
|
|
106
|
-
|
|
107
65
|
const imageUrls = [];
|
|
108
|
-
|
|
109
66
|
for (let i = 0; i < marketingImageConfigs.length; i++) {
|
|
110
67
|
const marketingImage = marketingImageConfigs[i];
|
|
111
68
|
for (let i = 0; i < marketingImage.marketingImageCodes.length; i++) {
|
|
112
69
|
const imageCode = marketingImage.marketingImageCodes[i];
|
|
113
70
|
const imageId = transformedImages[imageCode];
|
|
114
71
|
if (imageId) {
|
|
115
|
-
imageUrls.push(this.
|
|
72
|
+
imageUrls.push(this.getImagePathWithExtension(imageUrl, get(car, '_id', ''), imageId, config));
|
|
116
73
|
break;
|
|
117
74
|
}
|
|
118
75
|
}
|
|
119
76
|
}
|
|
77
|
+
|
|
120
78
|
if (imageUrls.length < FB_MAX_IMAGE_COUNT_FOR_DEAFULT) {
|
|
121
|
-
imageUrls.push(...
|
|
79
|
+
imageUrls.push(...this.DEFAULT_IMAGES);
|
|
122
80
|
}
|
|
81
|
+
|
|
123
82
|
return imageUrls;
|
|
124
83
|
}
|
|
125
84
|
|
|
126
|
-
private transformImagesArrayIntoObject(images:
|
|
85
|
+
private transformImagesArrayIntoObject(images: ImboImageResponseInterface[]) {
|
|
127
86
|
const result: { [imageCode: string]: string } = {};
|
|
128
87
|
images.forEach(image => {
|
|
129
88
|
const imageCode = image.imageCodePredicted.split('-')[0];
|
|
@@ -136,7 +95,7 @@ export class ImagesService {
|
|
|
136
95
|
return `${imageUrl}/${[carId[0], carId[1], carId[2], carId].join('/')}`;
|
|
137
96
|
}
|
|
138
97
|
|
|
139
|
-
protected
|
|
98
|
+
protected getImagePathWithExtension(
|
|
140
99
|
imageUrl: string,
|
|
141
100
|
carId: string,
|
|
142
101
|
imageId: string,
|
|
@@ -145,4 +104,31 @@ export class ImagesService {
|
|
|
145
104
|
const { channelCode, imageExtension } = config;
|
|
146
105
|
return `${this.getChannelPath(imageUrl, carId)}/${channelCode.replace(/ /g, '-')}-${imageId}.${imageExtension}`;
|
|
147
106
|
}
|
|
107
|
+
|
|
108
|
+
private sortImages(images: ImboImageResponseInterface[], car: DataSchemes.Car): void {
|
|
109
|
+
const firstImageId = get(car, 'metaData.mainImageId', null);
|
|
110
|
+
const secondImageId = get(car, 'metaData.secImageId', null);
|
|
111
|
+
const thirdImageId = get(car, 'metaData.thirdImageId', null);
|
|
112
|
+
|
|
113
|
+
if (firstImageId) {
|
|
114
|
+
images.forEach((image, index) => {
|
|
115
|
+
if (firstImageId === image?.imageIdentifier) {
|
|
116
|
+
const tmp = images[index];
|
|
117
|
+
images[index] = images[0];
|
|
118
|
+
images[0] = tmp;
|
|
119
|
+
}
|
|
120
|
+
if (secondImageId === image?.imageIdentifier) {
|
|
121
|
+
const tmp = images[index];
|
|
122
|
+
images[index] = images[1];
|
|
123
|
+
images[1] = tmp;
|
|
124
|
+
}
|
|
125
|
+
if (thirdImageId === image?.imageIdentifier) {
|
|
126
|
+
const tmp = images[index];
|
|
127
|
+
images[index] = images[2];
|
|
128
|
+
images[2] = tmp;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
images.filter(i => i); // sometimes thirdImageId exists but image is not
|
|
132
|
+
}
|
|
133
|
+
}
|
|
148
134
|
}
|
|
@@ -56,11 +56,9 @@ export class FacebookShopTransformer {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
private getTitle(car: DataSchemes.Car): string {
|
|
59
|
-
const year = toString(get(car, 'mainData.constructionYear', ''));
|
|
60
59
|
const make = toString(get(car, 'mainData.make', ''));
|
|
61
60
|
const model = toString(get(car, 'mainData.model', ''));
|
|
62
|
-
|
|
63
|
-
return trim(escape(join([year, make, model, subModel], ' ')));
|
|
61
|
+
return trim(escape(join([make, model], ' ')));
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
private getCondition(car: DataSchemes.Car): string {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { DataSchemes } from '@bytebrand/car-schema';
|
|
3
3
|
import { get, isEmpty, isNil, set, toString, upperFirst } from 'lodash';
|
|
4
|
-
import { MappingService } from '../services
|
|
4
|
+
import { MappingService, UserService, ImagesService } from '../services';
|
|
5
5
|
import { MappingRules } from '../interfaces/mapping-rules.interface';
|
|
6
|
-
import { UserService } from '../services/user.service';
|
|
7
6
|
import { CarDescriptionFactory, DescriptionTypeEnum } from '@bytebrand/car-description';
|
|
8
|
-
import { ConfigService } from '../services
|
|
7
|
+
import { ConfigService } from '../services';
|
|
9
8
|
import { isNotEmptyArray } from '../utils/validator.utils';
|
|
10
9
|
import { LoggerService } from '@bytebrand/cronicle-helper';
|
|
11
10
|
|
|
@@ -19,6 +18,7 @@ export class MobileTransformer {
|
|
|
19
18
|
private mappingService: MappingService,
|
|
20
19
|
private userService: UserService,
|
|
21
20
|
private configService: ConfigService,
|
|
21
|
+
private imagesService: ImagesService,
|
|
22
22
|
) {}
|
|
23
23
|
|
|
24
24
|
async transform(carData: DataSchemes.Car, images: unknown[]): Promise<unknown> {
|
|
@@ -347,17 +347,11 @@ export class MobileTransformer {
|
|
|
347
347
|
return `https://www.${this.configService.config.domain}${car._id}?source=classifieds&medium=listing&campaign=${this.configService.config.campaign}`;
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
private getImages(car: DataSchemes.Car, images
|
|
351
|
-
|
|
352
|
-
try {
|
|
353
|
-
res = this.getImagesField(car._id, get(car, 'metaData.mainImageId', null), images);
|
|
354
|
-
} catch (e) {
|
|
355
|
-
LoggerService.error(e);
|
|
356
|
-
throw e;
|
|
357
|
-
}
|
|
350
|
+
private async getImages(car: DataSchemes.Car, images): Promise<string | null> {
|
|
351
|
+
const transformedImages = await this.imagesService.getImages(car, images, this.configService.config.imageType);
|
|
358
352
|
let imagesAsALine;
|
|
359
|
-
if (isNotEmptyArray(
|
|
360
|
-
imagesAsALine =
|
|
353
|
+
if (isNotEmptyArray(transformedImages)) {
|
|
354
|
+
imagesAsALine = transformedImages.map((el: string) => el).join(';');
|
|
361
355
|
}
|
|
362
356
|
return imagesAsALine || null;
|
|
363
357
|
}
|
|
@@ -474,32 +468,4 @@ export class MobileTransformer {
|
|
|
474
468
|
}
|
|
475
469
|
return mileage.toString();
|
|
476
470
|
}
|
|
477
|
-
|
|
478
|
-
private getImagesField(carId: string, mainImageId: string, images: unknown[]): { url: string }[] {
|
|
479
|
-
const defImages = [
|
|
480
|
-
{ url: 'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg' },
|
|
481
|
-
{ url: 'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg' },
|
|
482
|
-
{ url: 'https://images.auto.de/carimage/noimage/gY1zF8PXzH2W/large-cached.jpeg' },
|
|
483
|
-
{ url: 'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg' },
|
|
484
|
-
];
|
|
485
|
-
if (isNotEmptyArray(images)) {
|
|
486
|
-
return images.sort(this.setMainImageFirst(mainImageId)).map((image: any) => {
|
|
487
|
-
return { url: this.buildLargeImageUrl(carId, image.imageIdentifier) };
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
return defImages;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
private buildLargeImageUrl(carId: string, imageId: string): string {
|
|
494
|
-
const format = this.configService.config.campaign === 'eauto' ? 'jpeg' : 'webp';
|
|
495
|
-
return `${this.configService.config.imageUrl}/${carId}/${imageId}/large-cached.${format}`;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
private setMainImageFirst(mainImageId: string): (current: any, next: any) => number {
|
|
499
|
-
return (current: any, next: any): number => {
|
|
500
|
-
if (current.imageIdentifier === mainImageId) return -1;
|
|
501
|
-
if (next.imageIdentifier === mainImageId) return 1;
|
|
502
|
-
return 0;
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
471
|
}
|