diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-07 16:09:57 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-07 16:25:29 +0100 |
commit | 2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f (patch) | |
tree | 998a0af6923475c85eb8e97ca1d30afb42655263 /shared/utils/videos/video-comments.ts | |
parent | 4b49385892b25aea5aa9e605fbcb66074bcb49b0 (diff) | |
parent | 35adc403b7eed6d1309bbce901268a76dd01b6ef (diff) | |
download | PeerTube-2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f.tar.gz PeerTube-2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f.tar.zst PeerTube-2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f.zip |
Merge branch 'move-utils-to-shared' of https://github.com/buoyantair/PeerTube into buoyantair-move-utils-to-shared
Diffstat (limited to 'shared/utils/videos/video-comments.ts')
-rw-r--r-- | shared/utils/videos/video-comments.ts | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/shared/utils/videos/video-comments.ts b/shared/utils/videos/video-comments.ts new file mode 100644 index 000000000..0ebf69ced --- /dev/null +++ b/shared/utils/videos/video-comments.ts | |||
@@ -0,0 +1,87 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { makeDeleteRequest } from '../requests/requests' | ||
3 | |||
4 | function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string, token?: string) { | ||
5 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | ||
6 | |||
7 | const req = request(url) | ||
8 | .get(path) | ||
9 | .query({ start: start }) | ||
10 | .query({ count: count }) | ||
11 | |||
12 | if (sort) req.query({ sort }) | ||
13 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
14 | |||
15 | return req.set('Accept', 'application/json') | ||
16 | .expect(200) | ||
17 | .expect('Content-Type', /json/) | ||
18 | } | ||
19 | |||
20 | function getVideoThreadComments (url: string, videoId: number | string, threadId: number, token?: string) { | ||
21 | const path = '/api/v1/videos/' + videoId + '/comment-threads/' + threadId | ||
22 | |||
23 | const req = request(url) | ||
24 | .get(path) | ||
25 | .set('Accept', 'application/json') | ||
26 | |||
27 | if (token) req.set('Authorization', 'Bearer ' + token) | ||
28 | |||
29 | return req.expect(200) | ||
30 | .expect('Content-Type', /json/) | ||
31 | } | ||
32 | |||
33 | function addVideoCommentThread (url: string, token: string, videoId: number | string, text: string, expectedStatus = 200) { | ||
34 | const path = '/api/v1/videos/' + videoId + '/comment-threads' | ||
35 | |||
36 | return request(url) | ||
37 | .post(path) | ||
38 | .send({ text }) | ||
39 | .set('Accept', 'application/json') | ||
40 | .set('Authorization', 'Bearer ' + token) | ||
41 | .expect(expectedStatus) | ||
42 | } | ||
43 | |||
44 | function addVideoCommentReply ( | ||
45 | url: string, | ||
46 | token: string, | ||
47 | videoId: number | string, | ||
48 | inReplyToCommentId: number, | ||
49 | text: string, | ||
50 | expectedStatus = 200 | ||
51 | ) { | ||
52 | const path = '/api/v1/videos/' + videoId + '/comments/' + inReplyToCommentId | ||
53 | |||
54 | return request(url) | ||
55 | .post(path) | ||
56 | .send({ text }) | ||
57 | .set('Accept', 'application/json') | ||
58 | .set('Authorization', 'Bearer ' + token) | ||
59 | .expect(expectedStatus) | ||
60 | } | ||
61 | |||
62 | function deleteVideoComment ( | ||
63 | url: string, | ||
64 | token: string, | ||
65 | videoId: number | string, | ||
66 | commentId: number, | ||
67 | statusCodeExpected = 204 | ||
68 | ) { | ||
69 | const path = '/api/v1/videos/' + videoId + '/comments/' + commentId | ||
70 | |||
71 | return makeDeleteRequest({ | ||
72 | url, | ||
73 | path, | ||
74 | token, | ||
75 | statusCodeExpected | ||
76 | }) | ||
77 | } | ||
78 | |||
79 | // --------------------------------------------------------------------------- | ||
80 | |||
81 | export { | ||
82 | getVideoCommentThreads, | ||
83 | getVideoThreadComments, | ||
84 | addVideoCommentThread, | ||
85 | addVideoCommentReply, | ||
86 | deleteVideoComment | ||
87 | } | ||