3dviewer-sdk 1.0.3 → 1.0.4
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/index.d.mts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +81 -1
- package/dist/index.mjs +81 -1
- package/dist/modules/files.module.d.ts +22 -0
- package/dist/modules/files.module.js +80 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -236,6 +236,23 @@ type FilesConfig = {
|
|
|
236
236
|
type ConvertOptions = {
|
|
237
237
|
downloadUrl?: string;
|
|
238
238
|
};
|
|
239
|
+
type ConvertV2Options = {
|
|
240
|
+
filename: string;
|
|
241
|
+
originalFilePath: string;
|
|
242
|
+
downloadUrl: string;
|
|
243
|
+
baseFileId: string;
|
|
244
|
+
baseMajorRev?: number;
|
|
245
|
+
baseMinorRev?: number;
|
|
246
|
+
overwrite?: boolean;
|
|
247
|
+
project?: string;
|
|
248
|
+
convertOptions?: Partial<StreamConvertOptions>;
|
|
249
|
+
};
|
|
250
|
+
type StreamConvertOptions = {
|
|
251
|
+
convert3DModel: number;
|
|
252
|
+
convert2DSheet: number;
|
|
253
|
+
extractProperties: number;
|
|
254
|
+
childModels: number;
|
|
255
|
+
};
|
|
239
256
|
declare class FilesModule {
|
|
240
257
|
private viewer;
|
|
241
258
|
on: {
|
|
@@ -287,6 +304,7 @@ declare class FilesModule {
|
|
|
287
304
|
}>;
|
|
288
305
|
convert(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
289
306
|
prepare(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
307
|
+
convertV2(options: ConvertV2Options): Promise<PreparedViewerData>;
|
|
290
308
|
open(input: PreparedViewerData | {
|
|
291
309
|
url: string;
|
|
292
310
|
}): void;
|
|
@@ -304,8 +322,11 @@ declare class FilesModule {
|
|
|
304
322
|
private getUploadSessionForFile;
|
|
305
323
|
private uploadInternal;
|
|
306
324
|
private buildCachePayload;
|
|
325
|
+
private buildConvertV2Payload;
|
|
307
326
|
private cacheFile;
|
|
327
|
+
private cacheFileV2;
|
|
308
328
|
private convertInternal;
|
|
329
|
+
private convertV2Internal;
|
|
309
330
|
private updateState;
|
|
310
331
|
private withOperation;
|
|
311
332
|
private toErrorMessage;
|
|
@@ -478,4 +499,4 @@ declare class Viewer3D {
|
|
|
478
499
|
private handleMessage;
|
|
479
500
|
}
|
|
480
501
|
|
|
481
|
-
export { type ConvertOptions, type FilesConfig, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
|
|
502
|
+
export { type ConvertOptions, type ConvertV2Options, type FilesConfig, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
|
package/dist/index.d.ts
CHANGED
|
@@ -236,6 +236,23 @@ type FilesConfig = {
|
|
|
236
236
|
type ConvertOptions = {
|
|
237
237
|
downloadUrl?: string;
|
|
238
238
|
};
|
|
239
|
+
type ConvertV2Options = {
|
|
240
|
+
filename: string;
|
|
241
|
+
originalFilePath: string;
|
|
242
|
+
downloadUrl: string;
|
|
243
|
+
baseFileId: string;
|
|
244
|
+
baseMajorRev?: number;
|
|
245
|
+
baseMinorRev?: number;
|
|
246
|
+
overwrite?: boolean;
|
|
247
|
+
project?: string;
|
|
248
|
+
convertOptions?: Partial<StreamConvertOptions>;
|
|
249
|
+
};
|
|
250
|
+
type StreamConvertOptions = {
|
|
251
|
+
convert3DModel: number;
|
|
252
|
+
convert2DSheet: number;
|
|
253
|
+
extractProperties: number;
|
|
254
|
+
childModels: number;
|
|
255
|
+
};
|
|
239
256
|
declare class FilesModule {
|
|
240
257
|
private viewer;
|
|
241
258
|
on: {
|
|
@@ -287,6 +304,7 @@ declare class FilesModule {
|
|
|
287
304
|
}>;
|
|
288
305
|
convert(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
289
306
|
prepare(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
307
|
+
convertV2(options: ConvertV2Options): Promise<PreparedViewerData>;
|
|
290
308
|
open(input: PreparedViewerData | {
|
|
291
309
|
url: string;
|
|
292
310
|
}): void;
|
|
@@ -304,8 +322,11 @@ declare class FilesModule {
|
|
|
304
322
|
private getUploadSessionForFile;
|
|
305
323
|
private uploadInternal;
|
|
306
324
|
private buildCachePayload;
|
|
325
|
+
private buildConvertV2Payload;
|
|
307
326
|
private cacheFile;
|
|
327
|
+
private cacheFileV2;
|
|
308
328
|
private convertInternal;
|
|
329
|
+
private convertV2Internal;
|
|
309
330
|
private updateState;
|
|
310
331
|
private withOperation;
|
|
311
332
|
private toErrorMessage;
|
|
@@ -478,4 +499,4 @@ declare class Viewer3D {
|
|
|
478
499
|
private handleMessage;
|
|
479
500
|
}
|
|
480
501
|
|
|
481
|
-
export { type ConvertOptions, type FilesConfig, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
|
|
502
|
+
export { type ConvertOptions, type ConvertV2Options, type FilesConfig, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
|
package/dist/index.js
CHANGED
|
@@ -217,6 +217,20 @@ var FilesModule = class {
|
|
|
217
217
|
return prepared;
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
+
// Trigger the newer downloadUrl-based conversion flow.
|
|
221
|
+
async convertV2(options) {
|
|
222
|
+
return this.withOperation({ stage: "converting", message: "Converting file..." }, async () => {
|
|
223
|
+
this.viewer._emit("files:conversion:start", { fileName: options.filename });
|
|
224
|
+
try {
|
|
225
|
+
const prepared = await this.convertV2Internal(options);
|
|
226
|
+
this.viewer._emit("files:conversion:success", prepared);
|
|
227
|
+
return prepared;
|
|
228
|
+
} catch (e) {
|
|
229
|
+
this.viewer._emit("files:conversion:error", { fileName: options.filename, error: this.toErrorMessage(e) });
|
|
230
|
+
throw e;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
220
234
|
// Open iframe with an already prepared viewer URL.
|
|
221
235
|
open(input) {
|
|
222
236
|
const url = input.url;
|
|
@@ -374,6 +388,26 @@ var FilesModule = class {
|
|
|
374
388
|
attemptedConvertTimes: 0
|
|
375
389
|
};
|
|
376
390
|
}
|
|
391
|
+
// Build payload for POST /api/StreamFile/convert.
|
|
392
|
+
buildConvertV2Payload(options) {
|
|
393
|
+
var _a, _b;
|
|
394
|
+
const convertOptions = {
|
|
395
|
+
convert3DModel: 1,
|
|
396
|
+
convert2DSheet: 1,
|
|
397
|
+
extractProperties: 1,
|
|
398
|
+
childModels: 0,
|
|
399
|
+
...options.convertOptions
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
filename: options.filename,
|
|
403
|
+
originalFilePath: options.originalFilePath,
|
|
404
|
+
convertOptions,
|
|
405
|
+
downloadUrl: options.downloadUrl,
|
|
406
|
+
baseFileId: options.baseFileId,
|
|
407
|
+
baseMajorRev: (_a = options.baseMajorRev) != null ? _a : 0,
|
|
408
|
+
baseMinorRev: (_b = options.baseMinorRev) != null ? _b : 0
|
|
409
|
+
};
|
|
410
|
+
}
|
|
377
411
|
// Submit conversion/caching request and return service response.
|
|
378
412
|
async cacheFile(file, baseFileId, options = {}) {
|
|
379
413
|
const hostConversion = await this.resolveHostConversion();
|
|
@@ -394,6 +428,34 @@ var FilesModule = class {
|
|
|
394
428
|
}
|
|
395
429
|
return await response.json();
|
|
396
430
|
}
|
|
431
|
+
// Submit conversion request to the newer downloadUrl-based endpoint.
|
|
432
|
+
async cacheFileV2(options) {
|
|
433
|
+
const hostConversion = await this.resolveHostConversion();
|
|
434
|
+
const params = new URLSearchParams();
|
|
435
|
+
if (typeof options.overwrite === "boolean") {
|
|
436
|
+
params.set("overwrite", String(options.overwrite));
|
|
437
|
+
}
|
|
438
|
+
if (options.project) {
|
|
439
|
+
params.set("project", options.project);
|
|
440
|
+
}
|
|
441
|
+
const query = params.toString();
|
|
442
|
+
const url = `${hostConversion}/api/StreamFile/convert${query ? `?${query}` : ""}`;
|
|
443
|
+
const payload = this.buildConvertV2Payload(options);
|
|
444
|
+
const response = await fetch(url, {
|
|
445
|
+
method: "POST",
|
|
446
|
+
headers: {
|
|
447
|
+
"Content-Type": "application/json",
|
|
448
|
+
Accept: "application/json"
|
|
449
|
+
},
|
|
450
|
+
body: JSON.stringify(payload)
|
|
451
|
+
});
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
throw new Error(
|
|
454
|
+
`Cache/convert v2 failed (${response.status} ${response.statusText})`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
return await response.json();
|
|
458
|
+
}
|
|
397
459
|
// Convert file and generate final iframe URL with query string.
|
|
398
460
|
async convertInternal(file, options = {}) {
|
|
399
461
|
var _a, _b, _c, _d;
|
|
@@ -404,7 +466,7 @@ var FilesModule = class {
|
|
|
404
466
|
const baseFileId = (_a = cacheResult.baseFileId) != null ? _a : seedBaseFileId;
|
|
405
467
|
const baseMajorRev = (_b = cacheResult.baseMajorRev) != null ? _b : 0;
|
|
406
468
|
const baseMinorRev = (_c = cacheResult.baseMinorRev) != null ? _c : 0;
|
|
407
|
-
const fileName = cacheResult.filename || file.name;
|
|
469
|
+
const fileName = cacheResult.filename || cacheResult.fileName || file.name;
|
|
408
470
|
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
409
471
|
if (cacheResult.cacheStatus !== 2) {
|
|
410
472
|
throw new Error(`Conversion not ready after first request (cacheStatus=${(_d = cacheResult.cacheStatus) != null ? _d : "unknown"})`);
|
|
@@ -415,6 +477,24 @@ var FilesModule = class {
|
|
|
415
477
|
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
416
478
|
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
417
479
|
}
|
|
480
|
+
async convertV2Internal(options) {
|
|
481
|
+
var _a, _b, _c, _d, _e;
|
|
482
|
+
this.updateState({ stage: "converting", message: "Converting file..." });
|
|
483
|
+
const cacheResult = await this.cacheFileV2(options);
|
|
484
|
+
const baseFileId = (_a = cacheResult.baseFileId) != null ? _a : options.baseFileId;
|
|
485
|
+
const baseMajorRev = (_c = (_b = cacheResult.baseMajorRev) != null ? _b : options.baseMajorRev) != null ? _c : 0;
|
|
486
|
+
const baseMinorRev = (_e = (_d = cacheResult.baseMinorRev) != null ? _d : options.baseMinorRev) != null ? _e : 0;
|
|
487
|
+
const fileName = cacheResult.filename || cacheResult.fileName || options.filename;
|
|
488
|
+
if (cacheResult.cacheStatus !== void 0 && cacheResult.cacheStatus !== 2) {
|
|
489
|
+
throw new Error(`Conversion not ready after v2 request (cacheStatus=${cacheResult.cacheStatus})`);
|
|
490
|
+
}
|
|
491
|
+
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
492
|
+
const query = new URLSearchParams({ fileList: JSON.stringify([cacheListItem]) }).toString();
|
|
493
|
+
const viewerBase = this.resolveViewerOrigin();
|
|
494
|
+
const viewerPath = this.resolveViewerPath();
|
|
495
|
+
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
496
|
+
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
497
|
+
}
|
|
418
498
|
// Update internal loading state and emit state event.
|
|
419
499
|
updateState(next) {
|
|
420
500
|
const elapsedMs = this.operationStartTime > 0 ? Date.now() - this.operationStartTime : 0;
|
package/dist/index.mjs
CHANGED
|
@@ -191,6 +191,20 @@ var FilesModule = class {
|
|
|
191
191
|
return prepared;
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
+
// Trigger the newer downloadUrl-based conversion flow.
|
|
195
|
+
async convertV2(options) {
|
|
196
|
+
return this.withOperation({ stage: "converting", message: "Converting file..." }, async () => {
|
|
197
|
+
this.viewer._emit("files:conversion:start", { fileName: options.filename });
|
|
198
|
+
try {
|
|
199
|
+
const prepared = await this.convertV2Internal(options);
|
|
200
|
+
this.viewer._emit("files:conversion:success", prepared);
|
|
201
|
+
return prepared;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
this.viewer._emit("files:conversion:error", { fileName: options.filename, error: this.toErrorMessage(e) });
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
194
208
|
// Open iframe with an already prepared viewer URL.
|
|
195
209
|
open(input) {
|
|
196
210
|
const url = input.url;
|
|
@@ -348,6 +362,26 @@ var FilesModule = class {
|
|
|
348
362
|
attemptedConvertTimes: 0
|
|
349
363
|
};
|
|
350
364
|
}
|
|
365
|
+
// Build payload for POST /api/StreamFile/convert.
|
|
366
|
+
buildConvertV2Payload(options) {
|
|
367
|
+
var _a, _b;
|
|
368
|
+
const convertOptions = {
|
|
369
|
+
convert3DModel: 1,
|
|
370
|
+
convert2DSheet: 1,
|
|
371
|
+
extractProperties: 1,
|
|
372
|
+
childModels: 0,
|
|
373
|
+
...options.convertOptions
|
|
374
|
+
};
|
|
375
|
+
return {
|
|
376
|
+
filename: options.filename,
|
|
377
|
+
originalFilePath: options.originalFilePath,
|
|
378
|
+
convertOptions,
|
|
379
|
+
downloadUrl: options.downloadUrl,
|
|
380
|
+
baseFileId: options.baseFileId,
|
|
381
|
+
baseMajorRev: (_a = options.baseMajorRev) != null ? _a : 0,
|
|
382
|
+
baseMinorRev: (_b = options.baseMinorRev) != null ? _b : 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
351
385
|
// Submit conversion/caching request and return service response.
|
|
352
386
|
async cacheFile(file, baseFileId, options = {}) {
|
|
353
387
|
const hostConversion = await this.resolveHostConversion();
|
|
@@ -368,6 +402,34 @@ var FilesModule = class {
|
|
|
368
402
|
}
|
|
369
403
|
return await response.json();
|
|
370
404
|
}
|
|
405
|
+
// Submit conversion request to the newer downloadUrl-based endpoint.
|
|
406
|
+
async cacheFileV2(options) {
|
|
407
|
+
const hostConversion = await this.resolveHostConversion();
|
|
408
|
+
const params = new URLSearchParams();
|
|
409
|
+
if (typeof options.overwrite === "boolean") {
|
|
410
|
+
params.set("overwrite", String(options.overwrite));
|
|
411
|
+
}
|
|
412
|
+
if (options.project) {
|
|
413
|
+
params.set("project", options.project);
|
|
414
|
+
}
|
|
415
|
+
const query = params.toString();
|
|
416
|
+
const url = `${hostConversion}/api/StreamFile/convert${query ? `?${query}` : ""}`;
|
|
417
|
+
const payload = this.buildConvertV2Payload(options);
|
|
418
|
+
const response = await fetch(url, {
|
|
419
|
+
method: "POST",
|
|
420
|
+
headers: {
|
|
421
|
+
"Content-Type": "application/json",
|
|
422
|
+
Accept: "application/json"
|
|
423
|
+
},
|
|
424
|
+
body: JSON.stringify(payload)
|
|
425
|
+
});
|
|
426
|
+
if (!response.ok) {
|
|
427
|
+
throw new Error(
|
|
428
|
+
`Cache/convert v2 failed (${response.status} ${response.statusText})`
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
return await response.json();
|
|
432
|
+
}
|
|
371
433
|
// Convert file and generate final iframe URL with query string.
|
|
372
434
|
async convertInternal(file, options = {}) {
|
|
373
435
|
var _a, _b, _c, _d;
|
|
@@ -378,7 +440,7 @@ var FilesModule = class {
|
|
|
378
440
|
const baseFileId = (_a = cacheResult.baseFileId) != null ? _a : seedBaseFileId;
|
|
379
441
|
const baseMajorRev = (_b = cacheResult.baseMajorRev) != null ? _b : 0;
|
|
380
442
|
const baseMinorRev = (_c = cacheResult.baseMinorRev) != null ? _c : 0;
|
|
381
|
-
const fileName = cacheResult.filename || file.name;
|
|
443
|
+
const fileName = cacheResult.filename || cacheResult.fileName || file.name;
|
|
382
444
|
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
383
445
|
if (cacheResult.cacheStatus !== 2) {
|
|
384
446
|
throw new Error(`Conversion not ready after first request (cacheStatus=${(_d = cacheResult.cacheStatus) != null ? _d : "unknown"})`);
|
|
@@ -389,6 +451,24 @@ var FilesModule = class {
|
|
|
389
451
|
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
390
452
|
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
391
453
|
}
|
|
454
|
+
async convertV2Internal(options) {
|
|
455
|
+
var _a, _b, _c, _d, _e;
|
|
456
|
+
this.updateState({ stage: "converting", message: "Converting file..." });
|
|
457
|
+
const cacheResult = await this.cacheFileV2(options);
|
|
458
|
+
const baseFileId = (_a = cacheResult.baseFileId) != null ? _a : options.baseFileId;
|
|
459
|
+
const baseMajorRev = (_c = (_b = cacheResult.baseMajorRev) != null ? _b : options.baseMajorRev) != null ? _c : 0;
|
|
460
|
+
const baseMinorRev = (_e = (_d = cacheResult.baseMinorRev) != null ? _d : options.baseMinorRev) != null ? _e : 0;
|
|
461
|
+
const fileName = cacheResult.filename || cacheResult.fileName || options.filename;
|
|
462
|
+
if (cacheResult.cacheStatus !== void 0 && cacheResult.cacheStatus !== 2) {
|
|
463
|
+
throw new Error(`Conversion not ready after v2 request (cacheStatus=${cacheResult.cacheStatus})`);
|
|
464
|
+
}
|
|
465
|
+
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
466
|
+
const query = new URLSearchParams({ fileList: JSON.stringify([cacheListItem]) }).toString();
|
|
467
|
+
const viewerBase = this.resolveViewerOrigin();
|
|
468
|
+
const viewerPath = this.resolveViewerPath();
|
|
469
|
+
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
470
|
+
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
471
|
+
}
|
|
392
472
|
// Update internal loading state and emit state event.
|
|
393
473
|
updateState(next) {
|
|
394
474
|
const elapsedMs = this.operationStartTime > 0 ? Date.now() - this.operationStartTime : 0;
|
|
@@ -8,6 +8,23 @@ export declare type FilesConfig = {
|
|
|
8
8
|
export declare type ConvertOptions = {
|
|
9
9
|
downloadUrl?: string;
|
|
10
10
|
};
|
|
11
|
+
export declare type ConvertV2Options = {
|
|
12
|
+
filename: string;
|
|
13
|
+
originalFilePath: string;
|
|
14
|
+
downloadUrl: string;
|
|
15
|
+
baseFileId: string;
|
|
16
|
+
baseMajorRev?: number;
|
|
17
|
+
baseMinorRev?: number;
|
|
18
|
+
overwrite?: boolean;
|
|
19
|
+
project?: string;
|
|
20
|
+
convertOptions?: Partial<StreamConvertOptions>;
|
|
21
|
+
};
|
|
22
|
+
declare type StreamConvertOptions = {
|
|
23
|
+
convert3DModel: number;
|
|
24
|
+
convert2DSheet: number;
|
|
25
|
+
extractProperties: number;
|
|
26
|
+
childModels: number;
|
|
27
|
+
};
|
|
11
28
|
export declare class FilesModule {
|
|
12
29
|
private viewer;
|
|
13
30
|
on: {
|
|
@@ -59,6 +76,7 @@ export declare class FilesModule {
|
|
|
59
76
|
}>;
|
|
60
77
|
convert(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
61
78
|
prepare(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
|
|
79
|
+
convertV2(options: ConvertV2Options): Promise<PreparedViewerData>;
|
|
62
80
|
open(input: PreparedViewerData | {
|
|
63
81
|
url: string;
|
|
64
82
|
}): void;
|
|
@@ -76,9 +94,13 @@ export declare class FilesModule {
|
|
|
76
94
|
private getUploadSessionForFile;
|
|
77
95
|
private uploadInternal;
|
|
78
96
|
private buildCachePayload;
|
|
97
|
+
private buildConvertV2Payload;
|
|
79
98
|
private cacheFile;
|
|
99
|
+
private cacheFileV2;
|
|
80
100
|
private convertInternal;
|
|
101
|
+
private convertV2Internal;
|
|
81
102
|
private updateState;
|
|
82
103
|
private withOperation;
|
|
83
104
|
private toErrorMessage;
|
|
84
105
|
}
|
|
106
|
+
export {};
|
|
@@ -72,6 +72,21 @@ export class FilesModule {
|
|
|
72
72
|
return prepared;
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
// Trigger the newer downloadUrl-based conversion flow.
|
|
76
|
+
async convertV2(options) {
|
|
77
|
+
return this.withOperation({ stage: "converting", message: "Converting file..." }, async () => {
|
|
78
|
+
this.viewer._emit("files:conversion:start", { fileName: options.filename });
|
|
79
|
+
try {
|
|
80
|
+
const prepared = await this.convertV2Internal(options);
|
|
81
|
+
this.viewer._emit("files:conversion:success", prepared);
|
|
82
|
+
return prepared;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
this.viewer._emit("files:conversion:error", { fileName: options.filename, error: this.toErrorMessage(e) });
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
75
90
|
// Open iframe with an already prepared viewer URL.
|
|
76
91
|
open(input) {
|
|
77
92
|
const url = input.url;
|
|
@@ -239,6 +254,26 @@ export class FilesModule {
|
|
|
239
254
|
attemptedConvertTimes: 0,
|
|
240
255
|
};
|
|
241
256
|
}
|
|
257
|
+
// Build payload for POST /api/StreamFile/convert.
|
|
258
|
+
buildConvertV2Payload(options) {
|
|
259
|
+
var _a, _b;
|
|
260
|
+
const convertOptions = {
|
|
261
|
+
convert3DModel: 1,
|
|
262
|
+
convert2DSheet: 1,
|
|
263
|
+
extractProperties: 1,
|
|
264
|
+
childModels: 0,
|
|
265
|
+
...options.convertOptions,
|
|
266
|
+
};
|
|
267
|
+
return {
|
|
268
|
+
filename: options.filename,
|
|
269
|
+
originalFilePath: options.originalFilePath,
|
|
270
|
+
convertOptions,
|
|
271
|
+
downloadUrl: options.downloadUrl,
|
|
272
|
+
baseFileId: options.baseFileId,
|
|
273
|
+
baseMajorRev: (_a = options.baseMajorRev) !== null && _a !== void 0 ? _a : 0,
|
|
274
|
+
baseMinorRev: (_b = options.baseMinorRev) !== null && _b !== void 0 ? _b : 0,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
242
277
|
// Submit conversion/caching request and return service response.
|
|
243
278
|
async cacheFile(file, baseFileId, options = {}) {
|
|
244
279
|
const hostConversion = await this.resolveHostConversion();
|
|
@@ -257,6 +292,32 @@ export class FilesModule {
|
|
|
257
292
|
}
|
|
258
293
|
return (await response.json());
|
|
259
294
|
}
|
|
295
|
+
// Submit conversion request to the newer downloadUrl-based endpoint.
|
|
296
|
+
async cacheFileV2(options) {
|
|
297
|
+
const hostConversion = await this.resolveHostConversion();
|
|
298
|
+
const params = new URLSearchParams();
|
|
299
|
+
if (typeof options.overwrite === "boolean") {
|
|
300
|
+
params.set("overwrite", String(options.overwrite));
|
|
301
|
+
}
|
|
302
|
+
if (options.project) {
|
|
303
|
+
params.set("project", options.project);
|
|
304
|
+
}
|
|
305
|
+
const query = params.toString();
|
|
306
|
+
const url = `${hostConversion}/api/StreamFile/convert${query ? `?${query}` : ""}`;
|
|
307
|
+
const payload = this.buildConvertV2Payload(options);
|
|
308
|
+
const response = await fetch(url, {
|
|
309
|
+
method: "POST",
|
|
310
|
+
headers: {
|
|
311
|
+
"Content-Type": "application/json",
|
|
312
|
+
Accept: "application/json",
|
|
313
|
+
},
|
|
314
|
+
body: JSON.stringify(payload),
|
|
315
|
+
});
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
throw new Error(`Cache/convert v2 failed (${response.status} ${response.statusText})`);
|
|
318
|
+
}
|
|
319
|
+
return (await response.json());
|
|
320
|
+
}
|
|
260
321
|
// Convert file and generate final iframe URL with query string.
|
|
261
322
|
async convertInternal(file, options = {}) {
|
|
262
323
|
var _a, _b, _c, _d;
|
|
@@ -268,7 +329,7 @@ export class FilesModule {
|
|
|
268
329
|
const baseFileId = (_a = cacheResult.baseFileId) !== null && _a !== void 0 ? _a : seedBaseFileId;
|
|
269
330
|
const baseMajorRev = (_b = cacheResult.baseMajorRev) !== null && _b !== void 0 ? _b : 0;
|
|
270
331
|
const baseMinorRev = (_c = cacheResult.baseMinorRev) !== null && _c !== void 0 ? _c : 0;
|
|
271
|
-
const fileName = cacheResult.filename || file.name;
|
|
332
|
+
const fileName = cacheResult.filename || cacheResult.fileName || file.name;
|
|
272
333
|
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
273
334
|
// Single-shot mode: one conversion request only, no polling retry.
|
|
274
335
|
if (cacheResult.cacheStatus !== 2) {
|
|
@@ -281,6 +342,24 @@ export class FilesModule {
|
|
|
281
342
|
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
282
343
|
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
283
344
|
}
|
|
345
|
+
async convertV2Internal(options) {
|
|
346
|
+
var _a, _b, _c, _d, _e;
|
|
347
|
+
this.updateState({ stage: "converting", message: "Converting file..." });
|
|
348
|
+
const cacheResult = await this.cacheFileV2(options);
|
|
349
|
+
const baseFileId = (_a = cacheResult.baseFileId) !== null && _a !== void 0 ? _a : options.baseFileId;
|
|
350
|
+
const baseMajorRev = (_c = (_b = cacheResult.baseMajorRev) !== null && _b !== void 0 ? _b : options.baseMajorRev) !== null && _c !== void 0 ? _c : 0;
|
|
351
|
+
const baseMinorRev = (_e = (_d = cacheResult.baseMinorRev) !== null && _d !== void 0 ? _d : options.baseMinorRev) !== null && _e !== void 0 ? _e : 0;
|
|
352
|
+
const fileName = cacheResult.filename || cacheResult.fileName || options.filename;
|
|
353
|
+
if (cacheResult.cacheStatus !== undefined && cacheResult.cacheStatus !== 2) {
|
|
354
|
+
throw new Error(`Conversion not ready after v2 request (cacheStatus=${cacheResult.cacheStatus})`);
|
|
355
|
+
}
|
|
356
|
+
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
357
|
+
const query = new URLSearchParams({ fileList: JSON.stringify([cacheListItem]) }).toString();
|
|
358
|
+
const viewerBase = this.resolveViewerOrigin();
|
|
359
|
+
const viewerPath = this.resolveViewerPath();
|
|
360
|
+
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
361
|
+
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
362
|
+
}
|
|
284
363
|
// Update internal loading state and emit state event.
|
|
285
364
|
updateState(next) {
|
|
286
365
|
const elapsedMs = this.operationStartTime > 0 ? Date.now() - this.operationStartTime : 0;
|