Added endpoint for getting plays grouped by days of week.
This commit is contained in:
@@ -16,9 +16,19 @@ class Tautulli {
|
|||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlaysByDays(plex_userid, days) {
|
getPlaysByDayOfWeek(plex_userid, days, y_axis) {
|
||||||
|
const url = this.buildUrlWithCmdAndUserid('get_plays_by_dayofweek', plex_userid)
|
||||||
|
url.searchParams.append('time_range', days)
|
||||||
|
url.searchParams.append('y_axis', y_axis)
|
||||||
|
|
||||||
|
return fetch(url.href)
|
||||||
|
.then(resp => resp.json())
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlaysByDays(plex_userid, days, y_axis) {
|
||||||
const url = this.buildUrlWithCmdAndUserid('get_plays_by_date', plex_userid)
|
const url = this.buildUrlWithCmdAndUserid('get_plays_by_date', plex_userid)
|
||||||
url.searchParams.append('time_range', days)
|
url.searchParams.append('time_range', days)
|
||||||
|
url.searchParams.append('y_axis', y_axis)
|
||||||
|
|
||||||
return fetch(url.href)
|
return fetch(url.href)
|
||||||
.then(resp => resp.json())
|
.then(resp => resp.json())
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ router.post('/v1/user/authenticate', mustBeAuthenticated, require('./controllers
|
|||||||
router.get('/v1/user/view_history', mustHaveAccountLinkedToPlex, tautulli.userViewHistoryController);
|
router.get('/v1/user/view_history', mustHaveAccountLinkedToPlex, tautulli.userViewHistoryController);
|
||||||
router.get('/v1/user/watch_time', mustHaveAccountLinkedToPlex, tautulli.watchTimeStatsController);
|
router.get('/v1/user/watch_time', mustHaveAccountLinkedToPlex, tautulli.watchTimeStatsController);
|
||||||
router.get('/v1/user/plays_by_day', mustHaveAccountLinkedToPlex, tautulli.getPlaysByDaysController);
|
router.get('/v1/user/plays_by_day', mustHaveAccountLinkedToPlex, tautulli.getPlaysByDaysController);
|
||||||
|
router.get('/v1/user/plays_by_dayofweek', mustHaveAccountLinkedToPlex, tautulli.getPlaysByDayOfWeekController);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seasoned
|
* Seasoned
|
||||||
|
|||||||
@@ -28,9 +28,22 @@ function watchTimeStatsController(req, res) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPlaysByDayOfWeekController(req, res) {
|
||||||
|
const user = req.loggedInUser;
|
||||||
|
const { days, y_axis } = req.query;
|
||||||
|
|
||||||
|
tautulli.getPlaysByDayOfWeek(user.plex_userid, days, y_axis)
|
||||||
|
.then(data => res.send({
|
||||||
|
success: true,
|
||||||
|
data: data.response.data,
|
||||||
|
message: 'play by day of week successfully fetched from tautulli'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function getPlaysByDaysController(req, res) {
|
function getPlaysByDaysController(req, res) {
|
||||||
const user = req.loggedInUser;
|
const user = req.loggedInUser;
|
||||||
const days = req.query.days || undefined;
|
const { days, y_axis } = req.query;
|
||||||
|
|
||||||
if (days === undefined) {
|
if (days === undefined) {
|
||||||
return res.status(422).send({
|
return res.status(422).send({
|
||||||
@@ -39,7 +52,15 @@ function getPlaysByDaysController(req, res) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tautulli.getPlaysByDays(user.plex_userid, days)
|
const allowedYAxisDataType = ['plays', 'duration'];
|
||||||
|
if (!allowedYAxisDataType.includes(y_axis)) {
|
||||||
|
return res.status(422).send({
|
||||||
|
success: false,
|
||||||
|
message: `Y axis parameter must be one of values: [${ allowedYAxisDataType }]`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tautulli.getPlaysByDays(user.plex_userid, days, y_axis)
|
||||||
.then(data => res.send({
|
.then(data => res.send({
|
||||||
success: true,
|
success: true,
|
||||||
data: data.response.data
|
data: data.response.data
|
||||||
@@ -76,5 +97,6 @@ function userViewHistoryController(req, res) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
watchTimeStatsController,
|
watchTimeStatsController,
|
||||||
getPlaysByDaysController,
|
getPlaysByDaysController,
|
||||||
|
getPlaysByDayOfWeekController,
|
||||||
userViewHistoryController
|
userViewHistoryController
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user