mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-01-06 05:29:34 -06:00
Add endpoint and tests for Plex sections.
This commit is contained in:
@@ -5,5 +5,6 @@ const router = Router();
|
||||
|
||||
router.get('/users', plexService.getUsers);
|
||||
router.get('/most-watched', plexService.getMostWatched);
|
||||
router.get('/sections', plexService.getSections);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -8,11 +8,19 @@ const getUsers = async (req, res) => {
|
||||
|
||||
const getMostWatched = async (req, res) => {
|
||||
const plexApi = plexApiClient();
|
||||
const mostWatched = await plexApi.getMostWatched(2);
|
||||
console.log('url---', req.query);
|
||||
const mostWatched = await plexApi.getMostWatched(req.query.type);
|
||||
res.json(mostWatched);
|
||||
};
|
||||
|
||||
const getSections = async (req, res) => {
|
||||
const plexApi = plexApiClient();
|
||||
const sections = await plexApi.getSections();
|
||||
res.json(sections);
|
||||
};
|
||||
|
||||
export default {
|
||||
getUsers,
|
||||
getMostWatched,
|
||||
getSections,
|
||||
};
|
||||
|
||||
@@ -21,6 +21,16 @@ PlexApiClient.prototype.getUsersUrlParams = function() {
|
||||
};
|
||||
};
|
||||
|
||||
PlexApiClient.prototype.getSectionsUrlParams = function() {
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
path: '/library/sections',
|
||||
queryParams: {
|
||||
'X-Plex-Token': this.options.token || config.plex.token,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
PlexApiClient.prototype.mostWatchedUrlParams = function(type, limit = 10) {
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
@@ -94,6 +104,13 @@ PlexApiClient.prototype.getMostWatched = async function(type, limit = 10) {
|
||||
return response.MediaContainer.Metadata;
|
||||
};
|
||||
|
||||
PlexApiClient.prototype.getSections = async function() {
|
||||
const urlParams = this.getSectionsUrlParams();
|
||||
const getUsersUrl = this.buildUrl(urlParams);
|
||||
const response = await this.request(getUsersUrl);
|
||||
return response.MediaContainer.Directory;
|
||||
};
|
||||
|
||||
const plexApiClient = (options = []) => {
|
||||
return new PlexApiClient(options);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user