MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / overwritePlaylistData

Function overwritePlaylistData

src/back/PlaylistFile.ts:98–123  ·  view source on GitHub ↗
(
  source: Playlist,
  data: Partial<Playlist>,
  onError?: (error: string) => void
)

Source from the content-addressed store, hash-verified

96};
97
98export 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
125function parsePlaylistGame(parser: IObjectParserProp<any>): PlaylistGame {
126 const game: PlaylistGame = {

Callers 2

registerRequestCallbacksFunction · 0.90
parseFunction · 0.85

Calls 8

strFunction · 0.90
uuidFunction · 0.90
parsePlaylistGameFunction · 0.85
onErrorFunction · 0.70
toStringMethod · 0.65
propMethod · 0.65
arrayMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected