From e63cdb4cf9dbec51c514697d43ab6bd897b762e1 Mon Sep 17 00:00:00 2001 From: 4gray Date: Sat, 12 Sep 2020 12:44:33 +0200 Subject: [PATCH] refactor: store url of the added playlist --- api.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api.ts b/api.ts index f77b0af16..153481711 100644 --- a/api.ts +++ b/api.ts @@ -22,7 +22,8 @@ export class Api { const parsedPlaylist = this.parsePlaylist(array); const playlistObject = this.createPlaylistObject( args.title, - parsedPlaylist + parsedPlaylist, + args.url ); this.insertToDb(playlistObject); event.sender.send('parse-url-response', { @@ -42,7 +43,10 @@ export class Api { }); ipcMain.on('playlists-all', async (event, args) => { - const playlists = await db.find({}, { count: 1, title: 1, _id: 1 }); + const playlists = await db.find( + {}, + { count: 1, title: 1, _id: 1, url: 1, importDate: 1 } + ); event.sender.send('playlist-all-result', { payload: playlists, }); @@ -99,8 +103,9 @@ export class Api { * Saves playlist to the localStorage * @param name name of the playlist * @param playlist playlist to save + * @param url url of the playlist */ - createPlaylistObject(name: string, playlist: any): Playlist { + createPlaylistObject(name: string, playlist: any, url?: string): Playlist { return { id: guid(), _id: guid(), @@ -108,9 +113,10 @@ export class Api { title: name, count: playlist.items.length, playlist, - importDate: new Date().getMilliseconds(), - lastUsage: new Date().getMilliseconds(), + importDate: new Date().toISOString(), + lastUsage: new Date().toISOString(), favorites: [], + ...(url ? { url } : {}), }; }