Browse Source

Add batch star

master
jeffvli 3 years ago
committed by Jeff
parent
commit
5ea1358e52
  1. 2
      src/api/api.ts
  2. 6
      src/api/controller.ts
  3. 22
      src/api/jellyfinApi.ts

2
src/api/api.ts

@ -411,8 +411,6 @@ export const getArtistSongs = async (options: { id: string }) => {
const promises = []; const promises = [];
const { data } = await api.get(`/getArtist`, { params: options }); const { data } = await api.get(`/getArtist`, { params: options });
console.log(`artist`, data.artist);
for (let i = 0; i < data.artist.album.length; i += 1) { for (let i = 0; i < data.artist.album.length; i += 1) {
promises.push(api.get(`/getAlbum`, { params: { id: data.artist.album[i].id } })); promises.push(api.get(`/getAlbum`, { params: { id: data.artist.album[i].id } }));
} }

6
src/api/controller.ts

@ -44,6 +44,8 @@ import {
getStarred as jfGetStarred, getStarred as jfGetStarred,
star as jfStar, star as jfStar,
unstar as jfUnstar, unstar as jfUnstar,
batchStar as jfBatchStar,
batchUnstar as jfBatchUnstar,
} from './jellyfinApi'; } from './jellyfinApi';
import { APIEndpoints, ServerType } from '../types'; import { APIEndpoints, ServerType } from '../types';
@ -62,8 +64,8 @@ const endpoints = [
{ id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } }, { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } },
{ id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } }, { id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } },
{ id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } }, { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } },
{ id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: jfBatchStar } },
{ id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } }, { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: jfBatchUnstar } },
{ id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } }, { id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } },
{ id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } }, { id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } },
{ id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } }, { id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } },

22
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}`); const { data } = await jellyfinApi.delete(`/users/${auth.username}/favoriteitems/${options.id}`);
return data; 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;
};

Loading…
Cancel
Save