]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/videos/video-imports.ts
52e0075fbe697a1a2f7908ae8209fc932782f501
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-imports.ts
1
2 import { VideoImportCreate } from '../../models/videos'
3 import { makeGetRequest, makeUploadRequest } from '../requests/requests'
4 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5
6 function getYoutubeVideoUrl () {
7 return 'http://www.youtube.com/watch?v=msX3jv1XdvM'
8 }
9
10 function getMagnetURI () {
11 // eslint-disable-next-line max-len
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'
13 }
14
15 function getBadVideoUrl () {
16 return 'https://download.cpy.re/peertube/bad_video.mp4'
17 }
18
19 function getGoodVideoUrl () {
20 return 'https://download.cpy.re/peertube/good_video.mp4'
21 }
22
23 function importVideo (
24 url: string,
25 token: string,
26 attributes: VideoImportCreate & { torrentfile?: string },
27 statusCodeExpected = HttpStatusCode.OK_200
28 ) {
29 const path = '/api/v1/videos/imports'
30
31 let attaches: any = {}
32 if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile }
33
34 return makeUploadRequest({
35 url,
36 path,
37 token,
38 attaches,
39 fields: attributes,
40 statusCodeExpected
41 })
42 }
43
44 function getMyVideoImports (url: string, token: string, sort?: string) {
45 const path = '/api/v1/users/me/videos/imports'
46
47 const query = {}
48 if (sort) query['sort'] = sort
49
50 return makeGetRequest({
51 url,
52 query,
53 path,
54 token,
55 statusCodeExpected: HttpStatusCode.OK_200
56 })
57 }
58
59 // ---------------------------------------------------------------------------
60
61 export {
62 getBadVideoUrl,
63 getYoutubeVideoUrl,
64 importVideo,
65 getMagnetURI,
66 getMyVideoImports,
67 getGoodVideoUrl
68 }