feat: add pagination options to watchlist api request

feature/watchlist-sync
Ryan Cohen 2 years ago committed by Ryan Cohen
parent d435418d3b
commit 4e6c9ec545

@ -286,11 +286,18 @@ class PlexTvAPI extends ExternalAPI {
return parsedXml; return parsedXml;
} }
public async getWatchlist(): Promise<PlexWatchlistItem[]> { public async getWatchlist({
offset = 0,
size = 20,
}: { offset?: number; size?: number } = {}): Promise<PlexWatchlistItem[]> {
try { try {
const response = await this.axios.get<WatchlistResponse>( const response = await this.axios.get<WatchlistResponse>(
'/library/sections/watchlist/all', '/library/sections/watchlist/all',
{ {
params: {
'X-Plex-Container-Start': offset,
'X-Plex-Container-Size': size,
},
baseURL: 'https://metadata.provider.plex.tv', baseURL: 'https://metadata.provider.plex.tv',
} }
); );

@ -709,29 +709,24 @@ discoverRoutes.get<{ language: string }, GenreSliderItem[]>(
} }
); );
discoverRoutes.get<never, WatchlistItem[]>( discoverRoutes.get<never, WatchlistItem[]>('/watchlist', async (req, res) => {
'/watchlist', const userRepository = getRepository(User);
async (req, res, next) => {
const userRepository = getRepository(User);
const activeUser = await userRepository.findOne({ const activeUser = await userRepository.findOne({
where: { id: req.user?.id }, where: { id: req.user?.id },
select: ['id', 'plexToken'], select: ['id', 'plexToken'],
}); });
if (!activeUser?.plexToken) { if (!activeUser?.plexToken) {
return next({ // We will just return an empty array if the user has no plex token
status: 500, return res.json([]);
message: 'Must be a Plex account to use watchlist feature.', }
});
}
const plexTV = new PlexTvAPI(activeUser?.plexToken); const plexTV = new PlexTvAPI(activeUser?.plexToken);
const watchlist = await plexTV.getWatchlist(); const watchlist = await plexTV.getWatchlist();
return res.json(watchlist); return res.json(watchlist);
} });
);
export default discoverRoutes; export default discoverRoutes;

Loading…
Cancel
Save