diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 16:21:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 313228e9c3b5bcef5391228c9b949d05d32ad7bb (patch) | |
tree | d2f39a2bd32ef093224c594d72219809504321b7 /shared/extra-utils | |
parent | e6346d59e63135cf012ed18c102d3b0179ef565f (diff) | |
download | PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.tar.gz PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.tar.zst PeerTube-313228e9c3b5bcef5391228c9b949d05d32ad7bb.zip |
Introduce history command
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/server/servers.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/videos/history-command.ts | 59 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-history.ts | 49 |
4 files changed, 63 insertions, 51 deletions
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 78b3be9c7..bd5c29e51 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests' | |||
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' | 20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' |
21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' | 21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' |
22 | import { ConfigCommand } from './config-command' | 22 | import { ConfigCommand } from './config-command' |
23 | import { ContactFormCommand } from './contact-form-command' | 23 | import { ContactFormCommand } from './contact-form-command' |
24 | import { DebugCommand } from './debug-command' | 24 | import { DebugCommand } from './debug-command' |
@@ -106,6 +106,7 @@ interface ServerInfo { | |||
106 | captionsCommand?: CaptionsCommand | 106 | captionsCommand?: CaptionsCommand |
107 | changeOwnershipCommand?: ChangeOwnershipCommand | 107 | changeOwnershipCommand?: ChangeOwnershipCommand |
108 | playlistsCommand?: PlaylistsCommand | 108 | playlistsCommand?: PlaylistsCommand |
109 | historyCommand?: HistoryCommand | ||
109 | } | 110 | } |
110 | 111 | ||
111 | function parallelTests () { | 112 | function parallelTests () { |
@@ -337,6 +338,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
337 | server.captionsCommand = new CaptionsCommand(server) | 338 | server.captionsCommand = new CaptionsCommand(server) |
338 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) | 339 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) |
339 | server.playlistsCommand = new PlaylistsCommand(server) | 340 | server.playlistsCommand = new PlaylistsCommand(server) |
341 | server.historyCommand = new HistoryCommand(server) | ||
340 | 342 | ||
341 | res(server) | 343 | res(server) |
342 | }) | 344 | }) |
diff --git a/shared/extra-utils/videos/history-command.ts b/shared/extra-utils/videos/history-command.ts new file mode 100644 index 000000000..8a144a312 --- /dev/null +++ b/shared/extra-utils/videos/history-command.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { ResultList, Video } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class HistoryCommand extends AbstractCommand { | ||
6 | |||
7 | wathVideo (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | currentTime: number | ||
10 | }) { | ||
11 | const { videoId, currentTime } = options | ||
12 | |||
13 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
14 | const fields = { currentTime } | ||
15 | |||
16 | return this.putBodyRequest({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | fields, | ||
21 | implicitToken: true, | ||
22 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | list (options: OverrideCommandOptions & { | ||
27 | search?: string | ||
28 | } = {}) { | ||
29 | const { search } = options | ||
30 | const path = '/api/v1/users/me/history/videos' | ||
31 | |||
32 | return this.getRequestBody<ResultList<Video>>({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | query: { | ||
37 | search | ||
38 | }, | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | remove (options: OverrideCommandOptions & { | ||
45 | beforeDate?: string | ||
46 | } = {}) { | ||
47 | const { beforeDate } = options | ||
48 | const path = '/api/v1/users/me/history/videos/remove' | ||
49 | |||
50 | return this.postBodyRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | fields: { beforeDate }, | ||
55 | implicitToken: true, | ||
56 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
57 | }) | ||
58 | } | ||
59 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 1f6241d7e..74667fc06 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -2,6 +2,7 @@ export * from './blacklist-command' | |||
2 | export * from './captions' | 2 | export * from './captions' |
3 | export * from './captions-command' | 3 | export * from './captions-command' |
4 | export * from './change-ownership-command' | 4 | export * from './change-ownership-command' |
5 | export * from './history-command' | ||
5 | export * from './live-command' | 6 | export * from './live-command' |
6 | export * from './live' | 7 | export * from './live' |
7 | export * from './playlists-command' | 8 | export * from './playlists-command' |
@@ -9,7 +10,6 @@ export * from './playlists' | |||
9 | export * from './services-command' | 10 | export * from './services-command' |
10 | export * from './video-channels' | 11 | export * from './video-channels' |
11 | export * from './video-comments' | 12 | export * from './video-comments' |
12 | export * from './video-history' | ||
13 | export * from './video-imports' | 13 | export * from './video-imports' |
14 | export * from './video-streaming-playlists' | 14 | export * from './video-streaming-playlists' |
15 | export * from './videos' | 15 | export * from './videos' |
diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts deleted file mode 100644 index b989e14dc..000000000 --- a/shared/extra-utils/videos/video-history.ts +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function userWatchVideo ( | ||
5 | url: string, | ||
6 | token: string, | ||
7 | videoId: number | string, | ||
8 | currentTime: number, | ||
9 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
10 | ) { | ||
11 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
12 | const fields = { currentTime } | ||
13 | |||
14 | return makePutBodyRequest({ url, path, token, fields, statusCodeExpected }) | ||
15 | } | ||
16 | |||
17 | function listMyVideosHistory (url: string, token: string, search?: string) { | ||
18 | const path = '/api/v1/users/me/history/videos' | ||
19 | |||
20 | return makeGetRequest({ | ||
21 | url, | ||
22 | path, | ||
23 | token, | ||
24 | query: { | ||
25 | search | ||
26 | }, | ||
27 | statusCodeExpected: HttpStatusCode.OK_200 | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | function removeMyVideosHistory (url: string, token: string, beforeDate?: string) { | ||
32 | const path = '/api/v1/users/me/history/videos/remove' | ||
33 | |||
34 | return makePostBodyRequest({ | ||
35 | url, | ||
36 | path, | ||
37 | token, | ||
38 | fields: beforeDate ? { beforeDate } : {}, | ||
39 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | // --------------------------------------------------------------------------- | ||
44 | |||
45 | export { | ||
46 | userWatchVideo, | ||
47 | listMyVideosHistory, | ||
48 | removeMyVideosHistory | ||
49 | } | ||