@contrail/flexplm 1.3.0 → 1.3.1-alpha.eae3d9f
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/.github/workflows/flexplm-lib.yml +1 -1
- package/.github/workflows/publish-to-npm.yml +35 -38
- package/lib/entity-processor/base-entity-processor.d.ts +42 -42
- package/lib/entity-processor/base-entity-processor.js +385 -385
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
- package/lib/entity-processor/base-entity-processor.spec.js +397 -397
- package/lib/flexplm-request.d.ts +3 -3
- package/lib/flexplm-request.js +34 -34
- package/lib/flexplm-utils.d.ts +5 -5
- package/lib/flexplm-utils.js +33 -33
- package/lib/flexplm-utils.spec.d.ts +1 -1
- package/lib/flexplm-utils.spec.js +26 -26
- package/lib/index.d.ts +22 -22
- package/lib/index.js +38 -38
- package/lib/interfaces/interfaces.d.ts +105 -105
- package/lib/interfaces/interfaces.js +2 -2
- package/lib/interfaces/item-family-changes.d.ts +20 -20
- package/lib/interfaces/item-family-changes.js +56 -56
- package/lib/interfaces/publish-change-data.d.ts +19 -19
- package/lib/interfaces/publish-change-data.js +32 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
- package/lib/publish/base-process-publish-assortment-callback.js +38 -38
- package/lib/publish/base-process-publish-assortment.d.ts +93 -93
- package/lib/publish/base-process-publish-assortment.js +944 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
- package/lib/publish/mockData.d.ts +1389 -1389
- package/lib/publish/mockData.js +4519 -4519
- package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
- package/lib/transform/identifier-conversion.d.ts +15 -15
- package/lib/transform/identifier-conversion.js +212 -212
- package/lib/transform/identifier-conversion.spec.d.ts +1 -1
- package/lib/transform/identifier-conversion.spec.js +339 -339
- package/lib/util/config-defaults.d.ts +8 -8
- package/lib/util/config-defaults.js +85 -85
- package/lib/util/config-defaults.spec.d.ts +1 -1
- package/lib/util/config-defaults.spec.js +293 -293
- package/lib/util/data-converter-spec-mockData.js +205 -205
- package/lib/util/data-converter.d.ts +39 -39
- package/lib/util/data-converter.js +592 -592
- package/lib/util/data-converter.spec.d.ts +1 -1
- package/lib/util/data-converter.spec.js +904 -904
- package/lib/util/error-response-object.d.ts +4 -4
- package/lib/util/error-response-object.js +47 -47
- package/lib/util/error-response-object.spec.d.ts +1 -1
- package/lib/util/error-response-object.spec.js +99 -99
- package/lib/util/event-short-message-status.d.ts +19 -19
- package/lib/util/event-short-message-status.js +23 -23
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +149 -149
- package/lib/util/flexplm-connect.d.ts +22 -22
- package/lib/util/flexplm-connect.js +176 -176
- package/lib/util/flexplm-connect.spec.d.ts +1 -1
- package/lib/util/flexplm-connect.spec.js +88 -88
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +26 -26
- package/lib/util/map-util-spec-mockData.js +205 -205
- package/lib/util/map-utils.d.ts +6 -6
- package/lib/util/map-utils.js +15 -15
- package/lib/util/map-utils.spec.d.ts +1 -1
- package/lib/util/map-utils.spec.js +89 -89
- package/lib/util/mockData.d.ts +80 -80
- package/lib/util/mockData.js +103 -103
- package/lib/util/thumbnail-util.d.ts +34 -34
- package/lib/util/thumbnail-util.js +215 -215
- package/lib/util/thumbnail-util.spec.d.ts +1 -1
- package/lib/util/thumbnail-util.spec.js +434 -434
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
- package/lib/util/type-conversion-utils.d.ts +23 -23
- package/lib/util/type-conversion-utils.js +265 -265
- package/lib/util/type-conversion-utils.spec.d.ts +1 -1
- package/lib/util/type-conversion-utils.spec.js +868 -868
- package/lib/util/type-defaults.d.ts +16 -16
- package/lib/util/type-defaults.js +221 -221
- package/lib/util/type-defaults.spec.d.ts +1 -1
- package/lib/util/type-defaults.spec.js +516 -516
- package/lib/util/type-utils.d.ts +13 -13
- package/lib/util/type-utils.js +114 -114
- package/lib/util/type-utils.spec.d.ts +1 -1
- package/lib/util/type-utils.spec.js +190 -190
- package/package.json +1 -1
- package/publish.sh +0 -0
- package/tsconfig.json +1 -6
- package/.claude/settings.local.json +0 -8
|
@@ -1,215 +1,215 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThumbnailUtil = void 0;
|
|
4
|
-
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
-
const sdk_1 = require("@contrail/sdk");
|
|
6
|
-
const flexplm_connect_1 = require("./flexplm-connect");
|
|
7
|
-
;
|
|
8
|
-
class ThumbnailUtil {
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.max_thumbnail_size = 5 * 1024 * 1024;
|
|
12
|
-
this.entities = new sdk_1.Entities();
|
|
13
|
-
if (this.config['max_thumbnail_size']) {
|
|
14
|
-
this.max_thumbnail_size = this.config['max_thumbnail_size'];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async setOutboundThumbnail(data, event) {
|
|
18
|
-
if (event?.newData?.primaryViewableId && event?.newData?.largeViewableDownloadUrl) {
|
|
19
|
-
const primaryViewableId = event.newData.primaryViewableId;
|
|
20
|
-
const fileId = await this.getFileId(primaryViewableId);
|
|
21
|
-
if (fileId) {
|
|
22
|
-
const customSizes = await this.getCustomSizes();
|
|
23
|
-
const key = (this.isThumbnailNew(event, customSizes))
|
|
24
|
-
? ThumbnailUtil.NEW_THUMBNAIL_ID
|
|
25
|
-
: ThumbnailUtil.EXISTING_THUMBNAIL_ID;
|
|
26
|
-
data[key] = fileId;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (event?.propertyDiffs?.largeViewableDownloadUrl?.oldValue && !event?.propertyDiffs?.largeViewableDownloadUrl?.newValue) {
|
|
30
|
-
data[ThumbnailUtil.NEW_THUMBNAIL_ID] = ThumbnailUtil.REMOVE_THUMBNAIL;
|
|
31
|
-
}
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
isThumbnailNew(event, customSizes) {
|
|
35
|
-
const propertyDiffs = event?.propertyDiffs;
|
|
36
|
-
if (propertyDiffs) {
|
|
37
|
-
const diffKeys = Object.keys(propertyDiffs);
|
|
38
|
-
const sizeKeys = ThumbnailUtil.OOB_SIZES.map(s => s.slug + 'DownloadUrl');
|
|
39
|
-
if (customSizes) {
|
|
40
|
-
sizeKeys.push(...customSizes.map(s => s.slug + 'Url'));
|
|
41
|
-
}
|
|
42
|
-
sizeKeys.push('primaryFileUrl');
|
|
43
|
-
console.info('diffKeys: ' + JSON.stringify(diffKeys));
|
|
44
|
-
console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
|
|
45
|
-
return diffKeys.some(s => sizeKeys.includes(s));
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
async getFileId(primaryViewableId) {
|
|
50
|
-
console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
|
|
51
|
-
const sizes = await this.getCustomSizes();
|
|
52
|
-
const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
|
|
53
|
-
sizes.push(...OOBSizes);
|
|
54
|
-
console.info('sizes: ' + JSON.stringify(sizes));
|
|
55
|
-
const content = await this.getContentEntity(primaryViewableId, sizes);
|
|
56
|
-
if (!content) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
const contentKeys = Object.getOwnPropertyNames(content);
|
|
60
|
-
const isDebugOn = app_framework_1.Logger.isDebugOn();
|
|
61
|
-
let fileId = undefined;
|
|
62
|
-
let tempFileSize = 0;
|
|
63
|
-
for (const size of sizes) {
|
|
64
|
-
const slug = size?.slug;
|
|
65
|
-
if (contentKeys.includes(slug)) {
|
|
66
|
-
const file = content[slug];
|
|
67
|
-
if (isDebugOn) {
|
|
68
|
-
console.debug('size: ' + slug);
|
|
69
|
-
console.debug('fileId: ' + file['id']);
|
|
70
|
-
}
|
|
71
|
-
if (file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
|
|
72
|
-
tempFileSize = file['size'];
|
|
73
|
-
fileId = file['id'];
|
|
74
|
-
if (isDebugOn) {
|
|
75
|
-
console.debug('fileId: ' + fileId);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
|
|
81
|
-
return fileId;
|
|
82
|
-
}
|
|
83
|
-
async getCustomSizes() {
|
|
84
|
-
const customSizes = await this.entities.get({
|
|
85
|
-
entityName: 'content-custom-size'
|
|
86
|
-
});
|
|
87
|
-
const sizes = [];
|
|
88
|
-
sizes.push(...customSizes);
|
|
89
|
-
return sizes;
|
|
90
|
-
}
|
|
91
|
-
async getContentEntity(primaryViewableId, sizes) {
|
|
92
|
-
const relations = sizes.map(s => s.slug);
|
|
93
|
-
relations.push('primaryFile');
|
|
94
|
-
const content = await this.entities.get({
|
|
95
|
-
entityName: 'content',
|
|
96
|
-
id: primaryViewableId,
|
|
97
|
-
relations
|
|
98
|
-
});
|
|
99
|
-
this.logContentResults(content, relations);
|
|
100
|
-
return content;
|
|
101
|
-
}
|
|
102
|
-
logContentResults(content, relations) {
|
|
103
|
-
if (app_framework_1.Logger.isDebugOn() && content && relations) {
|
|
104
|
-
const contentCopy = JSON.parse(JSON.stringify(content));
|
|
105
|
-
relations.forEach(r => {
|
|
106
|
-
delete contentCopy[r];
|
|
107
|
-
});
|
|
108
|
-
console.debug('content: ' + JSON.stringify(contentCopy));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async syncThumbnailToVibeIQ({ entityId, primaryViewableId, event, entityName }) {
|
|
112
|
-
console.debug(`syncThumbnailToVibeIQ: entityId=${entityId}, primaryViewableId=${primaryViewableId}, entityName=${entityName}`);
|
|
113
|
-
const eventData = event.data || {};
|
|
114
|
-
const newThumbnailId = eventData[ThumbnailUtil.NEW_THUMBNAIL_ID];
|
|
115
|
-
const existingThumbnailId = eventData[ThumbnailUtil.EXISTING_THUMBNAIL_ID];
|
|
116
|
-
const thumbnailUrl = newThumbnailId || existingThumbnailId;
|
|
117
|
-
if (newThumbnailId === ThumbnailUtil.REMOVE_THUMBNAIL) {
|
|
118
|
-
if (primaryViewableId) {
|
|
119
|
-
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
120
|
-
}
|
|
121
|
-
const clearUpdates = await this.getClearPrimaryViewableUpdates();
|
|
122
|
-
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: clearUpdates });
|
|
123
|
-
console.debug(`syncThumbnailToVibeIQ: applied clear updates for entityId=${entityId}`);
|
|
124
|
-
return updatedEntity;
|
|
125
|
-
}
|
|
126
|
-
if (!thumbnailUrl) {
|
|
127
|
-
console.debug(`syncThumbnailToVibeIQ: no thumbnail URL for entityId=${entityId}`);
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
if (!primaryViewableId) {
|
|
131
|
-
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
132
|
-
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
133
|
-
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
134
|
-
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
135
|
-
console.debug(`syncThumbnailToVibeIQ: created new content ${content.id} for entityId=${entityId}`);
|
|
136
|
-
return updatedEntity;
|
|
137
|
-
}
|
|
138
|
-
const primaryViewable = await this.entities.get({ entityName: 'content', id: primaryViewableId });
|
|
139
|
-
if (primaryViewable?.flexplmThumbnailUrl === thumbnailUrl) {
|
|
140
|
-
console.debug(`syncThumbnailToVibeIQ: thumbnail already synced for entityId=${entityId}`);
|
|
141
|
-
return undefined;
|
|
142
|
-
}
|
|
143
|
-
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
144
|
-
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
145
|
-
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
146
|
-
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
147
|
-
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
148
|
-
console.debug(`syncThumbnailToVibeIQ: replaced content ${primaryViewableId} with ${content.id} for entityId=${entityId}`);
|
|
149
|
-
return updatedEntity;
|
|
150
|
-
}
|
|
151
|
-
async createContentFromFlexPLM(thumbnailUrl, entityId, entityName) {
|
|
152
|
-
const urlParts = thumbnailUrl.split('/');
|
|
153
|
-
const fileName = urlParts[urlParts.length - 1] || 'thumbnail';
|
|
154
|
-
const encodedUrl = urlParts.map(part => encodeURIComponent(part)).join('/');
|
|
155
|
-
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
156
|
-
const response = await flexPLMConnect.getRequest({
|
|
157
|
-
urlPath: encodedUrl,
|
|
158
|
-
includeUrlContext: false,
|
|
159
|
-
returnFullResponse: true,
|
|
160
|
-
});
|
|
161
|
-
const fileBuffer = await response.arrayBuffer();
|
|
162
|
-
const buffer = Buffer.from(fileBuffer);
|
|
163
|
-
const contentTypeHeader = response.headers.get('content-type');
|
|
164
|
-
const contentType = contentTypeHeader ? contentTypeHeader.split(';')[0] : 'application/octet-stream';
|
|
165
|
-
const contentHolderReference = `${entityName}:${entityId}`;
|
|
166
|
-
const content = await new sdk_1.Content().create({
|
|
167
|
-
fileBuffer: buffer,
|
|
168
|
-
fileName,
|
|
169
|
-
contentType,
|
|
170
|
-
contentHolderReference,
|
|
171
|
-
});
|
|
172
|
-
return content;
|
|
173
|
-
}
|
|
174
|
-
async getPrimaryViewableUpdates(content) {
|
|
175
|
-
const updates = {
|
|
176
|
-
primaryViewableId: content.id,
|
|
177
|
-
contentType: content.contentType,
|
|
178
|
-
fileName: content.fileName,
|
|
179
|
-
primaryFileUrl: content.primaryFileUrl,
|
|
180
|
-
largeViewableDownloadUrl: content.largeViewableUrl || content.primaryFileUrl,
|
|
181
|
-
mediumLargeViewableDownloadUrl: content.mediumLargeViewableUrl || content.primaryFileUrl,
|
|
182
|
-
mediumViewableDownloadUrl: content.mediumViewableUrl || content.primaryFileUrl,
|
|
183
|
-
smallViewableDownloadUrl: content.smallViewableUrl || content.primaryFileUrl,
|
|
184
|
-
tinyViewableDownloadUrl: content.tinyViewableUrl || content.primaryFileUrl,
|
|
185
|
-
};
|
|
186
|
-
const customSizes = await this.getCustomSizes();
|
|
187
|
-
for (const size of customSizes) {
|
|
188
|
-
updates[`${size.slug}DownloadUrl`] = content[`${size.slug}Url`] || content.primaryFileUrl;
|
|
189
|
-
}
|
|
190
|
-
return updates;
|
|
191
|
-
}
|
|
192
|
-
async getClearPrimaryViewableUpdates() {
|
|
193
|
-
const updates = {
|
|
194
|
-
primaryViewableId: null,
|
|
195
|
-
contentType: null,
|
|
196
|
-
fileName: null,
|
|
197
|
-
primaryFileUrl: null,
|
|
198
|
-
largeViewableDownloadUrl: null,
|
|
199
|
-
mediumLargeViewableDownloadUrl: null,
|
|
200
|
-
mediumViewableDownloadUrl: null,
|
|
201
|
-
smallViewableDownloadUrl: null,
|
|
202
|
-
tinyViewableDownloadUrl: null,
|
|
203
|
-
};
|
|
204
|
-
const customSizes = await this.getCustomSizes();
|
|
205
|
-
for (const size of customSizes) {
|
|
206
|
-
updates[`${size.slug}DownloadUrl`] = null;
|
|
207
|
-
}
|
|
208
|
-
return updates;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.ThumbnailUtil = ThumbnailUtil;
|
|
212
|
-
ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
|
|
213
|
-
ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
|
|
214
|
-
ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
|
|
215
|
-
ThumbnailUtil.OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThumbnailUtil = void 0;
|
|
4
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
+
const sdk_1 = require("@contrail/sdk");
|
|
6
|
+
const flexplm_connect_1 = require("./flexplm-connect");
|
|
7
|
+
;
|
|
8
|
+
class ThumbnailUtil {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.max_thumbnail_size = 5 * 1024 * 1024;
|
|
12
|
+
this.entities = new sdk_1.Entities();
|
|
13
|
+
if (this.config['max_thumbnail_size']) {
|
|
14
|
+
this.max_thumbnail_size = this.config['max_thumbnail_size'];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async setOutboundThumbnail(data, event) {
|
|
18
|
+
if (event?.newData?.primaryViewableId && event?.newData?.largeViewableDownloadUrl) {
|
|
19
|
+
const primaryViewableId = event.newData.primaryViewableId;
|
|
20
|
+
const fileId = await this.getFileId(primaryViewableId);
|
|
21
|
+
if (fileId) {
|
|
22
|
+
const customSizes = await this.getCustomSizes();
|
|
23
|
+
const key = (this.isThumbnailNew(event, customSizes))
|
|
24
|
+
? ThumbnailUtil.NEW_THUMBNAIL_ID
|
|
25
|
+
: ThumbnailUtil.EXISTING_THUMBNAIL_ID;
|
|
26
|
+
data[key] = fileId;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (event?.propertyDiffs?.largeViewableDownloadUrl?.oldValue && !event?.propertyDiffs?.largeViewableDownloadUrl?.newValue) {
|
|
30
|
+
data[ThumbnailUtil.NEW_THUMBNAIL_ID] = ThumbnailUtil.REMOVE_THUMBNAIL;
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
isThumbnailNew(event, customSizes) {
|
|
35
|
+
const propertyDiffs = event?.propertyDiffs;
|
|
36
|
+
if (propertyDiffs) {
|
|
37
|
+
const diffKeys = Object.keys(propertyDiffs);
|
|
38
|
+
const sizeKeys = ThumbnailUtil.OOB_SIZES.map(s => s.slug + 'DownloadUrl');
|
|
39
|
+
if (customSizes) {
|
|
40
|
+
sizeKeys.push(...customSizes.map(s => s.slug + 'Url'));
|
|
41
|
+
}
|
|
42
|
+
sizeKeys.push('primaryFileUrl');
|
|
43
|
+
console.info('diffKeys: ' + JSON.stringify(diffKeys));
|
|
44
|
+
console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
|
|
45
|
+
return diffKeys.some(s => sizeKeys.includes(s));
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
async getFileId(primaryViewableId) {
|
|
50
|
+
console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
|
|
51
|
+
const sizes = await this.getCustomSizes();
|
|
52
|
+
const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
|
|
53
|
+
sizes.push(...OOBSizes);
|
|
54
|
+
console.info('sizes: ' + JSON.stringify(sizes));
|
|
55
|
+
const content = await this.getContentEntity(primaryViewableId, sizes);
|
|
56
|
+
if (!content) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const contentKeys = Object.getOwnPropertyNames(content);
|
|
60
|
+
const isDebugOn = app_framework_1.Logger.isDebugOn();
|
|
61
|
+
let fileId = undefined;
|
|
62
|
+
let tempFileSize = 0;
|
|
63
|
+
for (const size of sizes) {
|
|
64
|
+
const slug = size?.slug;
|
|
65
|
+
if (contentKeys.includes(slug)) {
|
|
66
|
+
const file = content[slug];
|
|
67
|
+
if (isDebugOn) {
|
|
68
|
+
console.debug('size: ' + slug);
|
|
69
|
+
console.debug('fileId: ' + file['id']);
|
|
70
|
+
}
|
|
71
|
+
if (file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
|
|
72
|
+
tempFileSize = file['size'];
|
|
73
|
+
fileId = file['id'];
|
|
74
|
+
if (isDebugOn) {
|
|
75
|
+
console.debug('fileId: ' + fileId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
|
|
81
|
+
return fileId;
|
|
82
|
+
}
|
|
83
|
+
async getCustomSizes() {
|
|
84
|
+
const customSizes = await this.entities.get({
|
|
85
|
+
entityName: 'content-custom-size'
|
|
86
|
+
});
|
|
87
|
+
const sizes = [];
|
|
88
|
+
sizes.push(...customSizes);
|
|
89
|
+
return sizes;
|
|
90
|
+
}
|
|
91
|
+
async getContentEntity(primaryViewableId, sizes) {
|
|
92
|
+
const relations = sizes.map(s => s.slug);
|
|
93
|
+
relations.push('primaryFile');
|
|
94
|
+
const content = await this.entities.get({
|
|
95
|
+
entityName: 'content',
|
|
96
|
+
id: primaryViewableId,
|
|
97
|
+
relations
|
|
98
|
+
});
|
|
99
|
+
this.logContentResults(content, relations);
|
|
100
|
+
return content;
|
|
101
|
+
}
|
|
102
|
+
logContentResults(content, relations) {
|
|
103
|
+
if (app_framework_1.Logger.isDebugOn() && content && relations) {
|
|
104
|
+
const contentCopy = JSON.parse(JSON.stringify(content));
|
|
105
|
+
relations.forEach(r => {
|
|
106
|
+
delete contentCopy[r];
|
|
107
|
+
});
|
|
108
|
+
console.debug('content: ' + JSON.stringify(contentCopy));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async syncThumbnailToVibeIQ({ entityId, primaryViewableId, event, entityName }) {
|
|
112
|
+
console.debug(`syncThumbnailToVibeIQ: entityId=${entityId}, primaryViewableId=${primaryViewableId}, entityName=${entityName}`);
|
|
113
|
+
const eventData = event.data || {};
|
|
114
|
+
const newThumbnailId = eventData[ThumbnailUtil.NEW_THUMBNAIL_ID];
|
|
115
|
+
const existingThumbnailId = eventData[ThumbnailUtil.EXISTING_THUMBNAIL_ID];
|
|
116
|
+
const thumbnailUrl = newThumbnailId || existingThumbnailId;
|
|
117
|
+
if (newThumbnailId === ThumbnailUtil.REMOVE_THUMBNAIL) {
|
|
118
|
+
if (primaryViewableId) {
|
|
119
|
+
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
120
|
+
}
|
|
121
|
+
const clearUpdates = await this.getClearPrimaryViewableUpdates();
|
|
122
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: clearUpdates });
|
|
123
|
+
console.debug(`syncThumbnailToVibeIQ: applied clear updates for entityId=${entityId}`);
|
|
124
|
+
return updatedEntity;
|
|
125
|
+
}
|
|
126
|
+
if (!thumbnailUrl) {
|
|
127
|
+
console.debug(`syncThumbnailToVibeIQ: no thumbnail URL for entityId=${entityId}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
if (!primaryViewableId) {
|
|
131
|
+
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
132
|
+
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
133
|
+
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
134
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
135
|
+
console.debug(`syncThumbnailToVibeIQ: created new content ${content.id} for entityId=${entityId}`);
|
|
136
|
+
return updatedEntity;
|
|
137
|
+
}
|
|
138
|
+
const primaryViewable = await this.entities.get({ entityName: 'content', id: primaryViewableId });
|
|
139
|
+
if (primaryViewable?.flexplmThumbnailUrl === thumbnailUrl) {
|
|
140
|
+
console.debug(`syncThumbnailToVibeIQ: thumbnail already synced for entityId=${entityId}`);
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
144
|
+
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
145
|
+
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
146
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
147
|
+
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
148
|
+
console.debug(`syncThumbnailToVibeIQ: replaced content ${primaryViewableId} with ${content.id} for entityId=${entityId}`);
|
|
149
|
+
return updatedEntity;
|
|
150
|
+
}
|
|
151
|
+
async createContentFromFlexPLM(thumbnailUrl, entityId, entityName) {
|
|
152
|
+
const urlParts = thumbnailUrl.split('/');
|
|
153
|
+
const fileName = urlParts[urlParts.length - 1] || 'thumbnail';
|
|
154
|
+
const encodedUrl = urlParts.map(part => encodeURIComponent(part)).join('/');
|
|
155
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
156
|
+
const response = await flexPLMConnect.getRequest({
|
|
157
|
+
urlPath: encodedUrl,
|
|
158
|
+
includeUrlContext: false,
|
|
159
|
+
returnFullResponse: true,
|
|
160
|
+
});
|
|
161
|
+
const fileBuffer = await response.arrayBuffer();
|
|
162
|
+
const buffer = Buffer.from(fileBuffer);
|
|
163
|
+
const contentTypeHeader = response.headers.get('content-type');
|
|
164
|
+
const contentType = contentTypeHeader ? contentTypeHeader.split(';')[0] : 'application/octet-stream';
|
|
165
|
+
const contentHolderReference = `${entityName}:${entityId}`;
|
|
166
|
+
const content = await new sdk_1.Content().create({
|
|
167
|
+
fileBuffer: buffer,
|
|
168
|
+
fileName,
|
|
169
|
+
contentType,
|
|
170
|
+
contentHolderReference,
|
|
171
|
+
});
|
|
172
|
+
return content;
|
|
173
|
+
}
|
|
174
|
+
async getPrimaryViewableUpdates(content) {
|
|
175
|
+
const updates = {
|
|
176
|
+
primaryViewableId: content.id,
|
|
177
|
+
contentType: content.contentType,
|
|
178
|
+
fileName: content.fileName,
|
|
179
|
+
primaryFileUrl: content.primaryFileUrl,
|
|
180
|
+
largeViewableDownloadUrl: content.largeViewableUrl || content.primaryFileUrl,
|
|
181
|
+
mediumLargeViewableDownloadUrl: content.mediumLargeViewableUrl || content.primaryFileUrl,
|
|
182
|
+
mediumViewableDownloadUrl: content.mediumViewableUrl || content.primaryFileUrl,
|
|
183
|
+
smallViewableDownloadUrl: content.smallViewableUrl || content.primaryFileUrl,
|
|
184
|
+
tinyViewableDownloadUrl: content.tinyViewableUrl || content.primaryFileUrl,
|
|
185
|
+
};
|
|
186
|
+
const customSizes = await this.getCustomSizes();
|
|
187
|
+
for (const size of customSizes) {
|
|
188
|
+
updates[`${size.slug}DownloadUrl`] = content[`${size.slug}Url`] || content.primaryFileUrl;
|
|
189
|
+
}
|
|
190
|
+
return updates;
|
|
191
|
+
}
|
|
192
|
+
async getClearPrimaryViewableUpdates() {
|
|
193
|
+
const updates = {
|
|
194
|
+
primaryViewableId: null,
|
|
195
|
+
contentType: null,
|
|
196
|
+
fileName: null,
|
|
197
|
+
primaryFileUrl: null,
|
|
198
|
+
largeViewableDownloadUrl: null,
|
|
199
|
+
mediumLargeViewableDownloadUrl: null,
|
|
200
|
+
mediumViewableDownloadUrl: null,
|
|
201
|
+
smallViewableDownloadUrl: null,
|
|
202
|
+
tinyViewableDownloadUrl: null,
|
|
203
|
+
};
|
|
204
|
+
const customSizes = await this.getCustomSizes();
|
|
205
|
+
for (const size of customSizes) {
|
|
206
|
+
updates[`${size.slug}DownloadUrl`] = null;
|
|
207
|
+
}
|
|
208
|
+
return updates;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.ThumbnailUtil = ThumbnailUtil;
|
|
212
|
+
ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
|
|
213
|
+
ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
|
|
214
|
+
ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
|
|
215
|
+
ThumbnailUtil.OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|