diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-17 15:52:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-18 11:35:50 +0100 |
commit | 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 (patch) | |
tree | 5e3392af5592d1401ada86d21f93bb7ad9da8ab1 /shared/utils | |
parent | 583cd0d2129dc855e599f981d70e537feade1632 (diff) | |
download | PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.gz PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.zst PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.zip |
Add history on server side
Add ability to disable, clear and list user videos history
Diffstat (limited to 'shared/utils')
-rw-r--r-- | shared/utils/users/users.ts | 16 | ||||
-rw-r--r-- | shared/utils/videos/video-history.ts | 33 |
2 files changed, 39 insertions, 10 deletions
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, | |||
162 | 162 | ||
163 | function updateMyUser (options: { | 163 | function updateMyUser (options: { |
164 | url: string | 164 | url: string |
165 | accessToken: string, | 165 | accessToken: string |
166 | currentPassword?: string, | 166 | currentPassword?: string |
167 | newPassword?: string, | 167 | newPassword?: string |
168 | nsfwPolicy?: NSFWPolicyType, | 168 | nsfwPolicy?: NSFWPolicyType |
169 | email?: string, | 169 | email?: string |
170 | autoPlayVideo?: boolean | 170 | autoPlayVideo?: boolean |
171 | displayName?: string, | 171 | displayName?: string |
172 | description?: string | 172 | description?: string |
173 | videosHistoryEnabled?: boolean | ||
173 | }) { | 174 | }) { |
174 | const path = '/api/v1/users/me' | 175 | const path = '/api/v1/users/me' |
175 | 176 | ||
@@ -181,6 +182,9 @@ function updateMyUser (options: { | |||
181 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email | 182 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
182 | if (options.description !== undefined && options.description !== null) toSend['description'] = options.description | 183 | if (options.description !== undefined && options.description !== null) toSend['description'] = options.description |
183 | if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName | 184 | if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName |
185 | if (options.videosHistoryEnabled !== undefined && options.videosHistoryEnabled !== null) { | ||
186 | toSend['videosHistoryEnabled'] = options.videosHistoryEnabled | ||
187 | } | ||
184 | 188 | ||
185 | return makePutBodyRequest({ | 189 | return makePutBodyRequest({ |
186 | url: options.url, | 190 | 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 @@ | |||
1 | import { makePutBodyRequest } from '../requests/requests' | 1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
2 | 2 | ||
3 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number) { | 3 | function userWatchVideo (url: string, token: string, videoId: number | string, currentTime: number, statusCodeExpected = 204) { |
4 | const path = '/api/v1/videos/' + videoId + '/watching' | 4 | const path = '/api/v1/videos/' + videoId + '/watching' |
5 | const fields = { currentTime } | 5 | const fields = { currentTime } |
6 | 6 | ||
7 | return makePutBodyRequest({ url, path, token, fields, statusCodeExpected: 204 }) | 7 | return makePutBodyRequest({ url, path, token, fields, statusCodeExpected }) |
8 | } | ||
9 | |||
10 | function listMyVideosHistory (url: string, token: string) { | ||
11 | const path = '/api/v1/users/me/history/videos' | ||
12 | |||
13 | return makeGetRequest({ | ||
14 | url, | ||
15 | path, | ||
16 | token, | ||
17 | statusCodeExpected: 200 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | function removeMyVideosHistory (url: string, token: string, beforeDate?: string) { | ||
22 | const path = '/api/v1/users/me/history/videos/remove' | ||
23 | |||
24 | return makePostBodyRequest({ | ||
25 | url, | ||
26 | path, | ||
27 | token, | ||
28 | fields: beforeDate ? { beforeDate } : {}, | ||
29 | statusCodeExpected: 204 | ||
30 | }) | ||
8 | } | 31 | } |
9 | 32 | ||
10 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
11 | 34 | ||
12 | export { | 35 | export { |
13 | userWatchVideo | 36 | userWatchVideo, |
37 | listMyVideosHistory, | ||
38 | removeMyVideosHistory | ||
14 | } | 39 | } |