@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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
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
|
}
|