@bytebrand/export-cars 1.0.9 → 1.0.10
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/config/as24.config.js +1 -0
- package/dist/config/as24.config.js.map +1 -1
- package/dist/config/autoboerse.config.js +1 -0
- package/dist/config/autoboerse.config.js.map +1 -1
- package/dist/config/config.d.ts +3 -0
- package/dist/config/config.js +5 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/eauto.config.js +1 -0
- package/dist/config/eauto.config.js.map +1 -1
- package/dist/config/marktde.config.js +1 -0
- package/dist/config/marktde.config.js.map +1 -1
- package/dist/config/yescar.config.js +1 -0
- package/dist/config/yescar.config.js.map +1 -1
- package/dist/export.schema.d.ts +6 -0
- package/dist/export.schema.js +6 -0
- package/dist/export.schema.js.map +1 -1
- package/dist/exporters/as24.exporter.js +13 -0
- package/dist/exporters/as24.exporter.js.map +1 -1
- package/dist/exporters/mobile.exporter.js +3 -4
- package/dist/exporters/mobile.exporter.js.map +1 -1
- package/dist/interfaces/params.interface.d.ts +1 -0
- package/dist/main.js.map +1 -1
- package/dist/services/mapping.service.d.ts +4 -3
- package/dist/services/mapping.service.js +23 -14
- package/dist/services/mapping.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/config/as24.config.ts +1 -0
- package/src/config/autoboerse.config.ts +1 -0
- package/src/config/config.ts +5 -0
- package/src/config/eauto.config.ts +1 -0
- package/src/config/marktde.config.ts +1 -0
- package/src/config/yescar.config.ts +1 -0
- package/src/export.schema.ts +6 -0
- package/src/exporters/as24.exporter.ts +17 -13
- package/src/exporters/mobile.exporter.ts +3 -4
- package/src/interfaces/params.interface.ts +1 -0
- package/src/main.ts +6 -1
- package/src/services/mapping.service.ts +25 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebrand/export-cars",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "bytebrand",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=14.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "76f936636e6e646ed55feb87f618d492d1cad69a"
|
|
68
68
|
}
|
|
@@ -8,5 +8,6 @@ export class AutoboerseConfig extends Config {
|
|
|
8
8
|
this.pathesConfig.localConvertedDirectory = 'resources/autoboerse-export';
|
|
9
9
|
this.imageUrl = `https://images.${this.url}/carimage`;
|
|
10
10
|
this.downloadImages = true;
|
|
11
|
+
this.mappingSpreadsheetTitle = 'mobile_yescar';
|
|
11
12
|
}
|
|
12
13
|
}
|
package/src/config/config.ts
CHANGED
|
@@ -32,6 +32,9 @@ export class Config {
|
|
|
32
32
|
cpc: string;
|
|
33
33
|
ownerId: string;
|
|
34
34
|
downloadImages: boolean;
|
|
35
|
+
googleSheetsApiKey: string;
|
|
36
|
+
mappingSpreadsheetId: string;
|
|
37
|
+
mappingSpreadsheetTitle: string;
|
|
35
38
|
|
|
36
39
|
protected environmentConfig = {
|
|
37
40
|
[Environment.LOCAL]: {
|
|
@@ -68,6 +71,8 @@ export class Config {
|
|
|
68
71
|
this.fileName = params.fileName || `${params.environment}_${params.exportType}`;
|
|
69
72
|
this.criteoId = this.environmentConfig[params.environment].criteoId;
|
|
70
73
|
this.url = this.environmentConfig[params.environment].url;
|
|
74
|
+
this.googleSheetsApiKey = params.googleSheetsApiKey;
|
|
75
|
+
this.mappingSpreadsheetId = '147qz9sTgs1wi13ua8YKa0IgfxAn1X_qH6LkGnAnzeyY';
|
|
71
76
|
this.userActionsUrl = `https://www.${this.url}/service/user-actions`;
|
|
72
77
|
this.imboUrl = `https://www.${this.url}/service/image-imbo`;
|
|
73
78
|
this.imageUrl = `https://images.${this.url}`;
|
package/src/export.schema.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { As24Config } from './config/as24.config';
|
|
1
2
|
import { Auto24Config } from './config/auto24.config';
|
|
2
3
|
import { AutoboerseConfig } from './config/autoboerse.config';
|
|
3
4
|
import { AutouncleConfig } from './config/autouncle.config';
|
|
@@ -10,6 +11,7 @@ import { MeinstadtConfig } from './config/meinstadt.config';
|
|
|
10
11
|
import { OoyyoConfig } from './config/ooyyo.config';
|
|
11
12
|
import { YescarConfig } from './config/yescar.config';
|
|
12
13
|
import { ExportType } from './enums/export-type.enum';
|
|
14
|
+
import { As24Exporter } from './exporters/as24.exporter';
|
|
13
15
|
import { Auto24Exporter } from './exporters/auto24.exporter';
|
|
14
16
|
import { AutouncleExporter } from './exporters/autouncle.exporter';
|
|
15
17
|
import { ByOwnerExporter } from './exporters/by-owner.exporter';
|
|
@@ -64,4 +66,8 @@ export const exportSchema = {
|
|
|
64
66
|
config: AutouncleConfig,
|
|
65
67
|
exporter: AutouncleExporter,
|
|
66
68
|
},
|
|
69
|
+
[ExportType.AS24]: {
|
|
70
|
+
config: As24Config,
|
|
71
|
+
exporter: As24Exporter,
|
|
72
|
+
},
|
|
67
73
|
};
|
|
@@ -7,9 +7,11 @@ import { Injectable } from '@nestjs/common';
|
|
|
7
7
|
import { ModuleRef } from '@nestjs/core';
|
|
8
8
|
import { As24Transformer } from '../transformers/as24.transformer';
|
|
9
9
|
import { UserService } from '../services/user.service';
|
|
10
|
-
import { get } from 'lodash';
|
|
10
|
+
import { get, union } from 'lodash';
|
|
11
11
|
import { convertToCSV } from '../utils/converter.utils';
|
|
12
12
|
import { writeFile } from 'fs/promises';
|
|
13
|
+
import { normalize } from 'path';
|
|
14
|
+
import { Zipper } from '@bytebrand/zipper';
|
|
13
15
|
|
|
14
16
|
@Injectable()
|
|
15
17
|
export class As24Exporter implements Exporter {
|
|
@@ -31,6 +33,8 @@ export class As24Exporter implements Exporter {
|
|
|
31
33
|
descriptionSchemas[dealerId] = await this.userService.getDefaultSummaryByDealerId(dealerId);
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
const processedDealers = [];
|
|
37
|
+
|
|
34
38
|
await this.loaderService.process(async (chunk: FsChunkInterface) => {
|
|
35
39
|
if (chunk && chunk.data) {
|
|
36
40
|
for (let i = 0; i < chunk.data.length; i += 1) {
|
|
@@ -43,28 +47,28 @@ export class As24Exporter implements Exporter {
|
|
|
43
47
|
) {
|
|
44
48
|
const transformedData = await as24Transformer.transform(data.car, descriptionSchemas);
|
|
45
49
|
const transformedDataCSV = `${convertToCSV(transformedData)}\n`;
|
|
50
|
+
|
|
46
51
|
await writeFile(
|
|
47
52
|
`${this.configService.config.pathesConfig.localConvertedDirectory}/${ownerId}.csv`,
|
|
48
53
|
Buffer.from(transformedDataCSV),
|
|
49
54
|
{ flag: 'a' },
|
|
50
55
|
);
|
|
56
|
+
|
|
57
|
+
union([ownerId], processedDealers);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
chunk.data = null;
|
|
54
61
|
}
|
|
55
62
|
});
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// if (await CronicleUtils.exists(fileCSV)) {
|
|
67
|
-
// await Zipper.zip({ fileList: [fileCSV], dest: fileZIP });
|
|
68
|
-
// }
|
|
64
|
+
for (const dealer of processedDealers) {
|
|
65
|
+
const now = new Date();
|
|
66
|
+
const d = `${now.getFullYear()}${now.getMonth() + 1}${now.getDate()}`;
|
|
67
|
+
const fileCSV = normalize(`${this.configService.config.pathesConfig.localConvertedDirectory}/${dealer}.csv`);
|
|
68
|
+
const fileZIP = normalize(`${this.configService.config.pathesConfig.localConvertedDirectory}/${d}_${dealer}.zip`);
|
|
69
|
+
if (await CronicleUtils.exists(fileCSV)) {
|
|
70
|
+
await Zipper.zip({ fileList: [fileCSV], dest: fileZIP });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -16,6 +16,7 @@ import { lastValueFrom } from 'rxjs';
|
|
|
16
16
|
import { createWriteStream } from 'fs';
|
|
17
17
|
import { get } from 'lodash';
|
|
18
18
|
import { RulesService } from '../services/rules.service';
|
|
19
|
+
import { pipeline } from 'stream/promises';
|
|
19
20
|
|
|
20
21
|
@Injectable()
|
|
21
22
|
export class MobileExporter implements Exporter {
|
|
@@ -93,7 +94,7 @@ export class MobileExporter implements Exporter {
|
|
|
93
94
|
responseType: 'stream',
|
|
94
95
|
}),
|
|
95
96
|
)
|
|
96
|
-
.then(
|
|
97
|
+
.then(({ data }) => {
|
|
97
98
|
const writer = createWriteStream(
|
|
98
99
|
join(
|
|
99
100
|
this.configService.config.pathesConfig.localConvertedDirectory,
|
|
@@ -101,9 +102,7 @@ export class MobileExporter implements Exporter {
|
|
|
101
102
|
`${vehicleId}_${index + 1}${extname(imageUrl) || '.jpg'}`,
|
|
102
103
|
),
|
|
103
104
|
);
|
|
104
|
-
|
|
105
|
-
writer.on('finish', resolve);
|
|
106
|
-
writer.on('error', reject);
|
|
105
|
+
pipeline(data, writer).then(resolve).catch(reject);
|
|
107
106
|
})
|
|
108
107
|
.catch(reject);
|
|
109
108
|
});
|
package/src/main.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { CommandFactory } from 'nest-commander';
|
|
|
3
3
|
import { AppModule } from './app.module';
|
|
4
4
|
|
|
5
5
|
async function bootstrap() {
|
|
6
|
+
// setInterval(() => {
|
|
7
|
+
// Object.entries(process.memoryUsage()).forEach(item =>
|
|
8
|
+
// console.log(`${item[0]}: ${(item[1] / 1024 / 1024).toFixed(4)} MB`),
|
|
9
|
+
// );
|
|
10
|
+
// console.log('\n');
|
|
11
|
+
// }, 10000);
|
|
6
12
|
try {
|
|
7
13
|
await CommandFactory.run(AppModule, console);
|
|
8
14
|
LoggerService.complete();
|
|
@@ -10,5 +16,4 @@ async function bootstrap() {
|
|
|
10
16
|
LoggerService.exitError(e.message || e);
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
|
-
|
|
14
19
|
bootstrap();
|
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { CronicleUtils } from '@bytebrand/cronicle-helper';
|
|
3
2
|
import { MappingRules } from '../interfaces/mapping-rules.interface';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { GoogleSpreadsheet, GoogleSpreadsheetRow } from 'google-spreadsheet';
|
|
4
|
+
import { ConfigService } from './config.service';
|
|
6
5
|
|
|
7
6
|
@Injectable()
|
|
8
7
|
export class MappingService {
|
|
9
|
-
constructor(private
|
|
8
|
+
constructor(private configService: ConfigService) {}
|
|
10
9
|
private rules: MappingRules[];
|
|
11
10
|
|
|
12
11
|
async getRules(): Promise<MappingRules[]> {
|
|
13
12
|
if (!this.rules) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
const rows: MappingRules[] = await CronicleUtils.parseCSV(data);
|
|
13
|
+
const spreadsheet = new GoogleSpreadsheet(this.configService.config.mappingSpreadsheetId);
|
|
14
|
+
spreadsheet.useApiKey(this.configService.config.googleSheetsApiKey);
|
|
15
|
+
await spreadsheet.loadInfo();
|
|
16
|
+
const rows = await spreadsheet.sheetsByTitle[this.configService.config.mappingSpreadsheetTitle].getRows();
|
|
17
|
+
const mappingRules = this.rowsToRules(rows);
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
this.removeEmptyKeys(
|
|
23
|
-
if (
|
|
24
|
-
this.groupSelectors(
|
|
19
|
+
mappingRules.map((rule, _i, selfRules) => {
|
|
20
|
+
this.removeEmptyKeys(rule);
|
|
21
|
+
if (rule.importFieldType && rule.importFieldType.includes('selector')) {
|
|
22
|
+
this.groupSelectors(rule, selfRules);
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
this.rules = this.filterResultedRows(
|
|
26
|
+
this.rules = this.filterResultedRows(mappingRules);
|
|
29
27
|
}
|
|
30
28
|
return this.rules;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
private rowsToRules(rows: GoogleSpreadsheetRow[]): MappingRules[] {
|
|
32
|
+
return rows.map(row =>
|
|
33
|
+
Object.assign(
|
|
34
|
+
{},
|
|
35
|
+
...Object.entries(Object.getOwnPropertyDescriptors(row))
|
|
36
|
+
.filter(([_key, descriptor]) => typeof descriptor.get === 'function')
|
|
37
|
+
.map(([key, descriptor]) => ({
|
|
38
|
+
[key]: descriptor.get() || '',
|
|
39
|
+
})),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
45
43
|
|
|
46
44
|
private filterResultedRows(rows: MappingRules[]): MappingRules[] {
|
|
47
45
|
return rows.filter((value, idx, self) => {
|