tnx-shared 5.8.1 → 5.8.3

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.
@@ -24801,6 +24801,16 @@ class FileObjectService extends BaseService {
24801
24801
  const url = `${this.serviceUri}/UploadWithByteArray`;
24802
24802
  return this._http.post(url, formData, { responseType: 'text' }).toPromise();
24803
24803
  }
24804
+ UploadExternalImage(url) {
24805
+ const options = {
24806
+ headers: new HttpHeaders({
24807
+ 'Content-Type': 'application/json-patch+json',
24808
+ }),
24809
+ responseType: 'text',
24810
+ };
24811
+ const apiUrl = `${this.serviceUri}/UploadExternalImage`;
24812
+ return this._http.post(apiUrl, { url: url }, options).toPromise();
24813
+ }
24804
24814
  }
24805
24815
  FileObjectService.ɵprov = ɵɵdefineInjectable({ factory: function FileObjectService_Factory() { return new FileObjectService(ɵɵinject(HttpClient), ɵɵinject(INJECTOR), ɵɵinject(ModuleConfigService)); }, token: FileObjectService, providedIn: "root" });
24806
24816
  FileObjectService.decorators = [
@@ -32550,9 +32560,9 @@ class FilePickerDialogComponent extends DataFormBase {
32550
32560
  else if (element.extension.toUpperCase() == '.MP4' || element.extension.toUpperCase() == '.AVI' || element.extension.toUpperCase() == '.MOV' || element.extension.toUpperCase() == '.WMV' || element.extension.toUpperCase() == '.FLV') {
32551
32561
  result = '<div style="width:100%; margin-bottom: 15px"><video style="display: block;margin-left: auto;margin-right: auto;" width="500" height="auto" controls><source src="' + this._fileObjectService.endPoint + '/v5/FileObject/public/' + element.id + '/download" type="video/mp4"></video></div>';
32552
32562
  }
32553
- else if (element.extension.toUpperCase() == '.PDF') {
32554
- result = '<div style="width:100%; margin-bottom: 15px"><iframe style="aspect-ratio: 9/16;"" src="' + this._fileObjectService.endPoint + '/v5/FileObject/public/' + element.id + '/download" width="100%"></iframe></div>';
32555
- }
32563
+ // else if (element.extension.toUpperCase() == '.PDF') {
32564
+ // result = '<div style="width:100%; margin-bottom: 15px"><iframe style="aspect-ratio: 9/16;"" src="' + this._fileObjectService.endPoint + '/v5/FileObject/public/' + element.id + '/download" width="100%"></iframe></div>';
32565
+ // }
32556
32566
  else {
32557
32567
  result = '<a style="width:100%; margin-bottom: 15px" href="' + this._fileObjectService.endPoint + '/v5/FileObject/public/' + element.id + '/download">' + element.name + '</a>';
32558
32568
  }
@@ -53067,6 +53077,7 @@ class TnTinymceComponent extends ComponentBase {
53067
53077
  '/assets/vendor/tinymce/custom.css'
53068
53078
  ],
53069
53079
  imagetools_toolbar: 'rotateleft rotateright | flipv fliph | editimage imageoptions',
53080
+ contextmenu: 'link image imagetools table',
53070
53081
  language: 'vi_VN',
53071
53082
  statusbar: false,
53072
53083
  relative_urls: false,
@@ -53180,7 +53191,48 @@ class TnTinymceComponent extends ComponentBase {
53180
53191
  };
53181
53192
  if (types.indexOf('text/html') !== -1) {
53182
53193
  if (pastedData.indexOf('<v:imagedata ') == -1) {
53183
- resolve(pastedData);
53194
+ // Parse HTML
53195
+ let docm = new DOMParser().parseFromString(pastedData, 'text/html');
53196
+ let imgTags = docm.getElementsByTagName('img');
53197
+ const imageUploaded = [];
53198
+ for (let i = 0; i < imgTags.length; i++) {
53199
+ let src = imgTags[i].src;
53200
+ try {
53201
+ if (src.startsWith('data:image/')) {
53202
+ // Case base64
53203
+ const imageType = src.substring(5, src.indexOf(';'));
53204
+ const base64 = src.substring(src.indexOf('base64,') + 7);
53205
+ const imageBlob = this.dataURItoBlob(base64, imageType);
53206
+ const file = new File([imageBlob], `paste_${Date.now()}_${i}.png`, { type: imageType });
53207
+ const uploadImage = yield this._fileObjectService.uploadWithByteArray(file);
53208
+ if (typeof uploadImage == 'string') {
53209
+ imgTags[i].src = this._fileObjectService.getUrlImage(uploadImage);
53210
+ imageUploaded.push(imgTags[i].src);
53211
+ }
53212
+ }
53213
+ else if (src.startsWith('http')) {
53214
+ // Case link ảnh từ web khác
53215
+ try {
53216
+ const uploadImage = yield this._fileObjectService.UploadExternalImage(src);
53217
+ if (typeof uploadImage == 'string') {
53218
+ imgTags[i].src = this._fileObjectService.getUrlImage(uploadImage);
53219
+ imageUploaded.push(imgTags[i].src);
53220
+ }
53221
+ }
53222
+ catch (err) {
53223
+ console.error('Skip external image:', err);
53224
+ imageUploaded.push(src);
53225
+ }
53226
+ }
53227
+ }
53228
+ catch (err) {
53229
+ console.error('Paste image error:', err);
53230
+ this._notifierService.showWarning('Upload ảnh khi dán nội dung thất bại');
53231
+ }
53232
+ }
53233
+ // Serialize lại HTML sau khi thay link ảnh
53234
+ const result = new XMLSerializer().serializeToString(docm);
53235
+ resolve(result);
53184
53236
  }
53185
53237
  else {
53186
53238
  if (types.indexOf('text/rtf') !== -1) {