From d4189e460135b1f32cbb90c693f72084b70d759f Mon Sep 17 00:00:00 2001 From: 4gray <4gray@users.noreply.github.com> Date: Sun, 22 Oct 2023 11:44:58 +0200 Subject: [PATCH] refactor(stalker): transform portal url --- .../stalker-portal-import.component.ts | 23 ++++++++++++++++++- .../stalker-main-container.component.ts | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/app/home/stalker-portal-import/stalker-portal-import.component.ts b/src/app/home/stalker-portal-import/stalker-portal-import.component.ts index 0a21fa798..dc0664bcd 100644 --- a/src/app/home/stalker-portal-import/stalker-portal-import.component.ts +++ b/src/app/home/stalker-portal-import/stalker-portal-import.component.ts @@ -48,7 +48,7 @@ export class StalkerPortalImportComponent { form = new FormGroup({ _id: new FormControl(uuid()), title: new FormControl('', [Validators.required]), - macAddress: new FormControl(''), + macAddress: new FormControl('', [Validators.required]), password: new FormControl(''), username: new FormControl(''), portalUrl: new FormControl('', [ @@ -62,8 +62,29 @@ export class StalkerPortalImportComponent { store = inject(Store); addPlaylist() { + this.form.value.portalUrl = this.transformPortalUrl( + this.form.value.portalUrl + ); this.store.dispatch( addPlaylist({ playlist: this.form.value as Playlist }) ); } + + transformPortalUrl(url: string) { + // if the url ends with "/c" it should be to end with "/portal.php" + if (url.endsWith('/c')) { + return url.replace('/c', '/portal.php'); + } + + // if the url ends with "/stalker_portal" it should be extended to "/stalker_portal/server/load.php" + if (url.endsWith('/stalker_portal')) { + return url.replace( + '/stalker_portal/c', + '/stalker_portal/server/load.php' + ); + } + + // otherwise keep the provided url + return url; + } } diff --git a/src/app/stalker/stalker-main-container.component.ts b/src/app/stalker/stalker-main-container.component.ts index 6de80c9db..81aa918d4 100644 --- a/src/app/stalker/stalker-main-container.component.ts +++ b/src/app/stalker/stalker-main-container.component.ts @@ -207,6 +207,7 @@ export class StalkerMainContainerComponent implements OnInit { response.action === StalkerPortalActions.GetCategories || response.action === StalkerPortalActions.GetGenres ) { + if (typeof response.payload !== 'object') return; this.items = response.payload.js.map((item) => ({ category_name: item.title, category_id: item.id,