@loaders.gl/tile-converter 4.3.0-alpha.4 → 4.3.0-alpha.6

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.
Files changed (59) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +4 -1
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +2 -2
  4. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/load-i3s.js +5 -4
  6. package/dist/converter-cli.js +2 -20
  7. package/dist/converter.min.cjs +69 -69
  8. package/dist/deps-installer/deps-installer.js +1 -1
  9. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  10. package/dist/i3s-converter/helpers/node-index-document.js +6 -14
  11. package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
  12. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  13. package/dist/i3s-converter/helpers/node-pages.js +14 -40
  14. package/dist/i3s-converter/helpers/progress.js +1 -1
  15. package/dist/i3s-converter/i3s-converter.d.ts +23 -23
  16. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  17. package/dist/i3s-converter/i3s-converter.js +64 -134
  18. package/dist/i3s-server/app.d.ts +2 -1
  19. package/dist/i3s-server/app.d.ts.map +1 -1
  20. package/dist/i3s-server/app.js +7 -10
  21. package/dist/i3s-server/bin/i3s-server.min.cjs +71 -71
  22. package/dist/i3s-server/bin/www.js +5 -0
  23. package/dist/index.cjs +92 -185
  24. package/dist/index.cjs.map +3 -3
  25. package/dist/lib/utils/statistic-utils.d.ts +20 -0
  26. package/dist/lib/utils/statistic-utils.d.ts.map +1 -0
  27. package/dist/lib/utils/{statistic-utills.js → statistic-utils.js} +17 -4
  28. package/dist/pgm-loader.js +1 -1
  29. package/package.json +19 -20
  30. package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -3
  31. package/src/3d-tiles-converter/helpers/load-i3s.ts +5 -4
  32. package/src/converter-cli.ts +3 -28
  33. package/src/i3s-converter/helpers/node-index-document.ts +16 -26
  34. package/src/i3s-converter/helpers/node-pages.ts +20 -46
  35. package/src/i3s-converter/helpers/progress.ts +1 -1
  36. package/src/i3s-converter/i3s-converter.ts +92 -160
  37. package/src/i3s-server/app.ts +7 -10
  38. package/src/i3s-server/bin/www.ts +6 -0
  39. package/src/lib/utils/{statistic-utills.ts → statistic-utils.ts} +21 -4
  40. package/bin/slpk-extractor.js +0 -2
  41. package/dist/i3s-server/controllers/index-controller.d.ts +0 -8
  42. package/dist/i3s-server/controllers/index-controller.d.ts.map +0 -1
  43. package/dist/i3s-server/controllers/index-controller.js +0 -31
  44. package/dist/i3s-server/routes/index.d.ts +0 -2
  45. package/dist/i3s-server/routes/index.d.ts.map +0 -1
  46. package/dist/i3s-server/routes/index.js +0 -17
  47. package/dist/lib/utils/statistic-utills.d.ts +0 -8
  48. package/dist/lib/utils/statistic-utills.d.ts.map +0 -1
  49. package/dist/slpk-extractor/slpk-extractor.d.ts +0 -23
  50. package/dist/slpk-extractor/slpk-extractor.d.ts.map +0 -1
  51. package/dist/slpk-extractor/slpk-extractor.js +0 -73
  52. package/dist/slpk-extractor-cli.d.ts +0 -17
  53. package/dist/slpk-extractor-cli.d.ts.map +0 -1
  54. package/dist/slpk-extractor-cli.js +0 -105
  55. package/dist/slpk-extractor.min.cjs +0 -344
  56. package/src/i3s-server/controllers/index-controller.ts +0 -32
  57. package/src/i3s-server/routes/index.ts +0 -18
  58. package/src/slpk-extractor/slpk-extractor.ts +0 -102
  59. package/src/slpk-extractor-cli.ts +0 -136
@@ -32,7 +32,7 @@ import md5 from 'md5';
32
32
  import NodePages from './helpers/node-pages';
33
33
  import {writeFile, removeDir, writeFileForSlpk, removeFile} from '../lib/utils/file-utils';
34
34
  import {compressFileWithGzip} from '../lib/utils/compress-util';
