@bytebrand/export-cars 1.21.0 → 1.21.1

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.0",
3
+ "version": "1.21.1",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14.0.0"
64
64
  },
65
- "gitHead": "3ef72636ca23cee78df87f16e66089e1a532b053"
65
+ "gitHead": "ea5d40b0c028d75455818e481f87d74bd18f820c"
66
66
  }
@@ -44,7 +44,7 @@ export class MobileExporter implements Exporter {
44
44
 
45
45
  if (this.configService.config.downloadImage) {
46
46
  const urls = await this.imageService.getImages(car, images, this.configService.config.imageType, true);
47
- imagesPath.push(...await this.imageService.downloadInParallel(car.metaData.vehicleId, urls, this.configService.config, 10));
47
+ imagesPath.push(...await this.imageService.downloadInParallel(car.metaData.vehicleId, urls, this.configService.config));
48
48
  }
49
49
 
50
50
  await writeFile(fileName, Buffer.from(`${convertToCSV(transformedData)}\n`), { flag: 'a' });
@@ -173,17 +173,14 @@ export class ImagesService {
173
173
  });
174
174
  }
175
175
 
176
- async downloadInParallel(vehicleId: string, urls: string[], config: Config, concurrency = 1): Promise<string[]> {
177
- for (let i = 0; i < urls.length; i += concurrency) {
178
- const downloadPromises = urls.map(
179
- (url: string, j: number) => this.download(
180
- url,
181
- `${config.pathesConfig.localConvertedDirectory}/${vehicleId}_${(i + 1).toLocaleString('en-US', { minimumIntegerDigits: 2 })}.jpeg`
182
- )
183
- );
184
- return Promise.all(downloadPromises);
185
- }
186
- return [];
176
+ async downloadInParallel(vehicleId: string, urls: string[], config: Config): Promise<string[]> {
177
+ const downloadPromises = urls.map(
178
+ async (url: string, j: number) => await this.download(
179
+ url,
180
+ `${config.pathesConfig.localConvertedDirectory}/${vehicleId}_${(j + 1).toLocaleString('en-US', { minimumIntegerDigits: 2 })}.jpg`
181
+ )
182
+ );
183
+ return Promise.all(downloadPromises);
187
184
  }
188
185
 
189
186
  private async download(url: string, imagePath: string) {
@@ -192,7 +189,7 @@ export class ImagesService {
192
189
  const response = await axios.get(url, { responseType: 'stream' });
193
190
  response.data.pipe(
194
191
  createWriteStream(imagePath)
195
- .on('finish', () => { console.log(`Downloaded: ${url}`); resolve(imagePath); })
192
+ .on('close', () => { console.log(`Downloaded: ${url}`, imagePath); resolve(imagePath); })
196
193
  .on('error', (err) => { console.error(`Failed to download: ${url}`); resolve(null); })
197
194
  );
198
195
  } catch (error) {