]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-imports.ts
replace numbers with typed http status codes (#3409)
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-imports.ts
CommitLineData
bc22d608 1
d4681c00 2import { VideoImportCreate } from '../../models/videos'
d175a6f7 3import { makeGetRequest, makeUploadRequest } from '../requests/requests'
2d53be02 4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
590fb506
C
5
6function getYoutubeVideoUrl () {
6848b9f4 7 return 'http://www.youtube.com/watch?v=msX3jv1XdvM'
590fb506
C
8}
9
187501f8 10function getMagnetURI () {
a1587156 11 // eslint-disable-next-line max-len
3e17515e 12 return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4'
187501f8
C
13}
14
dc133480
C
15function getBadVideoUrl () {
16 return 'https://download.cpy.re/peertube/bad_video.mp4'
17}
18
b488ba1e
C
19function getGoodVideoUrl () {
20 return 'https://download.cpy.re/peertube/good_video.mp4'
21}
22
2d53be02
RK
23function importVideo (
24 url: string,
25 token: string,
26 attributes: VideoImportCreate & { torrentfile?: string },
27 statusCodeExpected = HttpStatusCode.OK_200
28) {
590fb506
C
29 const path = '/api/v1/videos/imports'
30
187501f8
C
31 let attaches: any = {}
32 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
33
34 return makeUploadRequest({
590fb506
C
35 url,
36 path,
37 token,
187501f8 38 attaches,
590fb506 39 fields: attributes,
2158ac90 40 statusCodeExpected
590fb506
C
41 })
42}
43
3e17515e 44function getMyVideoImports (url: string, token: string, sort?: string) {
590fb506
C
45 const path = '/api/v1/users/me/videos/imports'
46
3e17515e
C
47 const query = {}
48 if (sort) query['sort'] = sort
49
590fb506
C
50 return makeGetRequest({
51 url,
3e17515e 52 query,
590fb506
C
53 path,
54 token,
2d53be02 55 statusCodeExpected: HttpStatusCode.OK_200
590fb506
C
56 })
57}
58
59// ---------------------------------------------------------------------------
60
61export {
dc133480 62 getBadVideoUrl,
590fb506
C
63 getYoutubeVideoUrl,
64 importVideo,
187501f8 65 getMagnetURI,
b488ba1e
C
66 getMyVideoImports,
67 getGoodVideoUrl
590fb506 68}