bruce-models 1.7.9 → 1.8.1

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.
@@ -3844,9 +3844,6 @@ var EntityTag;
3844
3844
  function Update(params) {
3845
3845
  return __awaiter(this, void 0, void 0, function* () {
3846
3846
  const { api, tag: data, req: reqParams } = params;
3847
- if (!(data === null || data === void 0 ? void 0 : data.ID)) {
3848
- throw ("Tag ID is required.");
3849
- }
3850
3847
  const url = data.ID ? `layer/${data.ID}` : "layer";
3851
3848
  const res = yield api.POST(url, data, Api.PrepReqParams(reqParams));
3852
3849
  api.Cache.Remove(GetCacheKey(data.ID));
@@ -4720,6 +4717,69 @@ var EntityAttribute;
4720
4717
  EntityAttribute.GetAttribute = GetAttribute;
4721
4718
  })(EntityAttribute || (EntityAttribute = {}));
4722
4719
 
4720
+ var Uploader;
4721
+ (function (Uploader) {
4722
+ Uploader.MIN_LARGE_FILE_SIZE = 100000000; // 100MB.
4723
+ function DoMultiPartUpload(params) {
4724
+ return __awaiter(this, void 0, void 0, function* () {
4725
+ const { file, api, urlSuffix: url, req, onProgress } = params;
4726
+ const FILE_PORTION_SIZE = 100000000; // 100MB.
4727
+ let fileSize = file.size;
4728
+ let fileOffset = 0;
4729
+ let filePartsCount = fileSize / FILE_PORTION_SIZE;
4730
+ let t = Math.trunc(filePartsCount);
4731
+ filePartsCount = filePartsCount > t ? t + 1 : t;
4732
+ let filePartIndex = 1;
4733
+ let uploadToken = ObjectUtils.UId();
4734
+ let data;
4735
+ while (fileOffset < fileSize) {
4736
+ let partSize = Math.min(FILE_PORTION_SIZE, fileSize - fileOffset);
4737
+ let retryCount = 5;
4738
+ let retryWait = 1000;
4739
+ while (retryCount > 0) {
4740
+ try {
4741
+ const blob = file.slice(fileOffset, fileOffset + partSize);
4742
+ const formData = new FormData();
4743
+ formData.append("originalFileName", file.name);
4744
+ formData.append("token", uploadToken);
4745
+ formData.append("count", "" + filePartsCount);
4746
+ formData.append("part", "" + filePartIndex);
4747
+ formData.append("file", blob);
4748
+ const reqParams = Api.PrepReqParams(req);
4749
+ reqParams.formData = formData;
4750
+ reqParams.onProgress = (progress) => {
4751
+ const sofar = fileOffset + progress.loaded;
4752
+ const percent = Math.round((sofar / file.size) * 100);
4753
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4754
+ percent: percent,
4755
+ uploaded: false
4756
+ });
4757
+ };
4758
+ data = yield api.UPLOAD(url, blob, reqParams);
4759
+ retryCount = 0;
4760
+ }
4761
+ catch (up) {
4762
+ retryCount -= 1;
4763
+ if (retryCount <= 0) {
4764
+ throw up;
4765
+ }
4766
+ yield new Promise((res) => setTimeout(res, retryWait));
4767
+ retryWait = retryWait * 2;
4768
+ }
4769
+ }
4770
+ fileOffset += partSize;
4771
+ filePartIndex++;
4772
+ }
4773
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4774
+ percent: 100,
4775
+ uploaded: true
4776
+ });
4777
+ return data;
4778
+ });
4779
+ }
4780
+ Uploader.DoMultiPartUpload = DoMultiPartUpload;
4781
+ })(Uploader || (Uploader = {}));
4782
+
4723
4783
  /**
4724
4784
  * Describes the "Client File" concept within Bruce.
4725
4785
  * A client file is a record of a file uploaded to Bruce.
@@ -4786,33 +4846,67 @@ var ClientFile;
4786
4846
  ClientFile.Delete = Delete;
4787
4847
  function Upload(params) {
4788
4848
  return __awaiter(this, void 0, void 0, function* () {
4789
- const { api, file, purpose, req } = params;
4849
+ const { api, file, purpose, req, onProgress } = params;
4790
4850
  if (!file) {
4791
4851
  throw ("File is required.");
4792
4852
  }
4793
- let formData = null;
4794
- if (purpose) {
4795
- formData = {
4796
- "Purpose": purpose
4797
- };
4853
+ const size = file === null || file === void 0 ? void 0 : file.size;
4854
+ if (!size) {
4855
+ throw ("You cannot upload a 0byte sized file.");
4798
4856
  }
4799
- const reqParams = Api.PrepReqParams(req);
4800
- reqParams.formData = formData;
4801
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
4802
- try {
4803
- const data = yield api.UPLOAD("file/uploadNew", file, reqParams);
4804
- res({
4805
- clientFile: data
4857
+ let clientFile;
4858
+ if (size > Uploader.MIN_LARGE_FILE_SIZE) {
4859
+ clientFile = yield Uploader.DoMultiPartUpload({
4860
+ api,
4861
+ file,
4862
+ urlSuffix: "fileUpload",
4863
+ req,
4864
+ onProgress
4865
+ });
4866
+ }
4867
+ else {
4868
+ const reqParams = Api.PrepReqParams(Object.assign({}, req));
4869
+ reqParams.onProgress = (progress) => {
4870
+ const percent = Math.round((progress.loaded / file.size) * 100);
4871
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4872
+ percent: percent,
4873
+ uploaded: false
4806
4874
  });
4807
- }
4808
- catch (e) {
4809
- rej(e);
4810
- }
4811
- }));
4812
- return prom;
4875
+ };
4876
+ clientFile = yield api.UPLOAD("file/uploadNew", file, req);
4877
+ }
4878
+ if ((clientFile === null || clientFile === void 0 ? void 0 : clientFile.ID) && purpose) {
4879
+ yield UpdatePurpose({
4880
+ api,
4881
+ fileId: clientFile.ID,
4882
+ purpose,
4883
+ req
4884
+ });
4885
+ }
4886
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4887
+ percent: 100,
4888
+ uploaded: true
4889
+ });
4890
+ return {
4891
+ clientFile
4892
+ };
4813
4893
  });
4814
4894
  }
4815
4895
  ClientFile.Upload = Upload;
4896
+ function UpdatePurpose(params) {
4897
+ return __awaiter(this, void 0, void 0, function* () {
4898
+ let { api, fileId, purpose, req: reqParams } = params;
4899
+ if (!purpose) {
4900
+ purpose = "";
4901
+ }
4902
+ yield api.POST("file/updatepurpose/" + fileId + "/?Purpose=" + purpose, {
4903
+ Purpose: purpose
4904
+ }, Api.PrepReqParams(reqParams));
4905
+ const cacheKey = GetCacheKey(fileId);
4906
+ api.Cache.RemoveByContains(cacheKey);
4907
+ });
4908
+ }
4909
+ ClientFile.UpdatePurpose = UpdatePurpose;
4816
4910
  /**
4817
4911
  * Uploads a temp file.
4818
4912
  * This will return a temp file id which can be used in various endpoints.
@@ -4821,23 +4915,41 @@ var ClientFile;
4821
4915
  */