35
- import {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';
35
+ import {calculateDatasetSize, timeConverter} from '../lib/utils/statistic-utils';
36
36
  import convertB3dmToI3sGeometry, {getPropertyTable} from './helpers/geometry-converter';
37
37
  import {
38
38
  createBoundingVolumes,
@@ -80,6 +80,7 @@ import {analyzeTileContent, mergePreprocessData} from './helpers/preprocess-3d-t
80
80
  import {Progress} from './helpers/progress';
81
81
  import {composeHashFile, createZip} from '@loaders.gl/zip';
82
82
  import {ConversionDump, ConversionDumpOptions, DumpMetadata} from '../lib/utils/conversion-dump';
83
+ import {PromptModule} from 'inquirer';
83
84
 
84
85
  const ION_DEFAULT_TOKEN = process.env?.IonToken;
85
86
  const HARDCODED_NODES_PER_PAGE = 64;
@@ -90,13 +91,31 @@ const CESIUM_DATASET_PREFIX = 'https://';
90
91
  // const FS_FILE_TOO_LARGE = 'ERR_FS_FILE_TOO_LARGE';
91
92
  const PROGRESS_PHASE1_COUNT = 'phase1-count';
92
93
 
94
+ type ConverterProps = {
95
+ inputUrl: string;
96
+ outputPath: string;
97
+ tilesetName: string;
98
+ egmFilePath: string;
99
+ maxDepth?: number;
100
+ token?: string;
101
+ draco?: boolean;
102
+ mergeMaterials?: boolean;
103
+ validate?: boolean;
104
+ generateTextures?: boolean;
105
+ generateBoundingVolumes?: boolean;
106
+ instantNodeWriting?: boolean;
107
+ inquirer?: {prompt: PromptModule};
108
+ metadataClass?: string;
109
+ analyze?: boolean;
110
+ };
111
+
93
112
  /**
94
113
  * Converter from 3d-tiles tileset to i3s layer
95
114
  */
96
115
  export default class I3SConverter {
97
116
  attributeMetadataInfo: AttributeMetadataInfo;
98
117
  nodePages: NodePages;
99
- options: any;
118
+ options: Partial<ConverterProps>;
100
119
  layers0Path: string;
101
120
  materialMap: Map<string, number>;
102
121
  materialDefinitions: I3SMaterialDefinition[];
@@ -174,8 +193,6 @@ export default class I3SConverter {
174
193
  * @param options.outputPath the output filename
175
194
  * @param options.tilesetName the output name of the tileset
176
195
  * @param options.maxDepth The max tree depth of conversion
177
- * @param options.slpk Generate slpk (Scene Layer Packages) output file
178
- * @param options.sevenZipExe Location of 7z.exe archiver to create slpk on Windows
179
196
  * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
180
197
  * @param options.token Token for Cesium ION tilesets authentication
181
198
  * @param options.draco Generate I3S 1.7 draco compressed geometries
@@ -185,26 +202,7 @@ export default class I3SConverter {
185
202
  * @param options.instantNodeWriting - Keep created 3DNodeIndexDocument files on disk instead of memory. This option reduce memory usage but decelerates conversion speed
186
203
  */
187
204
  // eslint-disable-next-line max-statements, complexity
188
- async convert(options: {
189
- inputUrl: string;
190
- outputPath: string;
191
- tilesetName: string;
192
- sevenZipExe: string;
193
- egmFilePath: string;
194
- maxDepth?: number;
195
- slpk?: boolean;
196
- token?: string;
197
- draco?: boolean;
198
- mergeMaterials?: boolean;
199
- validate?: boolean;
200
- generateTextures?: boolean;
201
- generateBoundingVolumes?: boolean;
202
- instantNodeWriting?: boolean;
203
- inquirer?: Promise<unknown>;
204
- metadataClass?: string;
205
- analyze?: boolean;
206
- noEgm?: boolean;
207
- }): Promise<string> {
205
+ async convert(options: ConverterProps): Promise<string> {
208
206
  if (isBrowser) {
209
207
  console.log(BROWSER_ERROR_MESSAGE); // eslint-disable-line no-console
210
208
  return BROWSER_ERROR_MESSAGE;
@@ -212,13 +210,11 @@ export default class I3SConverter {
212
210
  this.conversionStartTime = process.hrtime();
213
211
  const {
214
212
  tilesetName,
215
- slpk,
216
213
  egmFilePath,
217
214
  inputUrl,
218
215
  validate,
219
216
  outputPath,
220
217
  draco = true,
221
- sevenZipExe,
222
218
  maxDepth,
223
219
  token,
224
220
  generateTextures,
@@ -227,15 +223,12 @@ export default class I3SConverter {
227
223
  mergeMaterials = true,
228
224
  inquirer,
229
225
  metadataClass,
230
- analyze = false,
231
- noEgm = false
226
+ analyze = false
232
227
  } = options;
233
228
  this.options = {
234
229
  outputPath,
235
230
  tilesetName,
236
231
  maxDepth,
237
- slpk,
238
- sevenZipExe,
239
232
  egmFilePath,
240
233
  draco,
241
234
  token,
@@ -255,17 +248,15 @@ export default class I3SConverter {
255
248
  this.writeQueue = new WriteQueue(this.conversionDump);
256
249
  this.writeQueue.startListening();
257
250
 
258
- if (!noEgm) {
259
- console.log('--no-egm option selected, skip loading egm file'); // eslint-disable-line
251
+ if (egmFilePath.toLowerCase() === 'none') {
252
+ console.log('--egm chousen to be "none", skip loading egm file'); // eslint-disable-line
260
253
  } else {
261
254
  console.log('Loading egm file...'); // eslint-disable-line
262
255
  this.geoidHeightModel = await load(egmFilePath, PGMLoader);
263
256
  console.log('Loading egm file completed!'); // eslint-disable-line
264
257
  }
265
258
 
266
- if (slpk) {
267
- this.nodePages.useWriteFunction(writeFileForSlpk);
268
- }
259
+ this.nodePages.useWriteFunction(writeFileForSlpk);
269
260
 
270
261
  try {
271
262
  const preloadOptions = await this._fetchPreloadOptions();
@@ -285,7 +276,7 @@ export default class I3SConverter {
285
276
  const selectMetadataClassResult = await this.selectMetadataClass();
286
277
  if (selectMetadataClassResult) {
287
278
  await this._createAndSaveTileset(outputPath, tilesetName);
288
- await this._finishConversion({slpk: Boolean(slpk), outputPath, tilesetName});
279
+ await this._finishConversion({outputPath, tilesetName});
289
280
  }
290
281
  }
291
282
  } catch (error) {
@@ -596,17 +587,11 @@ export default class I3SConverter {
596
587
  * Write 3DSceneLayer https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DSceneLayer.cmn.md in file
597
588
  */
598
589
  private async _writeLayers0(): Promise<void> {
599
- if (this.options.slpk) {
600
- await this.writeQueue.enqueue({
601
- archiveKey: '3dSceneLayer.json.gz',
602
- writePromise: () =>
603
- writeFileForSlpk(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json')
604
- });
605
- } else {
606
- await this.writeQueue.enqueue({
607
- writePromise: () => writeFile(this.layers0Path, JSON.stringify(this.layers0))
608
- });
609
- }
590
+ await this.writeQueue.enqueue({
591
+ archiveKey: '3dSceneLayer.json.gz',
592
+ writePromise: () =>
593
+ writeFileForSlpk(this.layers0Path, JSON.stringify(this.layers0), '3dSceneLayer.json')
594
+ });
610
595
  }
611
596
 
612
597
  /**
@@ -615,20 +600,18 @@ export default class I3SConverter {
615
600
  */
616
601
  private async _createSlpk(tilesetPath: string): Promise<void> {
617
602
  await this.conversionDump.deleteDumpFile();
618
- if (this.options.slpk) {
619
- const slpkTilesetPath = join(tilesetPath, 'SceneServer', 'layers', '0');
620
- const slpkFileName = `${tilesetPath}.slpk`;
621
-
622
- await createZip(slpkTilesetPath, slpkFileName, async (fileList) => ({
623
- path: '@specialIndexFileHASH128@',
624
- file: await composeHashFile(fileList)
625
- }));
626
-
627
- try {
628
- await removeDir(tilesetPath);
629
- } catch (e) {
630
- // do nothing
631
- }
603
+ const slpkTilesetPath = join(tilesetPath, 'SceneServer', 'layers', '0');
604
+ const slpkFileName = `${tilesetPath}.slpk`;
605
+
606
+ await createZip(slpkTilesetPath, slpkFileName, async (fileList) => ({
607
+ path: '@specialIndexFileHASH128@',
608
+ file: await composeHashFile(fileList)
609
+ }));
610
+
611
+ try {
612
+ await removeDir(tilesetPath);
613
+ } catch (e) {
614
+ // do nothing
632
615
  }
633
616
  }
634
617
 
@@ -977,9 +960,9 @@ export default class I3SConverter {
977
960
  propertyTable,
978
961
  featuresHashArray: this.featuresHashArray,
979
962
  attributeStorageInfo: this.attributeMetadataInfo.attributeStorageInfo,
980
- draco: this.options.draco,
963
+ draco: this.options.draco ?? false,
981
964
  generateBoundingVolumes: this.generateBoundingVolumes,
982
- shouldMergeMaterials: this.options.mergeMaterials,
965
+ shouldMergeMaterials: this.options.mergeMaterials ?? false,
983
966
  geoidHeightModel: this.geoidHeightModel,
984
967
  libraries: this.loadOptions.modules as Record<string, string>,
985
968
  metadataClass: this.options.metadataClass
@@ -1166,47 +1149,27 @@ export default class I3SConverter {
1166
1149
 
1167
1150
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.GEOMETRY, false);
1168
1151
 
1169
- if (this.options.slpk) {
1170
- const slpkGeometryPath = join(childPath, 'geometries');
1171
- await this.writeQueue.enqueue({
1172
- archiveKey: `${slpkChildPath}/geometries/0.bin.gz`,
1173
- sourceId,
1174
- outputId: nodeId,
1175
- resourceType: ResourceType.GEOMETRY,
1176
- writePromise: () => writeFileForSlpk(slpkGeometryPath, geometryBuffer, '0.bin')
1177
- });
1178
- } else {
1179
- const geometryPath = join(childPath, 'geometries/0/');
1180
- await this.writeQueue.enqueue({
1181
- sourceId,
1182
- outputId: nodeId,
1183
- resourceType: ResourceType.GEOMETRY,
1184
- writePromise: () => writeFile(geometryPath, geometryBuffer, 'index.bin')
1185
- });
1186
- }
1152
+ const slpkGeometryPath = join(childPath, 'geometries');
1153
+ await this.writeQueue.enqueue({
1154
+ archiveKey: `${slpkChildPath}/geometries/0.bin.gz`,
1155
+ sourceId,
1156
+ outputId: nodeId,
1157
+ resourceType: ResourceType.GEOMETRY,
1158
+ writePromise: () => writeFileForSlpk(slpkGeometryPath, geometryBuffer, '0.bin')
1159
+ });
1187
1160
 
1188
1161
  if (this.options.draco && compressedGeometry) {
1189
1162
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.DRACO_GEOMETRY, false);
1190
1163
 
1191
- if (this.options.slpk) {
1192
- const slpkCompressedGeometryPath = join(childPath, 'geometries');
1193
- await this.writeQueue.enqueue({
1194
- archiveKey: `${slpkChildPath}/geometries/1.bin.gz`,
1195
- sourceId,
1196
- outputId: nodeId,
1197
- resourceType: ResourceType.DRACO_GEOMETRY,
1198
- writePromise: () =>
1199
- writeFileForSlpk(slpkCompressedGeometryPath, compressedGeometry, '1.bin')
1200
- });
1201
- } else {
1202
- const compressedGeometryPath = join(childPath, 'geometries/1/');
1203
- await this.writeQueue.enqueue({
1204
- sourceId,
1205
- outputId: nodeId,
1206
- resourceType: ResourceType.DRACO_GEOMETRY,
1207
- writePromise: () => writeFile(compressedGeometryPath, compressedGeometry, 'index.bin')
1208
- });
1209
- }
1164
+ const slpkCompressedGeometryPath = join(childPath, 'geometries');
1165
+ await this.writeQueue.enqueue({
1166
+ archiveKey: `${slpkChildPath}/geometries/1.bin.gz`,
1167
+ sourceId,
1168
+ outputId: nodeId,
1169
+ resourceType: ResourceType.DRACO_GEOMETRY,
1170
+ writePromise: () =>
1171
+ writeFileForSlpk(slpkCompressedGeometryPath, compressedGeometry, '1.bin')
1172
+ });
1210
1173
  }
1211
1174
  }
1212
1175
 
@@ -1241,24 +1204,14 @@ export default class I3SConverter {
1241
1204
  const sharedData = transform(sharedResources, sharedResourcesTemplate());
1242
1205
  const sharedDataStr = JSON.stringify(sharedData);
1243
1206
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.SHARED, false);
1244
- if (this.options.slpk) {
1245
- const slpkSharedPath = join(childPath, 'shared');
1246
- await this.writeQueue.enqueue({
1247
- archiveKey: `${slpkChildPath}/shared/sharedResource.json.gz`,
1248
- sourceId,
1249
- outputId: nodeId,
1250
- resourceType: ResourceType.SHARED,
1251
- writePromise: () => writeFileForSlpk(slpkSharedPath, sharedDataStr, 'sharedResource.json')
1252
- });
1253
- } else {
1254
- const sharedPath = join(childPath, 'shared/');
1255
- await this.writeQueue.enqueue({
1256
- sourceId,
1257
- outputId: nodeId,
1258
- resourceType: ResourceType.SHARED,
1259
- writePromise: () => writeFile(sharedPath, sharedDataStr)
1260
- });
1261
- }
1207
+ const slpkSharedPath = join(childPath, 'shared');
1208
+ await this.writeQueue.enqueue({
1209
+ archiveKey: `${slpkChildPath}/shared/sharedResource.json.gz`,
1210
+ sourceId,
1211
+ outputId: nodeId,
1212
+ resourceType: ResourceType.SHARED,
1213
+ writePromise: () => writeFileForSlpk(slpkSharedPath, sharedDataStr, 'sharedResource.json')
1214
+ });
1262
1215
  }
1263
1216
 
1264
1217
  /**
@@ -1423,27 +1376,17 @@ export default class I3SConverter {
1423
1376
  sourceId: string;
1424
1377
  nodeId: number;
1425
1378
  }): Promise<void> {
1426
- if (this.options.slpk) {
1427
- const slpkTexturePath = join(childPath, 'textures');
1428
- const compress = false;
1429
-
1430
- await this.writeQueue.enqueue({
1431
- archiveKey: `${slpkChildPath}/textures/${name}.${format}`,
1432
- sourceId,
1433
- outputId: nodeId,
1434
- resourceType: `${ResourceType.TEXTURE}/${format}`,
1435
- writePromise: () =>
1436
- writeFileForSlpk(slpkTexturePath, textureData, `${name}.${format}`, compress)
1437
- });
1438
- } else {
1439
- const texturePath = join(childPath, `textures/${name}/`);
1440
- await this.writeQueue.enqueue({
1441
- sourceId,
1442
- outputId: nodeId,
1443
- resourceType: `${ResourceType.TEXTURE}/${format}`,
1444
- writePromise: () => writeFile(texturePath, textureData, `index.${format}`)
1445
- });
1446
- }
1379
+ const slpkTexturePath = join(childPath, 'textures');
1380
+ const compress = false;
1381
+
1382
+ await this.writeQueue.enqueue({
1383
+ archiveKey: `${slpkChildPath}/textures/${name}.${format}`,
1384
+ sourceId,
1385
+ outputId: nodeId,
1386
+ resourceType: `${ResourceType.TEXTURE}/${format}`,
1387
+ writePromise: () =>
1388
+ writeFileForSlpk(slpkTexturePath, textureData, `${name}.${format}`, compress)
1389
+ });
1447
1390
  }
1448
1391
 
1449
1392
  /**
@@ -1476,24 +1419,14 @@ export default class I3SConverter {
1476
1419
  `${ResourceType.ATTRIBUTES}/${folderName}`,
1477
1420
  false
1478
1421
  );
1479
- if (this.options.slpk) {
1480
- const slpkAttributesPath = join(childPath, 'attributes', folderName);
1481
- await this.writeQueue.enqueue({
1482
- archiveKey: `${slpkChildPath}/attributes/${folderName}.bin.gz`,
1483
- sourceId,
1484
- outputId: nodeId,
1485
- resourceType: `${ResourceType.ATTRIBUTES}/${folderName}`,
1486
- writePromise: () => writeFileForSlpk(slpkAttributesPath, fileBuffer, '0.bin')
1487
- });
1488
- } else {
1489
- const attributesPath = join(childPath, `attributes/${folderName}/0`);
1490
- await this.writeQueue.enqueue({
1491
- sourceId,
1492
- outputId: nodeId,
1493
- resourceType: `${ResourceType.ATTRIBUTES}/${folderName}`,
1494
- writePromise: () => writeFile(attributesPath, fileBuffer, 'index.bin')
1495
- });
1496
- }
1422
+ const slpkAttributesPath = join(childPath, 'attributes', folderName);
1423
+ await this.writeQueue.enqueue({
1424
+ archiveKey: `${slpkChildPath}/attributes/${folderName}.bin.gz`,
1425
+ sourceId,
1426
+ outputId: nodeId,
1427
+ resourceType: `${ResourceType.ATTRIBUTES}/${folderName}`,
1428
+ writePromise: () => writeFileForSlpk(slpkAttributesPath, fileBuffer, '0.bin')
1429
+ });
1497
1430
  }
1498
1431
  }
1499
1432
  }
@@ -1586,7 +1519,6 @@ export default class I3SConverter {
1586
1519
  * @param params - output files data
1587
1520
  */
1588
1521
  private async _finishConversion(params: {
1589
- slpk: boolean;
1590
1522
  outputPath: string;
1591
1523
  tilesetName: string;
1592
1524
  }): Promise<void> {
@@ -1594,7 +1526,7 @@ export default class I3SConverter {
1594
1526
  const addRefinementPercentage = tilesWithAddRefineCount
1595
1527
  ? (tilesWithAddRefineCount / tilesCount) * 100
1596
1528
  : 0;
1597
- const filesSize = await calculateFilesSize(params);
1529
+ const filesSize = await calculateDatasetSize(params);
1598
1530
  const diff = process.hrtime(this.conversionStartTime);
1599
1531
  const conversionTime = timeConverter(diff);
1600
1532
  console.log('------------------------------------------------'); // eslint-disable-line no-undef, no-console
@@ -1616,7 +1548,7 @@ export default class I3SConverter {
1616
1548
  const options = {
1617
1549
  'cesium-ion': {accessToken: this.options.token || ION_DEFAULT_TOKEN}
1618
1550
  };
1619
- const preloadOptions = await this.Loader.preload(this.options.inputUrl, options);
1551
+ const preloadOptions = await this.Loader.preload(this.options.inputUrl ?? '', options);
1620
1552
  this.refreshTokenTime = process.hrtime();
1621
1553
  return {...options, ...preloadOptions};
1622
1554
  }
@@ -5,7 +5,6 @@ import cors from 'cors';
5
5
  // For local debug
6
6
  // import {fileURLToPath} from 'url';
7
7
  import {loadArchive} from './controllers/slpk-controller';
8
- import {router as indexRouter} from './routes';
9
8
  import {sceneServerRouter, router} from './routes/slpk-router';
10
9
 
11
10
  // For local debug
@@ -15,15 +14,15 @@ import {sceneServerRouter, router} from './routes/slpk-router';
15
14
  const I3S_LAYER_PATH = process.env.I3sLayerPath || ''; // eslint-disable-line no-process-env, no-undef
16
15
  const FULL_LAYER_PATH = path.join(process.cwd(), I3S_LAYER_PATH); // eslint-disable-line no-undef
17
16
 
18
- export const app = express();
19
-
20
- app.use(logger('dev'));
21
- app.use(express.json());
22
- app.use(express.urlencoded({extended: false}));
23
- app.use(express.static(path.join(__dirname, 'public')));
24
- app.use(cors());
17
+ export let app: ReturnType<typeof express> | undefined;
25
18
 
26
19
  if (/\.slpk$/.test(I3S_LAYER_PATH)) {
20
+ app = express();
21
+ app.use(logger('dev'));
22
+ app.use(express.json());
23
+ app.use(express.urlencoded({extended: false}));
24
+ app.use(express.static(path.join(__dirname, 'public')));
25
+ app.use(cors());
27
26
  let filePath = FULL_LAYER_PATH;
28
27
  // Checks if the first character is not a point to indicate absolute path
29
28
  const absolutePath = /^[^.]/.exec(I3S_LAYER_PATH);
@@ -33,6 +32,4 @@ if (/\.slpk$/.test(I3S_LAYER_PATH)) {
33
32
  loadArchive(filePath);
34
33
  app.use('/SceneServer/layers/0', router);
35
34
  app.use('/SceneServer', sceneServerRouter);
36
- } else {
37
- app.use('/', indexRouter);
38
35
  }
@@ -33,6 +33,12 @@ const options = {
33
33
  cert: fs.readFileSync(path.join(__dirname, '../certs/cert.pem'))
34
34
  };
35
35
 
36
+ if (!app) {
37
+ // eslint-disable-next-line no-console
38
+ console.error('This server supports *.slpk files only');
39
+ process.exit(1); // eslint-disable-line no-process-exit
40
+ }
41
+
36
42
  const httpServer = http.createServer(app);
37
43
  const httpsServer = https.createServer(options, app);
38
44
 
@@ -49,7 +49,19 @@ function timeConverterFromSecondsAndMilliseconds(timeInSeconds: number, millisec
49
49
  return result;
50
50
  }
51
51
 
52
- export async function calculateFilesSize(params) {
52
+ /**
53
+ * Calculates overall datatset size
54
+ * @param params - params object
55
+ * @param params.slpk - if dataset is in slpk format
56
+ * @param params.outputPath - path to the folder containing the dataset
57
+ * @param params.tilesetName - tileset name
58
+ * @returns dataset size in bytes
59
+ */
60
+ export async function calculateDatasetSize(params: {
61
+ slpk?: boolean;
62
+ outputPath: string;
63
+ tilesetName: string;
64
+ }): Promise<number | null> {
53
65
  const {slpk, outputPath, tilesetName} = params;
54
66
  const fullOutputPath = getAbsoluteFilePath(outputPath);
55
67
 
@@ -61,7 +73,7 @@ export async function calculateFilesSize(params) {
61
73
  }
62
74
 
63
75
  const directoryPath = join(fullOutputPath, tilesetName);
64
- const totalSize = await getTotalFilesSize(directoryPath);
76
+ const totalSize = await getDirectorySize(directoryPath);
65
77
  return totalSize;
66
78
  } catch (error) {
67
79
  console.log('Calculate file sizes error: ', error); // eslint-disable-line
@@ -69,7 +81,12 @@ export async function calculateFilesSize(params) {
69
81
  }
70
82
  }
71
83
 
72
- async function getTotalFilesSize(dirPath) {
84
+ /**
85
+ * Calculates directory size
86
+ * @param dirPath - path to the directory
87
+ * @returns directory size in bytes
88
+ */
89
+ async function getDirectorySize(dirPath: string): Promise<number> {
73
90
  let totalFileSize = 0;
74
91
 
75
92
  const files = await fs.readdir(dirPath);
@@ -77,7 +94,7 @@ async function getTotalFilesSize(dirPath) {
77
94
  for (const file of files) {
78
95
  const fileStat = await fs.stat(join(dirPath, file));
79
96
  if (fileStat.isDirectory()) {
80
- totalFileSize += await getTotalFilesSize(join(dirPath, file));
97
+ totalFileSize += await getDirectorySize(join(dirPath, file));
81
98
  } else {
82
99
  totalFileSize += fileStat.size;
83
100
  }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../dist/slpk-extractor.min.cjs';
@@ -1,8 +0,0 @@
1
- /**
2
- * Get local file name by input HTTP URL
3
- * @param url - I3S HTTP service url
4
- * @param i3sLayerPath - I3S layer path
5
- * @returns - local file name
6
- */
7
- export declare function getFileNameByUrl(url: string, i3sLayerPath?: string): Promise<string | null>;
8
- //# sourceMappingURL=index-controller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-controller.d.ts","sourceRoot":"","sources":["../../../src/i3s-server/controllers/index-controller.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,SAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoB7F"}
@@ -1,31 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- const { promises } = fs;
4
- /**
5
- * Get local file name by input HTTP URL
6
- * @param url - I3S HTTP service url
7
- * @param i3sLayerPath - I3S layer path
8
- * @returns - local file name
9
- */
10
- export async function getFileNameByUrl(url, i3sLayerPath = '') {
11
- i3sLayerPath = i3sLayerPath || process.env.I3sLayerPath || '';
12
- const extensions = ['json', 'bin', 'jpg', 'jpeg', 'png', 'bin.dds', 'ktx2'];
13
- let filePath = process.cwd();
14
- // Checks if the first character is not a point to indicate absolute path
15
- const absolutePath = /^[^.]/.exec(i3sLayerPath);
16
- if (absolutePath) {
17
- filePath = '';
18
- }
19
- const FULL_LAYER_PATH = path.join(filePath, i3sLayerPath, url);
20
- for (const ext of extensions) {
21
- const fileName = `${FULL_LAYER_PATH}/index.${ext}`;
22
- try {
23
- await promises.access(fileName);
24
- return fileName;
25
- }
26
- catch {
27
- continue; // eslint-disable-line no-continue
28
- }
29
- }
30
- return null;
31
- }
@@ -1,2 +0,0 @@
1
- export declare const router: import("express-serve-static-core").Router;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/i3s-server/routes/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,4CAAmB,CAAC"}
@@ -1,17 +0,0 @@
1
- import express from 'express';
2
- import { getFileNameByUrl } from "../controllers/index-controller.js";
3
- export const router = express.Router();
4
- /* GET home page. */
5
- router.get('*', (req, res, next) => {
6
- async function routerCallback(req, res, next) {
7
- const fileName = await getFileNameByUrl(req.path);
8
- if (fileName) {
9
- res.sendFile(fileName);
10
- }
11
- else {
12
- res.status(404);
13
- res.send('File not found');
14
- }
15
- }
16
- routerCallback(req, res, next);
17
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Converts time value to string.
3
- * @param time - high-resolution real time in a [seconds, nanoseconds] tuple Array, or a value on milliseconds.
4
- * @returns string representation of the time
5
- */
6
- export declare function timeConverter(time: number | [number, number]): string;
7
- export declare function calculateFilesSize(params: any): Promise<number | null>;
8
- //# sourceMappingURL=statistic-utills.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"statistic-utills.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/statistic-utills.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAarE;AA6BD,wBAAsB,kBAAkB,CAAC,MAAM,KAAA,0BAkB9C"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Converter from slpk to i3s
3
- */
4
- export default class SLPKExtractor {
5
- /**
6
- * Extract slpk to i3s
7
- * @param options
8
- * @param options.inputUrl the url to read SLPK file
9
- * @param options.outputPath the output filename
10
- */
11
- extract(options: {
12
- inputUrl: string;
13
- outputPath: string;
14
- }): Promise<string>;
15
- /**
16
- * Defines file name and path for i3s format
17
- * @param fileName initial file name and path
18
- */
19
- private correctIndexNames;
20
- private unGzip;
21
- private writeFile;
22
- }
23
- //# sourceMappingURL=slpk-extractor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slpk-extractor.d.ts","sourceRoot":"","sources":["../../src/slpk-extractor/slpk-extractor.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BtF;;;OAGG;IAEH,OAAO,CAAC,iBAAiB;YAYX,MAAM;YAWN,SAAS;CASxB"}