@wizishop/img-manager 0.2.100 → 0.2.101

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.
@@ -935,6 +935,7 @@ var ImgUploadComponent = /** @class */ (function () {
935
935
  this.loadingText = 'ImgManager.ImgUpload.loading';
936
936
  this.errorUploadingImg = 'ImgManager.ImgUpload.errorUploadingImg';
937
937
  this.errorNotImg = 'ImgManager.ImgUpload.errorNotImg';
938
+ this.MAX_IMAGE_SIZE = 10000000; // In bytes
938
939
  }
939
940
  ImgUploadComponent.prototype.ngOnInit = function () {
940
941
  this.assetsIcon = this.getAssets();
@@ -960,13 +961,19 @@ var ImgUploadComponent = /** @class */ (function () {
960
961
  try {
961
962
  for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
962
963
  var file = files_1_1.value;
963
- var formData = new FormData();
964
- formData.append('image', file, file.name);
964
+ console.log('file', file.size);
965
965
  if (!this.isFileImage(file.type)) {
966
966
  this.alertService.openAlert(this.errorNotImg);
967
967
  this.isLoading = false;
968
968
  continue;
969
969
  }
970
+ if (!this.isSizeValid(file.size)) {
971
+ this.alertService.openAlert("L'image : " + file.name + " est trop grande (" + this.getImageSizeInKo(file.size) + "ko). Taille maximum accept\u00E9e: " + this.getImageSizeInKo(this.MAX_IMAGE_SIZE) + "ko");
972
+ this.isLoading = false;
973
+ continue;
974
+ }
975
+ var formData = new FormData();
976
+ formData.append('image', file, file.name);
970
977
  imgToUploadList.push(this.imgManager.uploadFile(formData));
971
978
  }
972
979
  }
@@ -981,7 +988,13 @@ var ImgUploadComponent = /** @class */ (function () {
981
988
  _this.onImgUpload(img),
982
989
  _this.isLoading = false;
983
990
  }, function (error) {
984
- _this.alertService.openAlert(_this.errorUploadingImg);
991
+ var _a, _b;
992
+ if (((_b = (_a = error) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) && error.statusText !== 'Bad Request') {
993
+ _this.alertService.openAlertWithBackendRespons(_this.errorUploadingImg, error.error.message);
994
+ }
995
+ else {
996
+ _this.alertService.openAlert(_this.errorUploadingImg);
997
+ }
985
998
  _this.isLoading = false;
986
999
  });
987
1000
  };
@@ -996,6 +1009,12 @@ var ImgUploadComponent = /** @class */ (function () {
996
1009
  ImgUploadComponent.prototype.isFileImage = function (fileType) {
997
1010
  return fileType.split('/')[0] === 'image';
998
1011
  };
1012
+ ImgUploadComponent.prototype.isSizeValid = function (imageBytesSize) {
1013
+ return imageBytesSize < this.MAX_IMAGE_SIZE;
1014
+ };
1015
+ ImgUploadComponent.prototype.getImageSizeInKo = function (size) {
1016
+ return Math.round(size / 1024);
1017
+ };
999
1018
  /**
1000
1019
  * Remove the style of the drag and drop box
1001
1020
  * After an img is droped, the box is still grey