4822
4916
  function UploadTemp(params) {
4823
4917
  return __awaiter(this, void 0, void 0, function* () {
4824
- const { api, file, req } = params;
4918
+ const { api, file, req, onProgress } = params;
4825
4919
  if (!file) {
4826
4920
  throw ("File is required.");
4827
4921
  }
4828
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
4829
- try {
4830
- const reqParams = Api.PrepReqParams(req);
4831
- const data = yield api.UPLOAD("file/uploadTemp", file, reqParams);
4832
- res({
4833
- tempFileId: data["TempFile.ID"]
4922
+ const size = file === null || file === void 0 ? void 0 : file.size;
4923
+ if (!size) {
4924
+ throw ("You cannot upload a 0byte sized file.");
4925
+ }
4926
+ let tempFile;
4927
+ if (size > Uploader.MIN_LARGE_FILE_SIZE) {
4928
+ tempFile = yield Uploader.DoMultiPartUpload({
4929
+ api,
4930
+ file,
4931
+ urlSuffix: "tempFileUpload",
4932
+ req,
4933
+ onProgress
4934
+ });
4935
+ }
4936
+ else {
4937
+ req.onProgress = (progress) => {
4938
+ const percent = Math.round((progress.loaded / file.size) * 100);
4939
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4940
+ percent: percent,
4941
+ uploaded: false
4834
4942
  });
4835
- }
4836
- catch (e) {
4837
- rej(e);
4838
- }
4839
- }));
4840
- return prom;
4943
+ };
4944
+ tempFile = yield api.UPLOAD("file/uploadTemp", file, req);
4945
+ }
4946
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
4947
+ percent: 100,
4948
+ uploaded: true
4949
+ });
4950
+ return {
4951
+ tempFileId: tempFile["TempFile.ID"]
4952
+ };
4841
4953
  });
