From 5ea1358e528abb08bfccdbac86260f4fede6f128 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Fri, 19 Nov 2021 20:18:21 -0800 Subject: [PATCH] Add batch star --- src/api/api.ts | 2 -- src/api/controller.ts | 6 ++++-- src/api/jellyfinApi.ts | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index b509232..0b997a9 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -411,8 +411,6 @@ export const getArtistSongs = async (options: { id: string }) => { const promises = []; const { data } = await api.get(`/getArtist`, { params: options }); - console.log(`artist`, data.artist); - for (let i = 0; i < data.artist.album.length; i += 1) { promises.push(api.get(`/getAlbum`, { params: { id: data.artist.album[i].id } })); } diff --git a/src/api/controller.ts b/src/api/controller.ts index 6a1f67c..6c96560 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -44,6 +44,8 @@ import { getStarred as jfGetStarred, star as jfStar, unstar as jfUnstar, + batchStar as jfBatchStar, + batchUnstar as jfBatchUnstar, } from './jellyfinApi'; import { APIEndpoints, ServerType } from '../types'; @@ -62,8 +64,8 @@ const endpoints = [ { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } }, { id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } }, { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } }, - { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } }, - { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } }, + { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: jfBatchStar } }, + { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: jfBatchUnstar } }, { id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } }, { id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } }, { id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } }, diff --git a/src/api/jellyfinApi.ts b/src/api/jellyfinApi.ts index ba82e78..20805ae 100644 --- a/src/api/jellyfinApi.ts +++ b/src/api/jellyfinApi.ts @@ -387,3 +387,25 @@ export const unstar = async (options: { id: string }) => { const { data } = await jellyfinApi.delete(`/users/${auth.username}/favoriteitems/${options.id}`); return data; }; + +export const batchStar = async (options: { ids: string[] }) => { + const promises = []; + for (let i = 0; i < options.ids.length; i += 1) { + promises.push(star({ id: options.ids[i] })); + } + + const res = await Promise.all(promises); + + return res; +}; + +export const batchUnstar = async (options: { ids: string[] }) => { + const promises = []; + for (let i = 0; i < options.ids.length; i += 1) { + promises.push(unstar({ id: options.ids[i] })); + } + + const res = await Promise.all(promises); + + return res; +};