From 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 17 Dec 2018 15:52:38 +0100 Subject: Add history on server side Add ability to disable, clear and list user videos history --- shared/models/users/user-update-me.model.ts | 7 ++++-- shared/utils/users/users.ts | 16 ++++++++------ shared/utils/videos/video-history.ts | 33 +++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) (limited to 'shared') diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.ts index 10edeee2e..e24afab94 100644 --- a/shared/models/users/user-update-me.model.ts +++ b/shared/models/users/user-update-me.model.ts @@ -3,9 +3,12 @@ import { NSFWPolicyType } from '../videos/nsfw-policy.type' export interface UserUpdateMe { displayName?: string description?: string - nsfwPolicy?: NSFWPolicyType, - webTorrentEnabled?: boolean, + nsfwPolicy?: NSFWPolicyType + + webTorrentEnabled?: boolean autoPlayVideo?: boolean + videosHistoryEnabled?: boolean + email?: string currentPassword?: string password?: string diff --git a/shared/utils/users/users.ts b/shared/utils/users/users.ts index 554e42c01..61a7e3757 100644 --- a/shared/utils/users/users.ts +++ b/shared/utils/users/users.ts @@ -162,14 +162,15 @@ function unblockUser (url: string, userId: number | string, accessToken: string, function updateMyUser (options: { url: string - accessToken: string, - currentPassword?: string, - newPassword?: string, - nsfwPolicy?: NSFWPolicyType, - email?: string, + accessToken: string + currentPassword?: string + newPassword?: string + nsfwPolicy?: NSFWPolicyType + email?: string autoPlayVideo?: boolean - displayName?: string, + displayName?: string description?: string + videosHistoryEnabled?: boolean }) { const path = '/api/v1/users/me' @@ -181,6 +182,9 @@ function updateMyUser (options: { if (options.email !== undefined && options.email !== null) toSend['email'] = options.email if (options.description !== undefined && options.description !== null) toSend['description'] = options.description if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName + if (options.videosHistoryEnabled !== undefined && options.videosHistoryEnabled !== null) { + toSend['videosHistoryEnabled'] = options.videosHistoryEnabled + } return makePutBodyRequest({ url: options.url, diff --git a/shared/utils/videos/video-history.ts b/shared/utils/videos/video-history.ts index 7635478f7..dc7095b4d 100644 --- a/shared/utils/videos/video-history.ts +++ b/shared/utils/videos/video-history.ts @@ -1,14 +1,39 @@ -import { makePutBodyRequest } from '../requests/requests' +import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' -function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number) { +function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { const path = '/api/v1/videos/' + videoId + '/watching' const fields = { currentTime } - return makePutBodyRequest({ url, path, token, fields, statusCodeExpected: 204 }) + return makePutBodyRequest({ url, path, token, fields, statusCodeExpected }) +} + +function listMyVideosHistory (url: string, token: string) { + const path = '/api/v1/users/me/history/videos' + + return makeGetRequest({ + url, + path, + token, + statusCodeExpected: 200 + }) +} + +function removeMyVideosHistory (url: string, token: string, beforeDate?: string) { + const path = '/api/v1/users/me/history/videos/remove' + + return makePostBodyRequest({ + url, + path, + token, + fields: beforeDate ? { beforeDate } : {}, + statusCodeExpected: 204 + }) } // --------------------------------------------------------------------------- export { - userWatchVideo + userWatchVideo, + listMyVideosHistory, + removeMyVideosHistory } -- cgit v1.2.3