| 96 | }; |
| 97 | |
| 98 | export function overwritePlaylistData( |
| 99 | source: Playlist, |
| 100 | data: Partial<Playlist>, |
| 101 | onError?: (error: string) => void |
| 102 | ): Playlist { |
| 103 | const parser = new ObjectParser({ |
| 104 | input: data, |
| 105 | onError: onError && (e => onError(`Error while parsing Playlist: ${e.toString()}`)), |
| 106 | }); |
| 107 | parser.prop('id', v => source.id = str(v), true); |
| 108 | parser.prop('title', v => source.title = str(v)); |
| 109 | parser.prop('description', v => source.description = str(v)); |
| 110 | parser.prop('icon', v => source.icon = str(v)); |
| 111 | parser.prop('library', v => source.library = str(v)); |
| 112 | parser.prop('author', v => source.author = str(v)); |
| 113 | parser.prop('extreme', v => source.extreme = !!v); |
| 114 | if (!source.id) { |
| 115 | source.id = uuid(); |
| 116 | } |
| 117 | if (data.games) { |
| 118 | const newGames: PlaylistGame[] = []; |
| 119 | parser.prop('games').array((item, index) => newGames.push(parsePlaylistGame(item as IObjectParserProp<PlaylistGame>))); |
| 120 | source.games = newGames; |
| 121 | } |
| 122 | return source; |
| 123 | } |
| 124 | |
| 125 | function parsePlaylistGame(parser: IObjectParserProp<any>): PlaylistGame { |
| 126 | const game: PlaylistGame = { |