Added a scuffed redirect to prior page for impersonation. Fixed some conditions for websocket message checks.

This commit is contained in:
Tom
2025-03-27 11:31:36 +00:00
parent 6e5efab5ec
commit b1bac758e3
10 changed files with 27 additions and 25 deletions

View File

@ -25,7 +25,7 @@ export class ImpersonationComponent implements OnInit {
impersonated: string | undefined; impersonated: string | undefined;
users: { id: string, name: string }[]; users: { id: string, name: string }[];
constructor(private hermes: HermesClientService, private auth: ApiAuthenticationService, private router: Router, private events: EventService, private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) { constructor(private client: HermesClientService, private auth: ApiAuthenticationService, private router: Router, private events: EventService, private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) {
this.users = [] this.users = []
} }
@ -46,17 +46,19 @@ export class ImpersonationComponent implements OnInit {
} }
}); });
if (this.auth.isAdmin()) { this.events.listen('impersonation', (userId) => {
this.events.listen('impersonation', (userId) => { const url = this.router.url;
this.keyService.fetch(true) this.client.first(d => d.op == 2 && !d.d.another_client)
.pipe(timeout(3000), first()) .subscribe(async _ =>
.subscribe(async (d: ApiKey[]) => { await setTimeout(async () =>
if (d.length > 0) await this.router.navigate([url.substring(1)]), 500));
this.hermes.login(d[0].id); this.keyService.fetch(true)
await this.router.navigate([this.router.url.substring(1)]); .pipe(timeout(3000), first())
}); .subscribe(async (d: ApiKey[]) => {
}); if (d.length > 0)
} this.client.login(d[0].id);
});
});
} }
public isAdmin() { public isAdmin() {
@ -80,7 +82,7 @@ export class ImpersonationComponent implements OnInit {
impersonation: e.value impersonation: e.value
} }
}).subscribe(async (data: any) => { }).subscribe(async (data: any) => {
this.hermes.disconnect(); this.client.disconnect();
this.events.emit('impersonation', e.value); this.events.emit('impersonation', e.value);
}); });
} else { } else {
@ -91,7 +93,7 @@ export class ImpersonationComponent implements OnInit {
'Authorization': 'Bearer ' + localStorage.getItem('jwt') 'Authorization': 'Bearer ' + localStorage.getItem('jwt')
} }
}).subscribe(async (data: any) => { }).subscribe(async (data: any) => {
this.hermes.disconnect(); this.client.disconnect();
this.events.emit('impersonation', e.value); this.events.emit('impersonation', e.value);
await this.router.navigate(['tts-login']); await this.router.navigate(['tts-login']);
}); });

View File

@ -161,7 +161,7 @@ export class GroupPageComponent implements OnDestroy {
if (!this.group) if (!this.group)
return; return;
this._client.first(d => d.d.request.type == 'delete_group' && d.d.request.data.id == this.group!.id) this._client.first(d => d.op == 4 && d.d.request.type == 'delete_group' && d.d.request.data.id == this.group!.id)
.subscribe(async () => await this._router.navigate(['groups'])); .subscribe(async () => await this._router.navigate(['groups']));
this._client.deleteGroup(this.group.id); this._client.deleteGroup(this.group.id);
} }

View File

@ -63,7 +63,7 @@ export class ConnectionStateService {
return of(this.data); return of(this.data);
} }
const $ = this.client.first(d => d.d.request.type == 'get_connection_states')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_connection_states')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -64,7 +64,7 @@ export class ConnectionService {
return of(this.data); return of(this.data);
} }
const $ = this.client.first(d => d.d.request.type == 'get_connections')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_connections')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -69,7 +69,7 @@ export default class GroupService {
}); });
} }
const $ = this.client.first(d => d.d.request.type == 'get_groups')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_groups')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.groups = d.map((item: any) => item.group); this.groups = d.map((item: any) => item.group);
this.chatters = d.map((item: any) => item.chatters).flat(); this.chatters = d.map((item: any) => item.chatters).flat();

View File

@ -61,7 +61,7 @@ export class PermissionService {
return of(this.data); return of(this.data);
} }
const $ = this.client.first(d => d.d.request.type == 'get_group_permissions')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_group_permissions')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -45,7 +45,7 @@ export default class PolicyService {
return of(this.data); return of(this.data);
} }
const $ = this.client.first(d => d.d.request.type == 'get_policies')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_policies')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -45,7 +45,7 @@ export default class RedemptionService {
return of(this.data); return of(this.data);
} }
const $ = this.client.first(d => d.d.request.type == 'get_redemptions')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_redemptions')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -1,6 +1,6 @@
import { inject, Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { HermesClientService } from '../../hermes-client.service'; import { HermesClientService } from '../../hermes-client.service';
import { map, Observable, of } from 'rxjs'; import { first, map, Observable, of } from 'rxjs';
import EventService from './EventService'; import EventService from './EventService';
import { Filter } from '../models/filter'; import { Filter } from '../models/filter';
@ -41,10 +41,10 @@ export default class TtsFilterService {
fetch() { fetch() {
if (this.loaded) { if (this.loaded) {
return of(this.data); return of(this.data).pipe(first());
} }
const $ = this.client.first(d => d.d.request.type == 'get_tts_word_filters')!.pipe(map(d => d.d.data)); const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_tts_word_filters')!.pipe(map(d => d.d.data));
$.subscribe(d => { $.subscribe(d => {
this.data = d; this.data = d;
this.loaded = true; this.loaded = true;

View File

@ -32,7 +32,7 @@ export class TwitchUserItemComponent {
this.waitForResponse = true; this.waitForResponse = true;
this.responseError = undefined; this.responseError = undefined;
this._client.first(d => d.d.request.type == 'delete_group_chatter' && d.d.request.data.group == this.user.group_id && d.d.request.data.chatter == this.user.chatter_id) this._client.first(d => d.op == 4 && d.d.request.type == 'delete_group_chatter' && d.d.request.data.group == this.user.group_id && d.d.request.data.chatter == this.user.chatter_id)
.subscribe({ .subscribe({
next: (d) => { next: (d) => {
if (d.d.error) { if (d.d.error) {