mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-13 04:26:16 -08:00
refactor(playlists): improve error handling and filtering logic
Enhance the `getPortalFavorites` and `getPortalLiveStreamFavorites` methods to include null checks for the fetched items. This prevents potential runtime errors when accessing properties of undefined. Additionally, improve code readability by restructuring the filter logic a more explicit format. Add a console log for the parsed playlist in the `addPortalFavorite` method for debugging purposes.
This commit is contained in:
1 parent
3d0dd1de52
commit
2a2e831877
1 file changed
+25
-10
@@ -143,20 +143,34 @@ export class PlaylistsService {
|
||||
|
||||
getPortalFavorites(portalId: string) {
|
||||
return this.dbService
|
||||
.getByID<{ favorites: Partial<XtreamItem>[] }>(
|
||||
DbStores.Playlists,
|
||||
portalId
|
||||
)
|
||||
.pipe(map((item) => item.favorites.filter(itm => itm && itm.stream_type && itm.stream_type !== 'live') ?? []));
|
||||
.getByID<{
|
||||
favorites: Partial<XtreamItem>[];
|
||||
}>(DbStores.Playlists, portalId)
|
||||
.pipe(
|
||||
map((item) => {
|
||||
if (!item || !item.favorites) return [];
|
||||
return item.favorites.filter(
|
||||
(itm) =>
|
||||
itm && itm.stream_type && itm.stream_type !== 'live'
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getPortalLiveStreamFavorites(portalId: string) {
|
||||
return this.dbService
|
||||
.getByID<{ favorites: Partial<XtreamItem>[] }>(
|
||||
DbStores.Playlists,
|
||||
portalId
|
||||
)
|
||||
.pipe(map((item) => item.favorites.filter(itm => itm && itm.stream_type && itm.stream_type === 'live') ?? []));
|
||||
.getByID<{
|
||||
favorites: Partial<XtreamItem>[];
|
||||
}>(DbStores.Playlists, portalId)
|
||||
.pipe(
|
||||
map((item) => {
|
||||
if (!item || !item.favorites) return [];
|
||||
return item.favorites.filter(
|
||||
(itm) =>
|
||||
itm && itm.stream_type && itm.stream_type === 'live'
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
addPortalFavorite(portalId: string, item: any) {
|
||||
@@ -217,6 +231,7 @@ export class PlaylistsService {
|
||||
) {
|
||||
try {
|
||||
const parsedPlaylist = parse(playlist);
|
||||
console.log(parsedPlaylist);
|
||||
return createPlaylistObject(
|
||||
title,
|
||||
parsedPlaylist,
|
||||
|
||||
Reference in new issue
Block a user