refactor(stalker): transform portal url

This commit is contained in:
4gray committed 2023-10-22 11:44:58 +02:00
1 parent 8a59ff6388
commit d4189e4601
2 files changed
+23 -1

No files matched your search

@@ -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;
}
}
@@ -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,