@haus-tech/product-import-export-plugin 3.0.8 → 3.0.9

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.
@@ -56,105 +56,79 @@ let ExtendedAssetImporter = class ExtendedAssetImporter {
56
56
  const errors = [];
57
57
  const uniqueAssetPaths = new Set(assetPaths);
58
58
  for (const assetPath of uniqueAssetPaths.values()) {
59
- const cachedAsset = this.assetMap.get(assetPath.url);
60
- if (cachedAsset) {
61
- if (ctx?.channelId &&
62
- cachedAsset.channels.some((channel) => channel.id !== ctx?.channelId)) {
63
- await this.connection
64
- .getRepository(ctx, core_1.Asset)
65
- .createQueryBuilder()
66
- .relation(core_1.Asset, 'channels')
67
- .of(cachedAsset.id)
68
- .add(ctx?.channel);
69
- cachedAsset.channels.push(ctx?.channel);
70
- }
71
- if (cachedAsset.name !== assetPath.name && assetPath.name) {
72
- this.connection.getRepository(ctx, core_1.Asset).update(cachedAsset.id, {
73
- name: assetPath.name,
74
- });
75
- // Update the cached asset with the new name
76
- this.assetMap.set(assetPath.url, { ...cachedAsset, name: assetPath.name });
77
- assets.push({ ...cachedAsset, name: assetPath.name });
78
- }
79
- else {
80
- assets.push(cachedAsset);
81
- }
82
- }
83
- else {
84
- try {
85
- const assetHash = (0, generate_asset_hash_1.generateAssetHash)({
86
- source: assetPath.url,
87
- });
88
- const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
89
- where: {
90
- customFields: {
91
- hash: assetHash,
92
- },
59
+ try {
60
+ const assetHash = (0, generate_asset_hash_1.generateAssetHash)({
61
+ source: assetPath.url,
62
+ });
63
+ const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
64
+ where: {
65
+ customFields: {
66
+ hash: assetHash,
93
67
  },
94
- relations: ['channels'],
95
- });
96
- if (assetFromHash) {
97
- // Check if the asset name has changed
98
- if ((assetPath.name && assetFromHash.name !== assetPath.name) ||
99
- assetFromHash.channels.some((channel) => channel.id !== ctx?.channelId)) {
100
- assetFromHash.name = assetPath.name || assetFromHash.name;
101
- assetFromHash.channels.push(ctx?.channel);
102
- await this.connection.getRepository(ctx, core_1.Asset).save(assetFromHash);
103
- }
104
- this.assetMap.set(assetPath.url, assetFromHash);
105
- assets.push(assetFromHash);
106
- continue;
68
+ },
69
+ relations: ['channels'],
70
+ });
71
+ if (assetFromHash) {
72
+ // Check if the asset name has changed
73
+ if ((assetPath.name && assetFromHash.name !== assetPath.name) ||
74
+ assetFromHash.channels.some((channel) => channel.id !== ctx?.channelId)) {
75
+ assetFromHash.name = assetPath.name || assetFromHash.name;
76
+ assetFromHash.channels.push(ctx?.channel);
77
+ await this.connection.getRepository(ctx, core_1.Asset).save(assetFromHash);
107
78
  }
108
- const stream = await this.getStreamFromPath(assetPath.url);
109
- if (stream) {
110
- const createdAsset = await this.assetService.createFromFileStream(stream, assetPath.url, ctx);
111
- if ((0, core_1.isGraphQlErrorResult)(createdAsset)) {
112
- errors.push(createdAsset.message);
113
- }
114
- else {
115
- let assetToUpdate = createdAsset;
116
- let shouldDeleteCreatedAsset = false;
117
- const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
118
- where: {
119
- customFields: {
120
- hash: assetHash,
121
- },
79
+ this.assetMap.set(assetPath.url, assetFromHash);
80
+ assets.push(assetFromHash);
81
+ continue;
82
+ }
83
+ const stream = await this.getStreamFromPath(assetPath.url);
84
+ if (stream) {
85
+ const createdAsset = await this.assetService.createFromFileStream(stream, assetPath.url, ctx);
86
+ if ((0, core_1.isGraphQlErrorResult)(createdAsset)) {
87
+ errors.push(createdAsset.message);
88
+ }
89
+ else {
90
+ let assetToUpdate = createdAsset;
91
+ let shouldDeleteCreatedAsset = false;
92
+ const assetFromHash = await this.connection.getRepository(ctx, core_1.Asset).findOne({
93
+ where: {
94
+ customFields: {
95
+ hash: assetHash,
122
96
  },
123
- relations: ['channels'],
124
- });
125
- if (assetFromHash) {
126
- shouldDeleteCreatedAsset = true;
127
- assetToUpdate = { ...assetFromHash, name: assetPath.name || assetFromHash.name };
128
- }
129
- if (assetPath.id) {
130
- shouldDeleteCreatedAsset = true;
131
- assetToUpdate = {
132
- ...assetToUpdate,
133
- id: assetPath.id,
134
- };
135
- }
136
- this.assetMap.set(assetPath.url, assetToUpdate);
137
- assets.push(assetToUpdate);
138
- assetToUpdate.name = assetPath.name || assetToUpdate.name;
139
- assetToUpdate.channels.push(ctx?.channel);
140
- assetToUpdate.customFields = {
141
- ...assetToUpdate.customFields,
142
- hash: assetHash,
97
+ },
98
+ relations: ['channels'],
99
+ });
100
+ if (assetFromHash) {
101
+ shouldDeleteCreatedAsset = true;
102
+ assetToUpdate = { ...assetFromHash, name: assetPath.name || assetFromHash.name };
103
+ }
104
+ if (assetPath.id) {
105
+ shouldDeleteCreatedAsset = true;
106
+ assetToUpdate = {
107
+ ...assetToUpdate,
108
+ id: assetPath.id,
143
109
  };
144
- await this.connection.getRepository(ctx, core_1.Asset).save(assetToUpdate);
145
- if (shouldDeleteCreatedAsset) {
146
- this.connection.getRepository(ctx, core_1.Asset).delete(createdAsset.id);
147
- }
110
+ }
111
+ this.assetMap.set(assetPath.url, assetToUpdate);
112
+ assets.push(assetToUpdate);
113
+ assetToUpdate.name = assetPath.name || assetToUpdate.name;
114
+ assetToUpdate.channels.push(ctx?.channel);
115
+ assetToUpdate.customFields = {
116
+ ...assetToUpdate.customFields,
117
+ hash: assetHash,
118
+ };
119
+ await this.connection.getRepository(ctx, core_1.Asset).save(assetToUpdate);
120
+ if (shouldDeleteCreatedAsset) {
121
+ this.connection.getRepository(ctx, core_1.Asset).delete(createdAsset.id);
148
122
  }
149
123
  }
150
124
  }
151
- catch (e) {
152
- if (e.message.includes('no elements in sequence')) {
153
- errors.push(`Could not find asset at path "${assetPath.url}"`);
154
- }
155
- else {
156
- errors.push(e.message);
157
- }
125
+ }
126
+ catch (e) {
127
+ if (e.message.includes('no elements in sequence')) {
128
+ errors.push(`Could not find asset at path "${assetPath.url}"`);
129
+ }
130
+ else {
131
+ errors.push(e.message);
158
132
  }
159
133
  }
160
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/product-import-export-plugin",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "A Vendure plugin for importing and exporting products using a CSV file",
5
5
  "author": "Haus Tech",
6
6
  "repository": {