refactor(plexservers): use destructuring when possible
This commit is contained in:
parent
0f4d91e378
commit
a1d0868c2a
|
@ -29,7 +29,7 @@ export default {
|
||||||
getters.GET_SERVER_LIBRARY_SIZE({ machineIdentifier, sectionId }) - 1,
|
getters.GET_SERVER_LIBRARY_SIZE({ machineIdentifier, sectionId }) - 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
const contents = await dispatch('FETCH_LIBRARY_CONTENTS', {
|
const [item] = await dispatch('FETCH_LIBRARY_CONTENTS', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
sectionId,
|
sectionId,
|
||||||
start: randomItemIndex,
|
start: randomItemIndex,
|
||||||
|
@ -37,7 +37,7 @@ export default {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return contents[0];
|
return item;
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_RANDOM_ITEM: async ({ dispatch }, { machineIdentifier, sectionId, signal } = {}) => {
|
FETCH_RANDOM_ITEM: async ({ dispatch }, { machineIdentifier, sectionId, signal } = {}) => {
|
||||||
|
@ -85,7 +85,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
SEARCH_PLEX_SERVER: async ({ dispatch }, { query, machineIdentifier, signal }) => {
|
SEARCH_PLEX_SERVER: async ({ dispatch }, { query, machineIdentifier, signal }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Metadata } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: '/search',
|
path: '/search',
|
||||||
params: {
|
params: {
|
||||||
|
@ -94,18 +94,18 @@ export default {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data.MediaContainer.Metadata) {
|
if (!Metadata) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.MediaContainer.Metadata.map((result) => ({
|
return Metadata.map((result) => ({
|
||||||
...result,
|
...result,
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_PLEX_METADATA: async ({ dispatch }, { ratingKey, machineIdentifier, signal }) => {
|
FETCH_PLEX_METADATA: async ({ dispatch }, { ratingKey, machineIdentifier, signal }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Metadata: [item] } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: `/library/metadata/${ratingKey}`,
|
path: `/library/metadata/${ratingKey}`,
|
||||||
params: {
|
params: {
|
||||||
|
@ -127,7 +127,7 @@ export default {
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...data.MediaContainer.Metadata[0],
|
...item,
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -182,7 +182,7 @@ export default {
|
||||||
FETCH_ON_DECK: async ({ dispatch }, {
|
FETCH_ON_DECK: async ({ dispatch }, {
|
||||||
machineIdentifier, start, size, signal,
|
machineIdentifier, start, size, signal,
|
||||||
}) => {
|
}) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Metadata } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: '/library/onDeck',
|
path: '/library/onDeck',
|
||||||
params: {
|
params: {
|
||||||
|
@ -192,11 +192,11 @@ export default {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.MediaContainer.Metadata;
|
return Metadata;
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_ALL_LIBRARIES: async ({ dispatch }, { machineIdentifier, signal, ...rest }) => {
|
FETCH_ALL_LIBRARIES: async ({ dispatch }, { machineIdentifier, signal, ...rest }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Directory } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: '/library/sections',
|
path: '/library/sections',
|
||||||
signal,
|
signal,
|
||||||
|
@ -205,7 +205,7 @@ export default {
|
||||||
|
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
data.MediaContainer.Directory.map(async (library) => [
|
Directory.map(async (library) => [
|
||||||
library.key,
|
library.key,
|
||||||
{
|
{
|
||||||
...library,
|
...library,
|
||||||
|
@ -222,19 +222,19 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_RECENTLY_ADDED_MEDIA: async ({ dispatch }, { machineIdentifier, signal }) => {
|
FETCH_RECENTLY_ADDED_MEDIA: async ({ dispatch }, { machineIdentifier, signal }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Metadata } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: '/library/recentlyAdded',
|
path: '/library/recentlyAdded',
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.MediaContainer.Metadata;
|
return Metadata;
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_CHILDREN_CONTAINER: async ({ dispatch }, {
|
FETCH_CHILDREN_CONTAINER: async ({ dispatch }, {
|
||||||
machineIdentifier, ratingKey, start, size, excludeAllLeaves, signal,
|
machineIdentifier, ratingKey, start, size, excludeAllLeaves, signal,
|
||||||
}) => {
|
}) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: `/library/metadata/${ratingKey}/children`,
|
path: `/library/metadata/${ratingKey}/children`,
|
||||||
params: {
|
params: {
|
||||||
|
@ -247,24 +247,23 @@ export default {
|
||||||
|
|
||||||
// Add librarySectionID to all children
|
// Add librarySectionID to all children
|
||||||
return {
|
return {
|
||||||
...data.MediaContainer,
|
...MediaContainer,
|
||||||
Metadata: data.MediaContainer.Metadata.map((child) => ({
|
Metadata: MediaContainer.Metadata.map((child) => ({
|
||||||
...child,
|
...child,
|
||||||
librarySectionID: data.MediaContainer.librarySectionID,
|
librarySectionID: MediaContainer.librarySectionID,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_MEDIA_CHILDREN: async ({ dispatch }, params) => {
|
FETCH_MEDIA_CHILDREN: async ({ dispatch }, params) => {
|
||||||
const { Metadata } = await dispatch('FETCH_CHILDREN_CONTAINER', params);
|
const { Metadata } = await dispatch('FETCH_CHILDREN_CONTAINER', params);
|
||||||
|
|
||||||
return Metadata;
|
return Metadata;
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_RELATED: async ({ dispatch }, {
|
FETCH_RELATED: async ({ dispatch }, {
|
||||||
machineIdentifier, ratingKey, count, signal,
|
machineIdentifier, ratingKey, count, signal,
|
||||||
}) => {
|
}) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer: { Hub, librarySectionID } } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: `/library/metadata/${ratingKey}/related`,
|
path: `/library/metadata/${ratingKey}/related`,
|
||||||
params: {
|
params: {
|
||||||
|
@ -275,9 +274,9 @@ export default {
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: potentially include the other hubs too (related director etc...)
|
// TODO: potentially include the other hubs too (related director etc...)
|
||||||
return data.MediaContainer.Hub?.[0]?.Metadata?.map((child) => ({
|
return Hub?.[0]?.Metadata?.map((child) => ({
|
||||||
...child,
|
...child,
|
||||||
librarySectionID: data.MediaContainer.librarySectionID,
|
librarySectionID,
|
||||||
})) || [];
|
})) || [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -324,7 +323,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
CREATE_PLAY_QUEUE: async ({ dispatch }, { machineIdentifier: id, ratingKey, signal }) => {
|
CREATE_PLAY_QUEUE: async ({ dispatch }, { machineIdentifier: id, ratingKey, signal }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier: id,
|
machineIdentifier: id,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/playQueues',
|
path: '/playQueues',
|
||||||
|
@ -342,11 +341,11 @@ export default {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.MediaContainer;
|
return MediaContainer;
|
||||||
},
|
},
|
||||||
|
|
||||||
FETCH_PLAY_QUEUE: async ({ dispatch }, { machineIdentifier, playQueueID, signal }) => {
|
FETCH_PLAY_QUEUE: async ({ dispatch }, { machineIdentifier, playQueueID, signal }) => {
|
||||||
const data = await dispatch('FETCH_PLEX_SERVER', {
|
const { MediaContainer } = await dispatch('FETCH_PLEX_SERVER', {
|
||||||
machineIdentifier,
|
machineIdentifier,
|
||||||
path: `/playQueues/${playQueueID}`,
|
path: `/playQueues/${playQueueID}`,
|
||||||
params: {
|
params: {
|
||||||
|
@ -359,7 +358,7 @@ export default {
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.MediaContainer;
|
return MediaContainer;
|
||||||
},
|
},
|
||||||
|
|
||||||
MARK_WATCHED: ({ dispatch }, { machineIdentifier, ratingKey, signal }) => dispatch(
|
MARK_WATCHED: ({ dispatch }, { machineIdentifier, ratingKey, signal }) => dispatch(
|
||||||
|
|
Loading…
Reference in New Issue