Browse Source

Merge pull request #14377 from DmytroKhylko/fix/js-resource-data-encoding

Fix js module file encoding to include handling of special symbols
pull/14388/head
Vladyslav Prykhodko 10 months ago
committed by GitHub
parent
commit
49690aabae
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      ui-ngx/src/app/modules/home/pages/admin/resource/js-resource.component.ts

8
ui-ngx/src/app/modules/home/pages/admin/resource/js-resource.component.ts

@ -32,7 +32,7 @@ import {
} from '@shared/models/resource.models'; } from '@shared/models/resource.models';
import { startWith, takeUntil } from 'rxjs/operators'; import { startWith, takeUntil } from 'rxjs/operators';
import { ActionNotificationShow } from '@core/notification/notification.actions'; import { ActionNotificationShow } from '@core/notification/notification.actions';
import { isDefinedAndNotNull } from '@core/utils'; import { base64toString, isDefinedAndNotNull, stringToBase64 } from '@core/utils';
import { getCurrentAuthState } from '@core/auth/auth.selectors'; import { getCurrentAuthState } from '@core/auth/auth.selectors';
@Component({ @Component({
@ -84,13 +84,13 @@ export class JsResourceComponent extends EntityComponent<Resource> implements On
resourceSubType: [entity?.resourceSubType ? entity.resourceSubType : ResourceSubType.EXTENSION, Validators.required], resourceSubType: [entity?.resourceSubType ? entity.resourceSubType : ResourceSubType.EXTENSION, Validators.required],
fileName: [entity ? entity.fileName : null, Validators.required], fileName: [entity ? entity.fileName : null, Validators.required],
data: [entity ? entity.data : null, this.isAdd ? [Validators.required] : []], data: [entity ? entity.data : null, this.isAdd ? [Validators.required] : []],
content: [entity?.data?.length ? window.atob(entity.data) : '', Validators.required] content: [entity?.data?.length ? base64toString(entity.data) : '', Validators.required]
}); });
} }
updateForm(entity: Resource): void { updateForm(entity: Resource): void {
this.entityForm.patchValue(entity); this.entityForm.patchValue(entity);
const content = entity.resourceSubType === ResourceSubType.MODULE && entity?.data?.length ? window.atob(entity.data) : ''; const content = entity.resourceSubType === ResourceSubType.MODULE && entity?.data?.length ? base64toString(entity.data) : '';
this.entityForm.get('content').patchValue(content); this.entityForm.get('content').patchValue(content);
} }
@ -110,7 +110,7 @@ export class JsResourceComponent extends EntityComponent<Resource> implements On
if (!formValue.fileName) { if (!formValue.fileName) {
formValue.fileName = formValue.title + '.js'; formValue.fileName = formValue.title + '.js';
} }
formValue.data = window.btoa((formValue as any).content); formValue.data = stringToBase64((formValue as any).content);
delete (formValue as any).content; delete (formValue as any).content;
} }
return super.prepareFormValue(formValue); return super.prepareFormValue(formValue);

Loading…
Cancel
Save