UI: decode base64 and return normal value
This commit is contained in:
parent
58461c8106
commit
6a91c6418d
@ -185,6 +185,12 @@ export function objToBase64(obj: any): string {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function base64toString(b64Encoded: string): string {
|
||||||
|
return decodeURIComponent(atob(b64Encoded).split('').map((c) => {
|
||||||
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
|
}).join(''));
|
||||||
|
}
|
||||||
|
|
||||||
export function objToBase64URI(obj: any): string {
|
export function objToBase64URI(obj: any): string {
|
||||||
return encodeURIComponent(objToBase64(obj));
|
return encodeURIComponent(objToBase64(obj));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import { getAce } from '@shared/models/ace/ace.models';
|
|||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { beautifyJs } from '@shared/models/beautify.models';
|
import { beautifyJs } from '@shared/models/beautify.models';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
|
import { base64toString, isLiteralObject } from '@core/utils';
|
||||||
|
|
||||||
export interface EventContentDialogData {
|
export interface EventContentDialogData {
|
||||||
content: string;
|
content: string;
|
||||||
@ -64,6 +65,14 @@ export class EventContentDialogComponent extends DialogComponent<EventContentDia
|
|||||||
this.createEditor(this.eventContentEditorElmRef, this.content);
|
this.createEditor(this.eventContentEditorElmRef, this.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isJson(str) {
|
||||||
|
try {
|
||||||
|
return isLiteralObject(JSON.parse(str));
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createEditor(editorElementRef: ElementRef, content: string) {
|
createEditor(editorElementRef: ElementRef, content: string) {
|
||||||
const editorElement = editorElementRef.nativeElement;
|
const editorElement = editorElementRef.nativeElement;
|
||||||
let mode = 'java';
|
let mode = 'java';
|
||||||
@ -72,6 +81,16 @@ export class EventContentDialogComponent extends DialogComponent<EventContentDia
|
|||||||
mode = contentTypesMap.get(this.contentType).code;
|
mode = contentTypesMap.get(this.contentType).code;
|
||||||
if (this.contentType === ContentType.JSON && content) {
|
if (this.contentType === ContentType.JSON && content) {
|
||||||
content$ = beautifyJs(content, {indent_size: 4});
|
content$ = beautifyJs(content, {indent_size: 4});
|
||||||
|
} else if (this.contentType === ContentType.BINARY && content) {
|
||||||
|
try {
|
||||||
|
const decodedData = base64toString(content);
|
||||||
|
if (this.isJson(decodedData)) {
|
||||||
|
mode = 'json';
|
||||||
|
content$ = beautifyJs(decodedData, {indent_size: 4});
|
||||||
|
} else {
|
||||||
|
content$ = of(decodedData);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!content$) {
|
if (!content$) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user