Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/app/pages/share/share.component.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import {ActivatedRoute} from '@angular/router';
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';

// TODO 与 kubernetes 合并
@Component({
standalone: false,
selector: 'pages-share',
templateUrl: 'share.component.html',
templateUrl: 'share.component.html'
})
export class PagesShareComponent implements OnInit, AfterViewInit {
@ViewChild('iFrame', {static: false}) iframeRef: ElementRef;
@ViewChild('iFrame', { static: false }) iframeRef: ElementRef;

public ping;
public id: string = '';
public type: string = '';
public shareId: string = '';
public iframeURL: string = '';

constructor(private _route: ActivatedRoute) {
}
constructor(private _route: ActivatedRoute) {}

ngOnInit(): void {
this.id = 'window-' + Math.random().toString(36).substr(2);
this.shareId = this._route.snapshot.params['id'];
this.type = this._route.snapshot.queryParams['type'];

const queryParams = new URLSearchParams();

Object.entries(this._route.snapshot.queryParams).forEach(([key, value]) => {
if (value !== null && value !== undefined) {
queryParams.append(key, value as string);
}
});

const queryString = queryParams.toString();
const baseUrl = `${window.location.protocol}//${window.location.host}`;

if (this.type && this.type === 'lion') {
this.iframeURL = `${baseUrl}/lion/share/${this.shareId}`;
this.iframeURL = `${baseUrl}/lion/share/${this.shareId}?${queryString}`;
return;
}

this.iframeURL = `${baseUrl}/koko/share/${this.shareId}`;
this.iframeURL = `${baseUrl}/koko/share/${this.shareId}?${queryString}`;
}

ngAfterViewInit(): void {
Expand All @@ -40,18 +47,21 @@

handleK8sIframeEvent() {
this.ping = setInterval(() => {
this.iframeRef.nativeElement.contentWindow.postMessage({name: 'PING', id: this.id}, '*');
this.iframeRef.nativeElement.contentWindow.postMessage({ name: 'PING', id: this.id }, '*');
}, 1000);

window.addEventListener('message', (event) => {
window.addEventListener('message', event => {

Check failure

Code scanning / SonarCloud

Origins should be verified during cross-origin communications High

Verify the origin of the received message. See more on SonarQube Cloud
const msg = event.data;

switch (msg.name) {
case 'PONG':
clearInterval(this.ping);
break;
case 'PING':
this.iframeRef.nativeElement.contentWindow.postMessage({name: 'PING', id: this.id}, '*');
this.iframeRef.nativeElement.contentWindow.postMessage(

Check failure

Code scanning / SonarCloud

Origins should be verified during cross-origin communications High

Specify a target origin for this message. See more on SonarQube Cloud
{ name: 'PING', id: this.id },
'*'
);
break;
default:
break;
Expand Down