4842
4954
  }
4843
4955
  ClientFile.UploadTemp = UploadTemp;
@@ -5168,11 +5280,38 @@ var Tileset;
5168
5280
  Tileset.Update = Update;
5169
5281
  function UploadFile(params) {
5170
5282
  return __awaiter(this, void 0, void 0, function* () {
5171
- const { api, tilesetId, file, req: reqParams } = params;
5283
+ const { api, file, req, tilesetId, onProgress } = params;
5172
5284
  if (!tilesetId || !file) {
5173
5285
  throw ("Tileset ID and file are required.");
5174
5286
  }
5175
- return api.UPLOAD(`tileset/uploadFile/${tilesetId}/files`, file, Api.PrepReqParams(reqParams));
5287
+ const size = file === null || file === void 0 ? void 0 : file.size;
5288
+ if (!size) {
5289
+ throw ("You cannot upload a 0byte sized file.");
5290
+ }
5291
+ if (size > Uploader.MIN_LARGE_FILE_SIZE) {
5292
+ yield Uploader.DoMultiPartUpload({
5293
+ api,
5294
+ file,
5295
+ urlSuffix: `tileset/uploadFileEx/${tilesetId}/add`,
5296
+ req,
5297
+ onProgress
5298
+ });
5299
+ }
5300
+ else {
5301
+ req.onProgress = (progress) => {
5302
+ const percent = Math.round((progress.loaded / file.size) * 100);
5303
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
5304
+ percent: percent,
5305
+ uploaded: false
5306
+ });
5307
+ };
5308
+ yield api.UPLOAD(`tileset/uploadFile/${tilesetId}/files`, file, req);
5309
+ }
5310
+ api.Cache.Remove(GetCacheKey(tilesetId, true));
5311
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
5312
+ percent: 100,
5313
+ uploaded: true
5314
+ });
5176
5315
  });
5177
5316
  }
5178
5317
  Tileset.UploadFile = UploadFile;
@@ -5189,12 +5328,39 @@ var Tileset;
5189
5328
  Tileset.DeleteFile = DeleteFile;
5190
5329
  function UploadSrcFile(params) {
5191
5330
  return __awaiter(this, void 0, void 0, function* () {
5192
- const { api, tilesetId, file, req: reqParams } = params;
5331
+ const { api, file, req, tilesetId, onProgress } = params;
5193
5332
  if (!tilesetId || !file) {
5194
5333
  throw ("Tileset ID and file are required.");
5195
5334
  }
5196
- yield api.UPLOAD(`tileset/uploadFile/${tilesetId}/src`, file, Api.PrepReqParams(reqParams));
5335
+ const size = file === null || file === void 0 ? void 0 : file.size;
5336
+ if (!size) {
5337
+ throw ("You cannot upload a 0byte sized file.");
5338
+ }
5339
+ if (size > Uploader.MIN_LARGE_FILE_SIZE) {
5340
+ yield Uploader.DoMultiPartUpload({
5341
+ api,
5342
+ file,
5343
+ urlSuffix: `tileset/uploadFileEx/${tilesetId}/src`,
5344
+ req,
5345
+ onProgress
5346
+ });
5347
+ }
5348
+ else {
5349
+ req.onProgress = (progress) => {
5350
+ const percent = Math.round((progress.loaded / file.size) * 100);
5351
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
5352
+ percent: percent,
5353
+ uploaded: false
5354
+ });
5355
+ };
5356
+ yield api.UPLOAD(`tileset/uploadFile/${tilesetId}/src`, file, req);
5357
+ }
5197
5358
  api.Cache.Remove(GetCacheKey(tilesetId, true));
5359
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
5360
+ percent: 100,
5361
+ uploaded: true
5362
+ });
5363
+ return;
5198
5364
  });
5199
5365
  }
5200
5366
  Tileset.UploadSrcFile = UploadSrcFile;
@@ -7220,5 +7386,5 @@ var Markup;
7220
7386
  })(Circle = Markup.Circle || (Markup.Circle = {}));
7221
7387
  })(Markup || (Markup = {}));
7222
7388
 
7223
- export { AnnDocument, CustomForm, CustomFormContent, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, MessageBroker, Style, Tileset, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup };
7389
+ export { AnnDocument, CustomForm, CustomFormContent, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, MessageBroker, Style, Tileset, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader };
7224
7390
  //# sourceMappingURL=bruce-models.es5.js.map