X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Futils%2Fvideos%2Fvideo-history.ts;h=dc7095b4d7181c817c6ea7a4f352660a62fa5374;hb=8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4;hp=7635478f770b39a7e9f1015a20ab4bf87c507899;hpb=583cd0d2129dc855e599f981d70e537feade1632;p=github%2FChocobozzz%2FPeerTube.git 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 }