@bytebrand/export-cars 1.21.7 → 1.21.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/.editorconfig +8 -8
- package/.eslintignore +1 -1
- package/.eslintrc.js +24 -24
- package/.prettierrc.js +7 -7
- package/README.md +65 -65
- package/dist/configs/index.d.ts +1 -0
- package/dist/configs/index.js +1 -0
- package/dist/configs/index.js.map +1 -1
- package/dist/configs/santander.config.d.ts +5 -0
- package/dist/configs/santander.config.js +18 -0
- package/dist/configs/santander.config.js.map +1 -0
- package/dist/enums/export-type.enum.d.ts +1 -0
- package/dist/enums/export-type.enum.js +1 -0
- package/dist/enums/export-type.enum.js.map +1 -1
- package/dist/export.command.js +1 -1
- package/dist/export.command.js.map +1 -1
- package/dist/export.schema.d.ts +6 -2
- package/dist/export.schema.js +4 -0
- package/dist/export.schema.js.map +1 -1
- package/dist/exporters/index.d.ts +1 -0
- package/dist/exporters/index.js +1 -0
- package/dist/exporters/index.js.map +1 -1
- package/dist/exporters/santander.exporter.d.ts +12 -0
- package/dist/exporters/santander.exporter.js +63 -0
- package/dist/exporters/santander.exporter.js.map +1 -0
- package/dist/formats/auto24-xml.builder.js +2 -2
- package/dist/formats/google-xml.builder.js +3 -3
- package/dist/formats/modix-xml.builder.js +2 -2
- package/dist/formats/ooyyo-xml.builder.js +1 -1
- package/dist/formats/santander-csv.builder.d.ts +6 -0
- package/dist/formats/santander-csv.builder.js +17 -0
- package/dist/formats/santander-csv.builder.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/nest-cli.json +5 -5
- package/package.json +61 -61
- package/src/app.module.ts +38 -38
- package/src/configs/alleskralle.config.ts +15 -15
- package/src/configs/as24.config.ts +13 -13
- package/src/configs/auto24.config.ts +15 -15
- package/src/configs/autoboerse.config.ts +16 -16
- package/src/configs/autouncle.config.ts +14 -14
- package/src/configs/awin.config.ts +15 -15
- package/src/configs/by-owner.config.ts +14 -14
- package/src/configs/config.ts +83 -83
- package/src/configs/criteo.config.ts +17 -17
- package/src/configs/dasparking.config.ts +15 -15
- package/src/configs/eauto.config.ts +15 -15
- package/src/configs/evium.config.ts +18 -18
- package/src/configs/facebook-shop.config.ts +16 -16
- package/src/configs/fb.config.ts +16 -16
- package/src/configs/google.config.ts +14 -14
- package/src/configs/index.ts +22 -21
- package/src/configs/kleinanzeigeFocus.config.ts +14 -14
- package/src/configs/marktde.config.ts +18 -18
- package/src/configs/meinstadt.config.ts +15 -15
- package/src/configs/mitula.config.ts +14 -14
- package/src/configs/ooyyo.config.ts +15 -15
- package/src/configs/santander.config.ts +15 -0
- package/src/configs/trovit.config.ts +14 -14
- package/src/configs/yescar.config.ts +17 -17
- package/src/constants/autouncle.contants.ts +4 -4
- package/src/constants/fb.constants.ts +7 -7
- package/src/constants/index.ts +1 -1
- package/src/constants/modix/body-color-name.constant.ts +20 -20
- package/src/constants/modix/category.constant.ts +14 -14
- package/src/constants/modix/fuel.constant.ts +14 -14
- package/src/constants/modix/index.ts +7 -7
- package/src/constants/modix/manufacturers.constant.ts +7498 -7498
- package/src/constants/modix/transmission.constant.ts +8 -8
- package/src/constants/modix/usage-type.constant.ts +13 -13
- package/src/constants/modix/vehicle-class.constant.ts +17 -17
- package/src/enums/environment.enum.ts +5 -5
- package/src/enums/export-type.enum.ts +33 -32
- package/src/enums/file-types.enum.ts +8 -8
- package/src/enums/image-type.enum.ts +4 -4
- package/src/enums/index.ts +4 -4
- package/src/export.command.ts +37 -37
- package/src/export.schema.ts +134 -128
- package/src/exporters/as24.exporter.ts +69 -69
- package/src/exporters/auto24.exporter.ts +48 -48
- package/src/exporters/autouncle.exporter.ts +60 -60
- package/src/exporters/awin.exporter.ts +47 -47
- package/src/exporters/by-owner.exporter.ts +44 -44
- package/src/exporters/facebook-shop.exporter.ts +51 -51
- package/src/exporters/fb.exporter.ts +52 -52
- package/src/exporters/google.exporter.ts +45 -45
- package/src/exporters/index.ts +15 -14
- package/src/exporters/meinstadt.exporter.ts +55 -55
- package/src/exporters/mobile.exporter.ts +64 -64
- package/src/exporters/modix.exporter.ts +56 -56
- package/src/exporters/ooyyo.exporter.ts +48 -48
- package/src/exporters/rubrikk.exporter.ts +53 -53
- package/src/exporters/santander.exporter.ts +50 -0
- package/src/exporters/trovit.exporter.ts +51 -51
- package/src/formats/auto24-xml.builder.ts +54 -54
- package/src/formats/autouncle-json.builder.ts +20 -20
- package/src/formats/awin-csv.builder.ts +16 -16
- package/src/formats/facebook-shop.builder.ts +69 -69
- package/src/formats/fb-xml.builder.ts +71 -71
- package/src/formats/google-xml.builder.ts +35 -35
- package/src/formats/index.ts +5 -5
- package/src/formats/meinstadt-json.builder.ts +19 -19
- package/src/formats/modix-xml.builder.ts +180 -180
- package/src/formats/ooyyo-xml.builder.ts +48 -48
- package/src/formats/rubrikk-xml.builder.ts +27 -27
- package/src/formats/santander-csv.builder.ts +15 -0
- package/src/formats/trovit-xml.builder.ts +44 -44
- package/src/interfaces/atributes-wrap-item.intreface.ts +6 -6
- package/src/interfaces/dealers-mapping.interface.ts +7 -7
- package/src/interfaces/description.interface.ts +24 -24
- package/src/interfaces/export-item.interface.ts +366 -366
- package/src/interfaces/exporter.interface.ts +3 -3
- package/src/interfaces/index.ts +3 -3
- package/src/interfaces/input.interface.ts +6 -6
- package/src/interfaces/mapping-rules.interface.ts +11 -11
- package/src/interfaces/modix/index.ts +1 -1
- package/src/interfaces/modix/modix-item-list.interface.ts +5 -5
- package/src/interfaces/params.interface.ts +13 -13
- package/src/interfaces/rule-parser.interface.ts +3 -3
- package/src/main.ts +14 -14
- package/src/rules/abstract.rule.ts +37 -37
- package/src/rules/date.rule.ts +19 -19
- package/src/rules/number.rule.ts +15 -15
- package/src/rules/string.rule.ts +8 -8
- package/src/services/car.service.ts +49 -49
- package/src/services/config.service.ts +15 -15
- package/src/services/images.service.ts +207 -207
- package/src/services/index.ts +9 -9
- package/src/services/loader.service.ts +29 -29
- package/src/services/mapping.service.ts +91 -91
- package/src/services/request.service.ts +44 -44
- package/src/services/rules.service.ts +61 -61
- package/src/services/transformer.service.ts +129 -129
- package/src/services/user.service.ts +57 -57
- package/src/transformers/as24.transformer.ts +253 -253
- package/src/transformers/auto24.transfomer.ts +155 -155
- package/src/transformers/autouncle.transformer.ts +236 -236
- package/src/transformers/awin.transformer.ts +193 -193
- package/src/transformers/by-owner.transformer.ts +354 -354
- package/src/transformers/facebook-shop.transformer.ts +93 -93
- package/src/transformers/fb-description.transformer.ts +316 -316
- package/src/transformers/fb-equipment.transformer.ts +161 -161
- package/src/transformers/fb.transformer.ts +655 -655
- package/src/transformers/google.transformer.ts +169 -169
- package/src/transformers/index.ts +5 -5
- package/src/transformers/meinstadt.transformer.ts +92 -92
- package/src/transformers/mobile.transformer.ts +482 -482
- package/src/transformers/modix.transformer.ts +227 -227
- package/src/transformers/ooyyo.transformer.ts +109 -109
- package/src/transformers/rubrikk.transformer.ts +200 -200
- package/src/transformers/trovit.transformer.ts +63 -63
- package/src/utils/converter.utils.ts +15 -15
- package/src/utils/index.ts +2 -2
- package/src/utils/validator.utils.ts +7 -7
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +29 -29
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
import { createWriteStream } from 'fs';
|
|
2
|
-
import { extname } from 'path';
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
|
|
5
|
-
import { Injectable } from '@nestjs/common';
|
|
6
|
-
|
|
7
|
-
import { MarketingImageConfigsInterface } from '@bytebrand/autode-request';
|
|
8
|
-
import { ImboImageResponseInterface } from '@bytebrand/chunkable';
|
|
9
|
-
import { DataSchemes } from '@bytebrand/car-schema';
|
|
10
|
-
|
|
11
|
-
import { FB_MAX_IMAGE_COUNT_FOR_DEAFULT } from '../constants/fb.constants';
|
|
12
|
-
import { ConfigService } from './config.service';
|
|
13
|
-
import { UserService } from './user.service';
|
|
14
|
-
import { isNotEmptyArray } from '../utils';
|
|
15
|
-
import { Config } from '../configs/config';
|
|
16
|
-
import { ImageType } from '../enums';
|
|
17
|
-
|
|
18
|
-
@Injectable()
|
|
19
|
-
export class ImagesService {
|
|
20
|
-
private readonly IMAGES_SORT_ORDER: { [imageCode: string]: number } = {
|
|
21
|
-
ext_f_right: 1,
|
|
22
|
-
ext_f_cowl: 2,
|
|
23
|
-
ext_f_left: 3,
|
|
24
|
-
ext_l_main: 4,
|
|
25
|
-
ext_b_left: 5,
|
|
26
|
-
ext_b_main: 6,
|
|
27
|
-
ext_b_trunk: 7,
|
|
28
|
-
ext_b_right: 8,
|
|
29
|
-
ext_r_main: 9,
|
|
30
|
-
ext_f_main: 10,
|
|
31
|
-
ext_f_main_opened: 11,
|
|
32
|
-
ext_f_left_opened: 12,
|
|
33
|
-
ext_l_main_opened: 13,
|
|
34
|
-
ext_b_left_opened: 14,
|
|
35
|
-
ext_b_main_opened: 15,
|
|
36
|
-
ext_b_right_opened: 16,
|
|
37
|
-
ext_r_main_opened: 17,
|
|
38
|
-
ext_f_right_opened: 18,
|
|
39
|
-
conext_f_main: 19,
|
|
40
|
-
conext_f_left: 20,
|
|
41
|
-
conext_l_main: 21,
|
|
42
|
-
conext_b_left: 22,
|
|
43
|
-
conext_b_main: 23,
|
|
44
|
-
conext_b_right: 24,
|
|
45
|
-
conext_r_main: 25,
|
|
46
|
-
conext_f_right: 26,
|
|
47
|
-
ext_feat_engine: 27,
|
|
48
|
-
int_f_ipanel1: 28,
|
|
49
|
-
int_f_ipanel2: 29,
|
|
50
|
-
int_f_ipanel5: 30,
|
|
51
|
-
int_f_driverseats: 31,
|
|
52
|
-
int_f_assistantseats: 32,
|
|
53
|
-
int_b_rearseats: 33,
|
|
54
|
-
int_f_fandrseats: 34,
|
|
55
|
-
int_f_driverdashboard: 35,
|
|
56
|
-
int_f_doordriverside: 36,
|
|
57
|
-
int_f_stickshift: 37,
|
|
58
|
-
int_b_trunk: 38,
|
|
59
|
-
int_t_sunroof: 39,
|
|
60
|
-
int_t_panorama_sunroof: 40,
|
|
61
|
-
int_f_ipanel3: 41,
|
|
62
|
-
int_f_ipanel4: 42,
|
|
63
|
-
int_feat_seatheating: 43,
|
|
64
|
-
ext_feat_ledlights: 44,
|
|
65
|
-
ext_feat_cruisecontrol: 45,
|
|
66
|
-
int_feat_climatization: 46,
|
|
67
|
-
int_feat_bluetooth: 47,
|
|
68
|
-
ext_feat_rainsensor: 48,
|
|
69
|
-
ext_feat_rims: 49,
|
|
70
|
-
ext_feat_parkassistant: 50,
|
|
71
|
-
ext_feat_lightsensor: 51,
|
|
72
|
-
int_feat_handsfree: 52,
|
|
73
|
-
int_feat_headupdisplay: 53,
|
|
74
|
-
ext_feat_trafficsignrec: 54,
|
|
75
|
-
ext_feat_auxiliaryheating: 55,
|
|
76
|
-
ext_feat_laneassistant: 56,
|
|
77
|
-
int_feat_startstop: 57,
|
|
78
|
-
int_feat_breakassistant: 58,
|
|
79
|
-
ext_feat_nightassistant: 59,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
private readonly DEFAULT_IMAGES = [
|
|
83
|
-
'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg',
|
|
84
|
-
'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg',
|
|
85
|
-
'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg',
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
constructor(private readonly configService: ConfigService, private readonly userService: UserService) { }
|
|
89
|
-
|
|
90
|
-
async getImages(car: DataSchemes.Car, images: ImboImageResponseInterface[], imageType: ImageType, ignoreDefImages: boolean): Promise<Array<string>> {
|
|
91
|
-
if (imageType === ImageType.default) {
|
|
92
|
-
return this.getDefaultImages(car._id, images, ignoreDefImages);
|
|
93
|
-
} else {
|
|
94
|
-
return await this.getMarketingImages(car._id, images, ignoreDefImages);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getDefaultImages(carId: string, images: ImboImageResponseInterface[], ignoreDefImages: boolean): Array<string> {
|
|
99
|
-
if (!isNotEmptyArray(images)) {
|
|
100
|
-
return this.DEFAULT_IMAGES;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const sortedImages = this.sortImages(images);
|
|
104
|
-
const transformedImages = this.generateImageLinks(sortedImages, carId);
|
|
105
|
-
|
|
106
|
-
if (!ignoreDefImages && transformedImages.length < 17) {
|
|
107
|
-
transformedImages.push(...this.DEFAULT_IMAGES);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return transformedImages;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
generateImageLinks(images: ImboImageResponseInterface[], carId: string) {
|
|
114
|
-
return images.map((image: ImboImageResponseInterface) => {
|
|
115
|
-
return `${this.configService.config.baseImageUrl}/carimage/${carId}/${image.imageIdentifier}/large`;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async getMarketingImages(carId: string, images: ImboImageResponseInterface[], ignoreDefImages: boolean): Promise<string[]> {
|
|
120
|
-
const imageUrl = this.configService.config.marketingImageUrl;
|
|
121
|
-
|
|
122
|
-
const transformedImages = this.transformImagesArrayIntoObject(images);
|
|
123
|
-
const config = await this.userService.getMarketingImageConfig(this.configService.config.marketingImageConfigId);
|
|
124
|
-
const marketingImageConfigs = config.marketingImages.map(i => ({ marketingImageCodes: i.imageCodes }));
|
|
125
|
-
|
|
126
|
-
const imageWithUrls: Partial<ImboImageResponseInterface & { url: string }>[] = [];
|
|
127
|
-
for (let i = 0; i < marketingImageConfigs.length; i++) {
|
|
128
|
-
const marketingImage = marketingImageConfigs[i];
|
|
129
|
-
for (let i = 0; i < marketingImage.marketingImageCodes.length; i++) {
|
|
130
|
-
const imageCode = marketingImage.marketingImageCodes[i];
|
|
131
|
-
const imageId = transformedImages[imageCode];
|
|
132
|
-
if (imageId) {
|
|
133
|
-
imageWithUrls.push({
|
|
134
|
-
imageCodePredicted: imageCode,
|
|
135
|
-
url: this.getImagePathWithExtension(imageUrl, carId, imageId, config)
|
|
136
|
-
});
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
this.sortImages(imageWithUrls as ImboImageResponseInterface[]);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (!ignoreDefImages && imageWithUrls.length < FB_MAX_IMAGE_COUNT_FOR_DEAFULT) {
|
|
146
|
-
imageWithUrls.map(i => i.url).push(...this.DEFAULT_IMAGES);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return imageWithUrls.map(i => i.url);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private transformImagesArrayIntoObject(images: ImboImageResponseInterface[]): { [imageCode: string]: string } {
|
|
153
|
-
return images.reduce((result, image) => {
|
|
154
|
-
const imageCode = image?.imageCodePredicted?.split('-')[0];
|
|
155
|
-
if (imageCode) {
|
|
156
|
-
result[imageCode] = image.imageIdentifier;
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}, {});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
protected getChannelPath(imageUrl: string, carId: string): string {
|
|
163
|
-
return `${imageUrl}/${[carId[0], carId[1], carId[2], carId].join('/')}`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
protected getImagePathWithExtension(imageUrl: string, carId: string, imageId: string, config: MarketingImageConfigsInterface): string {
|
|
167
|
-
const { channelCode, imageExtension } = config;
|
|
168
|
-
return `${this.getChannelPath(imageUrl, carId)}/${channelCode.replace(/ /g, '-')}-${imageId}.${imageExtension}`;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
sortImages(images: ImboImageResponseInterface[]): ImboImageResponseInterface[] {
|
|
172
|
-
return images.sort((a, b) => {
|
|
173
|
-
const imageCodePredictedA = a.imageCodePredicted.includes('-') ? a.imageCodePredicted.split('-')[0] : a.imageCodePredicted;
|
|
174
|
-
const imageCodePredictedB = b.imageCodePredicted.includes('-') ? b.imageCodePredicted.split('-')[0] : b.imageCodePredicted;
|
|
175
|
-
const orderA = this.IMAGES_SORT_ORDER[imageCodePredictedA] || 100;
|
|
176
|
-
const orderB = this.IMAGES_SORT_ORDER[imageCodePredictedB] || 100;
|
|
177
|
-
|
|
178
|
-
return orderA - orderB;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async downloadInParallel(vehicleId: string, urls: string[], config: Config): Promise<string[]> {
|
|
183
|
-
const downloadPromises = urls.map(
|
|
184
|
-
async (url: string, j: number) => await this.download(
|
|
185
|
-
url,
|
|
186
|
-
`${config.pathesConfig.localConvertedDirectory}/${vehicleId}_${(j + 1).toLocaleString('en-US', { minimumIntegerDigits: 2 })}.jpg`
|
|
187
|
-
)
|
|
188
|
-
);
|
|
189
|
-
return Promise.all(downloadPromises);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private async download(url: string, imagePath: string) {
|
|
193
|
-
return new Promise<string>(async resolve => {
|
|
194
|
-
try {
|
|
195
|
-
const response = await axios.get(url, { responseType: 'stream' });
|
|
196
|
-
response.data.pipe(
|
|
197
|
-
createWriteStream(imagePath)
|
|
198
|
-
.on('close', () => { resolve(imagePath); })
|
|
199
|
-
.on('error', (err) => { console.error(`Failed to download: ${url}; Error: ${err.message}`); resolve(null); })
|
|
200
|
-
);
|
|
201
|
-
} catch (error) {
|
|
202
|
-
console.error(`Failed to download: ${url}`);
|
|
203
|
-
resolve(null);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
}
|
|
1
|
+
import { createWriteStream } from 'fs';
|
|
2
|
+
import { extname } from 'path';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
import { Injectable } from '@nestjs/common';
|
|
6
|
+
|
|
7
|
+
import { MarketingImageConfigsInterface } from '@bytebrand/autode-request';
|
|
8
|
+
import { ImboImageResponseInterface } from '@bytebrand/chunkable';
|
|
9
|
+
import { DataSchemes } from '@bytebrand/car-schema';
|
|
10
|
+
|
|
11
|
+
import { FB_MAX_IMAGE_COUNT_FOR_DEAFULT } from '../constants/fb.constants';
|
|
12
|
+
import { ConfigService } from './config.service';
|
|
13
|
+
import { UserService } from './user.service';
|
|
14
|
+
import { isNotEmptyArray } from '../utils';
|
|
15
|
+
import { Config } from '../configs/config';
|
|
16
|
+
import { ImageType } from '../enums';
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class ImagesService {
|
|
20
|
+
private readonly IMAGES_SORT_ORDER: { [imageCode: string]: number } = {
|
|
21
|
+
ext_f_right: 1,
|
|
22
|
+
ext_f_cowl: 2,
|
|
23
|
+
ext_f_left: 3,
|
|
24
|
+
ext_l_main: 4,
|
|
25
|
+
ext_b_left: 5,
|
|
26
|
+
ext_b_main: 6,
|
|
27
|
+
ext_b_trunk: 7,
|
|
28
|
+
ext_b_right: 8,
|
|
29
|
+
ext_r_main: 9,
|
|
30
|
+
ext_f_main: 10,
|
|
31
|
+
ext_f_main_opened: 11,
|
|
32
|
+
ext_f_left_opened: 12,
|
|
33
|
+
ext_l_main_opened: 13,
|
|
34
|
+
ext_b_left_opened: 14,
|
|
35
|
+
ext_b_main_opened: 15,
|
|
36
|
+
ext_b_right_opened: 16,
|
|
37
|
+
ext_r_main_opened: 17,
|
|
38
|
+
ext_f_right_opened: 18,
|
|
39
|
+
conext_f_main: 19,
|
|
40
|
+
conext_f_left: 20,
|
|
41
|
+
conext_l_main: 21,
|
|
42
|
+
conext_b_left: 22,
|
|
43
|
+
conext_b_main: 23,
|
|
44
|
+
conext_b_right: 24,
|
|
45
|
+
conext_r_main: 25,
|
|
46
|
+
conext_f_right: 26,
|
|
47
|
+
ext_feat_engine: 27,
|
|
48
|
+
int_f_ipanel1: 28,
|
|
49
|
+
int_f_ipanel2: 29,
|
|
50
|
+
int_f_ipanel5: 30,
|
|
51
|
+
int_f_driverseats: 31,
|
|
52
|
+
int_f_assistantseats: 32,
|
|
53
|
+
int_b_rearseats: 33,
|
|
54
|
+
int_f_fandrseats: 34,
|
|
55
|
+
int_f_driverdashboard: 35,
|
|
56
|
+
int_f_doordriverside: 36,
|
|
57
|
+
int_f_stickshift: 37,
|
|
58
|
+
int_b_trunk: 38,
|
|
59
|
+
int_t_sunroof: 39,
|
|
60
|
+
int_t_panorama_sunroof: 40,
|
|
61
|
+
int_f_ipanel3: 41,
|
|
62
|
+
int_f_ipanel4: 42,
|
|
63
|
+
int_feat_seatheating: 43,
|
|
64
|
+
ext_feat_ledlights: 44,
|
|
65
|
+
ext_feat_cruisecontrol: 45,
|
|
66
|
+
int_feat_climatization: 46,
|
|
67
|
+
int_feat_bluetooth: 47,
|
|
68
|
+
ext_feat_rainsensor: 48,
|
|
69
|
+
ext_feat_rims: 49,
|
|
70
|
+
ext_feat_parkassistant: 50,
|
|
71
|
+
ext_feat_lightsensor: 51,
|
|
72
|
+
int_feat_handsfree: 52,
|
|
73
|
+
int_feat_headupdisplay: 53,
|
|
74
|
+
ext_feat_trafficsignrec: 54,
|
|
75
|
+
ext_feat_auxiliaryheating: 55,
|
|
76
|
+
ext_feat_laneassistant: 56,
|
|
77
|
+
int_feat_startstop: 57,
|
|
78
|
+
int_feat_breakassistant: 58,
|
|
79
|
+
ext_feat_nightassistant: 59,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
private readonly DEFAULT_IMAGES = [
|
|
83
|
+
'https://images.auto.de/carimage/noimage/7pNvWELuWhZX/large-cached.jpeg',
|
|
84
|
+
'https://images.auto.de/carimage/noimage/GvyXmrpaf1D6/large-cached.jpeg',
|
|
85
|
+
'https://images.auto.de/carimage/noimage/pFyfBsqBHEso/large-cached.jpeg',
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
constructor(private readonly configService: ConfigService, private readonly userService: UserService) { }
|
|
89
|
+
|
|
90
|
+
async getImages(car: DataSchemes.Car, images: ImboImageResponseInterface[], imageType: ImageType, ignoreDefImages: boolean): Promise<Array<string>> {
|
|
91
|
+
if (imageType === ImageType.default) {
|
|
92
|
+
return this.getDefaultImages(car._id, images, ignoreDefImages);
|
|
93
|
+
} else {
|
|
94
|
+
return await this.getMarketingImages(car._id, images, ignoreDefImages);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getDefaultImages(carId: string, images: ImboImageResponseInterface[], ignoreDefImages: boolean): Array<string> {
|
|
99
|
+
if (!isNotEmptyArray(images)) {
|
|
100
|
+
return this.DEFAULT_IMAGES;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const sortedImages = this.sortImages(images);
|
|
104
|
+
const transformedImages = this.generateImageLinks(sortedImages, carId);
|
|
105
|
+
|
|
106
|
+
if (!ignoreDefImages && transformedImages.length < 17) {
|
|
107
|
+
transformedImages.push(...this.DEFAULT_IMAGES);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return transformedImages;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
generateImageLinks(images: ImboImageResponseInterface[], carId: string) {
|
|
114
|
+
return images.map((image: ImboImageResponseInterface) => {
|
|
115
|
+
return `${this.configService.config.baseImageUrl}/carimage/${carId}/${image.imageIdentifier}/large`;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async getMarketingImages(carId: string, images: ImboImageResponseInterface[], ignoreDefImages: boolean): Promise<string[]> {
|
|
120
|
+
const imageUrl = this.configService.config.marketingImageUrl;
|
|
121
|
+
|
|
122
|
+
const transformedImages = this.transformImagesArrayIntoObject(images);
|
|
123
|
+
const config = await this.userService.getMarketingImageConfig(this.configService.config.marketingImageConfigId);
|
|
124
|
+
const marketingImageConfigs = config.marketingImages.map(i => ({ marketingImageCodes: i.imageCodes }));
|
|
125
|
+
|
|
126
|
+
const imageWithUrls: Partial<ImboImageResponseInterface & { url: string }>[] = [];
|
|
127
|
+
for (let i = 0; i < marketingImageConfigs.length; i++) {
|
|
128
|
+
const marketingImage = marketingImageConfigs[i];
|
|
129
|
+
for (let i = 0; i < marketingImage.marketingImageCodes.length; i++) {
|
|
130
|
+
const imageCode = marketingImage.marketingImageCodes[i];
|
|
131
|
+
const imageId = transformedImages[imageCode];
|
|
132
|
+
if (imageId) {
|
|
133
|
+
imageWithUrls.push({
|
|
134
|
+
imageCodePredicted: imageCode,
|
|
135
|
+
url: this.getImagePathWithExtension(imageUrl, carId, imageId, config)
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.sortImages(imageWithUrls as ImboImageResponseInterface[]);
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if (!ignoreDefImages && imageWithUrls.length < FB_MAX_IMAGE_COUNT_FOR_DEAFULT) {
|
|
146
|
+
imageWithUrls.map(i => i.url).push(...this.DEFAULT_IMAGES);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return imageWithUrls.map(i => i.url);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private transformImagesArrayIntoObject(images: ImboImageResponseInterface[]): { [imageCode: string]: string } {
|
|
153
|
+
return images.reduce((result, image) => {
|
|
154
|
+
const imageCode = image?.imageCodePredicted?.split('-')[0];
|
|
155
|
+
if (imageCode) {
|
|
156
|
+
result[imageCode] = image.imageIdentifier;
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}, {});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
protected getChannelPath(imageUrl: string, carId: string): string {
|
|
163
|
+
return `${imageUrl}/${[carId[0], carId[1], carId[2], carId].join('/')}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
protected getImagePathWithExtension(imageUrl: string, carId: string, imageId: string, config: MarketingImageConfigsInterface): string {
|
|
167
|
+
const { channelCode, imageExtension } = config;
|
|
168
|
+
return `${this.getChannelPath(imageUrl, carId)}/${channelCode.replace(/ /g, '-')}-${imageId}.${imageExtension}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
sortImages(images: ImboImageResponseInterface[]): ImboImageResponseInterface[] {
|
|
172
|
+
return images.sort((a, b) => {
|
|
173
|
+
const imageCodePredictedA = a.imageCodePredicted.includes('-') ? a.imageCodePredicted.split('-')[0] : a.imageCodePredicted;
|
|
174
|
+
const imageCodePredictedB = b.imageCodePredicted.includes('-') ? b.imageCodePredicted.split('-')[0] : b.imageCodePredicted;
|
|
175
|
+
const orderA = this.IMAGES_SORT_ORDER[imageCodePredictedA] || 100;
|
|
176
|
+
const orderB = this.IMAGES_SORT_ORDER[imageCodePredictedB] || 100;
|
|
177
|
+
|
|
178
|
+
return orderA - orderB;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async downloadInParallel(vehicleId: string, urls: string[], config: Config): Promise<string[]> {
|
|
183
|
+
const downloadPromises = urls.map(
|
|
184
|
+
async (url: string, j: number) => await this.download(
|
|
185
|
+
url,
|
|
186
|
+
`${config.pathesConfig.localConvertedDirectory}/${vehicleId}_${(j + 1).toLocaleString('en-US', { minimumIntegerDigits: 2 })}.jpg`
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
return Promise.all(downloadPromises);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private async download(url: string, imagePath: string) {
|
|
193
|
+
return new Promise<string>(async resolve => {
|
|
194
|
+
try {
|
|
195
|
+
const response = await axios.get(url, { responseType: 'stream' });
|
|
196
|
+
response.data.pipe(
|
|
197
|
+
createWriteStream(imagePath)
|
|
198
|
+
.on('close', () => { resolve(imagePath); })
|
|
199
|
+
.on('error', (err) => { console.error(`Failed to download: ${url}; Error: ${err.message}`); resolve(null); })
|
|
200
|
+
);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.error(`Failed to download: ${url}`);
|
|
203
|
+
resolve(null);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './transformer.service';
|
|
2
|
-
export * from './request.service';
|
|
3
|
-
export * from './mapping.service';
|
|
4
|
-
export * from './loader.service';
|
|
5
|
-
export * from './config.service';
|
|
6
|
-
export * from './images.service';
|
|
7
|
-
export * from './rules.service';
|
|
8
|
-
export * from './user.service';
|
|
9
|
-
export * from './car.service';
|
|
1
|
+
export * from './transformer.service';
|
|
2
|
+
export * from './request.service';
|
|
3
|
+
export * from './mapping.service';
|
|
4
|
+
export * from './loader.service';
|
|
5
|
+
export * from './config.service';
|
|
6
|
+
export * from './images.service';
|
|
7
|
+
export * from './rules.service';
|
|
8
|
+
export * from './user.service';
|
|
9
|
+
export * from './car.service';
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { AbstractChunkable, FsChunkInterface, Loaders } from '@bytebrand/chunkable';
|
|
3
|
-
import { ConfigService } from './config.service';
|
|
4
|
-
import { toNumber } from 'lodash';
|
|
5
|
-
import { LoggerService } from '@bytebrand/cronicle-helper';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class LoaderService {
|
|
9
|
-
constructor(private configService: ConfigService) {}
|
|
10
|
-
|
|
11
|
-
private loader: AbstractChunkable;
|
|
12
|
-
|
|
13
|
-
process(fn: (chunk: FsChunkInterface) => Promise<void>): Promise<boolean> {
|
|
14
|
-
if (!this.loader) {
|
|
15
|
-
this.loader = new Loaders.FsCarsLoader(this.configService.config);
|
|
16
|
-
}
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
this.loader.onChunk(async (chunk: FsChunkInterface) => {
|
|
19
|
-
await fn(chunk);
|
|
20
|
-
|
|
21
|
-
const progress = (toNumber(chunk.id) + 1) / chunk.total;
|
|
22
|
-
LoggerService.progress(progress < 1 ? progress : 1);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
this.loader.onError(reject);
|
|
26
|
-
return this.loader.start().then(resolve);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { AbstractChunkable, FsChunkInterface, Loaders } from '@bytebrand/chunkable';
|
|
3
|
+
import { ConfigService } from './config.service';
|
|
4
|
+
import { toNumber } from 'lodash';
|
|
5
|
+
import { LoggerService } from '@bytebrand/cronicle-helper';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class LoaderService {
|
|
9
|
+
constructor(private configService: ConfigService) {}
|
|
10
|
+
|
|
11
|
+
private loader: AbstractChunkable;
|
|
12
|
+
|
|
13
|
+
process(fn: (chunk: FsChunkInterface) => Promise<void>): Promise<boolean> {
|
|
14
|
+
if (!this.loader) {
|
|
15
|
+
this.loader = new Loaders.FsCarsLoader(this.configService.config);
|
|
16
|
+
}
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
this.loader.onChunk(async (chunk: FsChunkInterface) => {
|
|
19
|
+
await fn(chunk);
|
|
20
|
+
|
|
21
|
+
const progress = (toNumber(chunk.id) + 1) / chunk.total;
|
|
22
|
+
LoggerService.progress(progress < 1 ? progress : 1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
this.loader.onError(reject);
|
|
26
|
+
return this.loader.start().then(resolve);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|