Added endpoint for getting plays grouped by days of week.

This commit is contained in:
2019-11-11 17:59:16 +01:00
parent 2650497986
commit 510c014549
3 changed files with 36 additions and 3 deletions

View File

@@ -16,9 +16,19 @@ class Tautulli {
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)
url.searchParams.append('time_range', days)
url.searchParams.append('y_axis', y_axis)
return fetch(url.href)
.then(resp => resp.json())

View File

@@ -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/watch_time', mustHaveAccountLinkedToPlex, tautulli.watchTimeStatsController);
router.get('/v1/user/plays_by_day', mustHaveAccountLinkedToPlex, tautulli.getPlaysByDaysController);
router.get('/v1/user/plays_by_dayofweek', mustHaveAccountLinkedToPlex, tautulli.getPlaysByDayOfWeekController);
/**
* Seasoned

View File

@@ -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) {
const user = req.loggedInUser;
const days = req.query.days || undefined;
const { days, y_axis } = req.query;
if (days === undefined) {
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({
success: true,
data: data.response.data
@@ -76,5 +97,6 @@ function userViewHistoryController(req, res) {
module.exports = {
watchTimeStatsController,
getPlaysByDaysController,
getPlaysByDayOfWeekController,
userViewHistoryController
};