@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.
@@ -1136,6 +1136,7 @@
1136
1136
  this.loadingText = 'ImgManager.ImgUpload.loading';
1137
1137
  this.errorUploadingImg = 'ImgManager.ImgUpload.errorUploadingImg';
1138
1138
  this.errorNotImg = 'ImgManager.ImgUpload.errorNotImg';
1139
+ this.MAX_IMAGE_SIZE = 10000000; // In bytes
1139
1140
  }
1140
1141
  ImgUploadComponent.prototype.ngOnInit = function () {
1141
1142
  this.assetsIcon = this.getAssets();
@@ -1161,13 +1162,19 @@
1161
1162
  try {
1162
1163
  for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
1163
1164
  var file = files_1_1.value;
1164
- var formData = new FormData();
1165
- formData.append('image', file, file.name);
1165
+ console.log('file', file.size);
1166
1166
  if (!this.isFileImage(file.type)) {
1167
1167
  this.alertService.openAlert(this.errorNotImg);
1168
1168
  this.isLoading = false;
1169
1169
  continue;
1170
1170
  }
1171
+ if (!this.isSizeValid(file.size)) {
1172
+ 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");
1173
+ this.isLoading = false;
1174
+ continue;
1175
+ }
1176
+ var formData = new FormData();
1177
+ formData.append('image', file, file.name);
1171
1178
  imgToUploadList.push(this.imgManager.uploadFile(formData));
1172
1179
  }
1173
1180
  }
@@ -1182,7 +1189,13 @@
1182
1189
  _this.onImgUpload(img),
1183
1190
  _this.isLoading = false;
1184
1191
  }, function (error) {
1185
- _this.alertService.openAlert(_this.errorUploadingImg);
1192
+ var _a, _b;
1193
+ if (((_b = (_a = error) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.message) && error.statusText !== 'Bad Request') {
1194
+ _this.alertService.openAlertWithBackendRespons(_this.errorUploadingImg, error.error.message);
1195
+ }
1196
+ else {
1197
+ _this.alertService.openAlert(_this.errorUploadingImg);
1198
+ }
1186
1199
  _this.isLoading = false;
1187
1200
  });
1188
1201
  };
@@ -1197,6 +1210,12 @@
1197
1210
  ImgUploadComponent.prototype.isFileImage = function (fileType) {
1198
1211
  return fileType.split('/')[0] === 'image';
1199
1212
  };
1213
+ ImgUploadComponent.prototype.isSizeValid = function (imageBytesSize) {
1214
+ return imageBytesSize < this.MAX_IMAGE_SIZE;
1215
+ };
1216
+ ImgUploadComponent.prototype.getImageSizeInKo = function (size) {
1217
+ return Math.round(size / 1024);
1218
+ };
1200
1219
  /**
1201
1220
  * Remove the style of the drag and drop box
1202
1221
  * After an img is droped, the box is still grey