aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts6
-rw-r--r--server/helpers/core-utils.ts5
-rw-r--r--server/helpers/utils.ts3
-rw-r--r--server/helpers/webtorrent.ts9
-rw-r--r--server/lib/job-queue/handlers/video-import.ts8
-rw-r--r--server/tests/api/check-params/users.ts2
-rw-r--r--server/tests/api/check-params/video-imports.ts2
-rw-r--r--server/tests/api/videos/video-imports.ts159
-rw-r--r--server/tests/fixtures/60fps_small-240p.torrent1
-rw-r--r--server/tests/fixtures/video-720p.torrentbin0 -> 2644 bytes
-rw-r--r--server/tests/utils/videos/video-imports.ts10
11 files changed, 145 insertions, 60 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 94dafcdbd..b2f73fa48 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -97,7 +97,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
97 await processThumbnail(req, video) 97 await processThumbnail(req, video)
98 await processPreview(req, video) 98 await processPreview(req, video)
99 99
100 const tags = null 100 const tags = body.tags || undefined
101 const videoImportAttributes = { 101 const videoImportAttributes = {
102 magnetUri, 102 magnetUri,
103 torrentName, 103 torrentName,
@@ -224,11 +224,13 @@ function insertIntoDB (
224 videoCreated.VideoChannel = videoChannel 224 videoCreated.VideoChannel = videoChannel
225 225
226 // Set tags to the video 226 // Set tags to the video
227 if (tags !== undefined) { 227 if (tags) {
228 const tagInstances = await TagModel.findOrCreateTags(tags, t) 228 const tagInstances = await TagModel.findOrCreateTags(tags, t)
229 229
230 await videoCreated.$set('Tags', tagInstances, sequelizeOptions) 230 await videoCreated.$set('Tags', tagInstances, sequelizeOptions)
231 videoCreated.Tags = tagInstances 231 videoCreated.Tags = tagInstances
232 } else {
233 videoCreated.Tags = []
232 } 234 }
233 235
234 // Create video import object in database 236 // Create video import object in database
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 25eb6454a..3b38da66c 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -5,7 +5,7 @@
5 5
6import * as bcrypt from 'bcrypt' 6import * as bcrypt from 'bcrypt'
7import * as createTorrent from 'create-torrent' 7import * as createTorrent from 'create-torrent'
8import { pseudoRandomBytes } from 'crypto' 8import { createHash, pseudoRandomBytes } from 'crypto'
9import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs' 9import { copyFile, readdir, readFile, rename, stat, Stats, unlink, writeFile } from 'fs'
10import * as mkdirp from 'mkdirp' 10import * as mkdirp from 'mkdirp'
11import { isAbsolute, join } from 'path' 11import { isAbsolute, join } from 'path'
@@ -13,7 +13,6 @@ import * as pem from 'pem'
13import * as rimraf from 'rimraf' 13import * as rimraf from 'rimraf'
14import { URL } from 'url' 14import { URL } from 'url'
15import { truncate } from 'lodash' 15import { truncate } from 'lodash'
16import * as crypto from 'crypto'
17 16
18function sanitizeUrl (url: string) { 17function sanitizeUrl (url: string) {
19 const urlObject = new URL(url) 18 const urlObject = new URL(url)
@@ -97,7 +96,7 @@ function peertubeTruncate (str: string, maxLength: number) {
97} 96}
98 97
99function sha256 (str: string) { 98function sha256 (str: string) {
100 return crypto.createHash('sha256').update(str).digest('hex') 99 return createHash('sha256').update(str).digest('hex')
101} 100}
102 101
103function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { 102function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 2ad87951e..eaad55555 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -9,8 +9,7 @@ import { ApplicationModel } from '../models/application/application'
9import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils' 9import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils'
10import { logger } from './logger' 10import { logger } from './logger'
11import { isArray } from './custom-validators/misc' 11import { isArray } from './custom-validators/misc'
12import * as crypto from "crypto" 12import { join } from 'path'
13import { join } from "path"
14import { Instance as ParseTorrent } from 'parse-torrent' 13import { Instance as ParseTorrent } from 'parse-torrent'
15 14
16const isCidr = require('is-cidr') 15const isCidr = require('is-cidr')
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 04b3ac71b..121cd0b41 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -2,7 +2,6 @@ import { logger } from './logger'
2import { generateVideoTmpPath } from './utils' 2import { generateVideoTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream } from 'fs' 4import { createWriteStream } from 'fs'
5import { Instance as ParseTorrent } from 'parse-torrent'
6import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
7import { join } from 'path' 6import { join } from 'path'
8 7
@@ -20,10 +19,12 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName: stri
20 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId)) 19 if (torrent.files.length !== 1) return rej(new Error('The number of files is not equal to 1 for ' + torrentId))
21 20
22 const file = torrent.files[ 0 ] 21 const file = torrent.files[ 0 ]
23 file.createReadStream().pipe(createWriteStream(path))
24 })
25 22
26 torrent.on('done', () => res(path)) 23 const writeStream = createWriteStream(path)
24 writeStream.on('finish', () => res(path))
25
26 file.createReadStream().pipe(writeStream)
27 })
27 28
28 torrent.on('error', err => rej(err)) 29 torrent.on('error', err => rej(err))
29 }) 30 })
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 28a03d19e..2d19b82a4 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -114,8 +114,8 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
114 tempVideoPath = await downloader() 114 tempVideoPath = await downloader()
115 115
116 // Get information about this video 116 // Get information about this video
117 const { size } = await statPromise(tempVideoPath) 117 const stats = await statPromise(tempVideoPath)
118 const isAble = await videoImport.User.isAbleToUploadVideo({ size }) 118 const isAble = await videoImport.User.isAbleToUploadVideo({ size: stats.size })
119 if (isAble === false) { 119 if (isAble === false) {
120 throw new Error('The user video quota is exceeded with this video to import.') 120 throw new Error('The user video quota is exceeded with this video to import.')
121 } 121 }
@@ -128,7 +128,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
128 const videoFileData = { 128 const videoFileData = {
129 extname: extname(tempVideoPath), 129 extname: extname(tempVideoPath),
130 resolution: videoFileResolution, 130 resolution: videoFileResolution,
131 size, 131 size: stats.size,
132 fps, 132 fps,
133 videoId: videoImport.videoId 133 videoId: videoImport.videoId
134 } 134 }
@@ -209,7 +209,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
209 209
210 } catch (err) { 210 } catch (err) {
211 try { 211 try {
212 if (tempVideoPath) await unlinkPromise(tempVideoPath) 212 // if (tempVideoPath) await unlinkPromise(tempVideoPath)
213 } catch (errUnlink) { 213 } catch (errUnlink) {
214 logger.warn('Cannot cleanup files after a video import error.', { err: errUnlink }) 214 logger.warn('Cannot cleanup files after a video import error.', { err: errUnlink })
215 } 215 }
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index e1655e85b..7b25df29f 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -627,7 +627,7 @@ describe('Test users API validators', function () {
627 } 627 }
628 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) 628 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
629 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) 629 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
630 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: '60fps_small-240p.torrent' })) 630 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
631 631
632 await waitJobs([ server ]) 632 await waitJobs([ server ])
633 633
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index e62f0918e..38ddd4e56 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -303,7 +303,7 @@ describe('Test video imports API validator', function () {
303 303
304 fields = omit(fields, 'magnetUri') 304 fields = omit(fields, 'magnetUri')
305 const attaches = { 305 const attaches = {
306 'torrentfile': join(__dirname, '..', '..', 'fixtures', '60fps_small-240p.torrent') 306 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
307 } 307 }
308 308
309 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) 309 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index f21ade5c3..b7866d529 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -2,7 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' 5import { VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos'
6import { 6import {
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
@@ -10,12 +10,13 @@ import {
10 getMyVideos, 10 getMyVideos,
11 getVideo, 11 getVideo,
12 getVideosList, 12 getVideosList,
13 immutableAssign,
13 killallServers, 14 killallServers,
14 ServerInfo, 15 ServerInfo,
15 setAccessTokensToServers 16 setAccessTokensToServers
16} from '../../utils' 17} from '../../utils'
17import { waitJobs } from '../../utils/server/jobs' 18import { waitJobs } from '../../utils/server/jobs'
18import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' 19import { getMagnetURI, getYoutubeVideoUrl, importVideo, getMyVideoImports } from '../../utils/videos/video-imports'
19 20
20const expect = chai.expect 21const expect = chai.expect
21 22
@@ -24,19 +25,36 @@ describe('Test video imports', function () {
24 let channelIdServer1: number 25 let channelIdServer1: number
25 let channelIdServer2: number 26 let channelIdServer2: number
26 27
27 async function checkVideoServer1 (url: string, id: number | string) { 28 async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) {
28 const res = await getVideo(url, id) 29 const resHttp = await getVideo(url, idHttp)
29 const video: VideoDetails = res.body 30 const videoHttp: VideoDetails = resHttp.body
30 31
31 expect(video.name).to.equal('small video - youtube') 32 expect(videoHttp.name).to.equal('small video - youtube')
32 expect(video.category.label).to.equal('News') 33 expect(videoHttp.category.label).to.equal('News')
33 expect(video.licence.label).to.equal('Attribution') 34 expect(videoHttp.licence.label).to.equal('Attribution')
34 expect(video.language.label).to.equal('Unknown') 35 expect(videoHttp.language.label).to.equal('Unknown')
35 expect(video.nsfw).to.be.false 36 expect(videoHttp.nsfw).to.be.false
36 expect(video.description).to.equal('this is a super description') 37 expect(videoHttp.description).to.equal('this is a super description')
37 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) 38 expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])
39 expect(videoHttp.files).to.have.lengthOf(1)
40
41 const resMagnet = await getVideo(url, idMagnet)
42 const videoMagnet: VideoDetails = resMagnet.body
43 const resTorrent = await getVideo(url, idTorrent)
44 const videoTorrent: VideoDetails = resTorrent.body
45
46 for (const video of [ videoMagnet, videoTorrent ]) {
47 expect(video.category.label).to.equal('Misc')
48 expect(video.licence.label).to.equal('Unknown')
49 expect(video.language.label).to.equal('Unknown')
50 expect(video.nsfw).to.be.false
51 expect(video.description).to.equal('this is a super torrent description')
52 expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ])
53 expect(video.files).to.have.lengthOf(1)
54 }
38 55
39 expect(video.files).to.have.lengthOf(1) 56 expect(videoTorrent.name).to.contain('你好 世界 720p.mp4')
57 expect(videoMagnet.name).to.contain('super peertube2 video')
40 } 58 }
41 59
42 async function checkVideoServer2 (url: string, id: number | string) { 60 async function checkVideoServer2 (url: string, id: number | string) {
@@ -75,50 +93,88 @@ describe('Test video imports', function () {
75 await doubleFollow(servers[0], servers[1]) 93 await doubleFollow(servers[0], servers[1])
76 }) 94 })
77 95
78 it('Should import a video on server 1', async function () { 96 it('Should import videos on server 1', async function () {
79 this.timeout(60000) 97 this.timeout(60000)
80 98
81 const attributes = { 99 const baseAttributes = {
82 targetUrl: getYoutubeVideoUrl(),
83 channelId: channelIdServer1, 100 channelId: channelIdServer1,
84 privacy: VideoPrivacy.PUBLIC 101 privacy: VideoPrivacy.PUBLIC
85 } 102 }
86 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 103
87 expect(res.body.video.name).to.equal('small video - youtube') 104 {
105 const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
106 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
107 expect(res.body.video.name).to.equal('small video - youtube')
108 }
109
110 {
111 const attributes = immutableAssign(baseAttributes, {
112 magnetUri: getMagnetURI(),
113 description: 'this is a super torrent description',
114 tags: [ 'tag_torrent1', 'tag_torrent2' ]
115 })
116 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
117 expect(res.body.video.name).to.equal('super peertube2 video')
118 }
119
120 {
121 const attributes = immutableAssign(baseAttributes, {
122 torrentfile: 'video-720p.torrent',
123 description: 'this is a super torrent description',
124 tags: [ 'tag_torrent1', 'tag_torrent2' ]
125 })
126 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
127 expect(res.body.video.name).to.equal('你好 世界 720p.mp4')
128 }
88 }) 129 })
89 130
90 it('Should list the video to import in my videos on server 1', async function () { 131 it('Should list the videos to import in my videos on server 1', async function () {
91 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 132 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt')
92 133
93 expect(res.body.total).to.equal(1) 134 expect(res.body.total).to.equal(3)
94 135
95 const videos = res.body.data 136 const videos = res.body.data
96 expect(videos).to.have.lengthOf(1) 137 expect(videos).to.have.lengthOf(3)
97 expect(videos[0].name).to.equal('small video - youtube') 138 expect(videos[0].name).to.equal('small video - youtube')
139 expect(videos[1].name).to.equal('super peertube2 video')
140 expect(videos[2].name).to.equal('你好 世界 720p.mp4')
98 }) 141 })
99 142
100 it('Should list the video to import in my imports on server 1', async function () { 143 it('Should list the videos to import in my imports on server 1', async function () {
101 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) 144 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt')
145
146 expect(res.body.total).to.equal(3)
147 const videoImports: VideoImport[] = res.body.data
148 expect(videoImports).to.have.lengthOf(3)
149
150 expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl())
151 expect(videoImports[2].magnetUri).to.be.null
152 expect(videoImports[2].torrentName).to.be.null
153 expect(videoImports[2].video.name).to.equal('small video - youtube')
102 154
103 expect(res.body.total).to.equal(1) 155 expect(videoImports[1].targetUrl).to.be.null
104 const videoImports = res.body.data 156 expect(videoImports[1].magnetUri).to.equal(getMagnetURI())
105 expect(videoImports).to.have.lengthOf(1) 157 expect(videoImports[1].torrentName).to.be.null
158 expect(videoImports[1].video.name).to.equal('super peertube2 video')
106 159
107 expect(videoImports[0].targetUrl).to.equal(getYoutubeVideoUrl()) 160 expect(videoImports[0].targetUrl).to.be.null
108 expect(videoImports[0].video.name).to.equal('small video - youtube') 161 expect(videoImports[0].magnetUri).to.be.null
162 expect(videoImports[0].torrentName).to.equal('video-720p.torrent')
163 expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4')
109 }) 164 })
110 165
111 it('Should have the video listed on the two instances1', async function () { 166 it('Should have the video listed on the two instances', async function () {
112 this.timeout(120000) 167 this.timeout(120000)
113 168
114 await waitJobs(servers) 169 await waitJobs(servers)
115 170
116 for (const server of servers) { 171 for (const server of servers) {
117 const res = await getVideosList(server.url) 172 const res = await getVideosList(server.url)
118 expect(res.body.total).to.equal(1) 173 expect(res.body.total).to.equal(3)
119 expect(res.body.data).to.have.lengthOf(1) 174 expect(res.body.data).to.have.lengthOf(3)
120 175
121 await checkVideoServer1(server.url, res.body.data[0].uuid) 176 const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data
177 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
122 } 178 }
123 }) 179 })
124 180
@@ -127,7 +183,7 @@ describe('Test video imports', function () {
127 183
128 const attributes = { 184 const attributes = {
129 targetUrl: getYoutubeVideoUrl(), 185 targetUrl: getYoutubeVideoUrl(),
130 channelId: channelIdServer1, 186 channelId: channelIdServer2,
131 privacy: VideoPrivacy.PUBLIC, 187 privacy: VideoPrivacy.PUBLIC,
132 category: 10, 188 category: 10,
133 licence: 7, 189 licence: 7,
@@ -140,18 +196,43 @@ describe('Test video imports', function () {
140 expect(res.body.video.name).to.equal('my super name') 196 expect(res.body.video.name).to.equal('my super name')
141 }) 197 })
142 198
143 it('Should have the video listed on the two instances', async function () { 199 it('Should have the videos listed on the two instances', async function () {
144 this.timeout(120000) 200 this.timeout(120000)
145 201
146 await waitJobs(servers) 202 await waitJobs(servers)
147 203
148 for (const server of servers) { 204 for (const server of servers) {
149 const res = await getVideosList(server.url) 205 const res = await getVideosList(server.url)
150 expect(res.body.total).to.equal(2) 206 expect(res.body.total).to.equal(4)
151 expect(res.body.data).to.have.lengthOf(2) 207 expect(res.body.data).to.have.lengthOf(4)
152 208
153 await checkVideoServer2(server.url, res.body.data[0].uuid) 209 await checkVideoServer2(server.url, res.body.data[0].uuid)
154 await checkVideoServer1(server.url, res.body.data[1].uuid) 210
211 const [ ,videoHttp, videoMagnet, videoTorrent ] = res.body.data
212 await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid)
213 }
214 })
215
216 it('Should import a video that will be transcoded', async function () {
217 this.timeout(120000)
218
219 const attributes = {
220 name: 'transcoded video',
221 magnetUri: getMagnetURI(),
222 channelId: channelIdServer2,
223 privacy: VideoPrivacy.PUBLIC
224 }
225 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
226 const videoUUID = res.body.video.uuid
227
228 await waitJobs(servers)
229
230 for (const server of servers) {
231 const res = await getVideo(server.url, videoUUID)
232 const video: VideoDetails = res.body
233
234 expect(video.name).to.equal('transcoded video')
235 expect(video.files).to.have.lengthOf(4)
155 } 236 }
156 }) 237 })
157 238
diff --git a/server/tests/fixtures/60fps_small-240p.torrent b/server/tests/fixtures/60fps_small-240p.torrent
deleted file mode 100644
index ec4c0babe..000000000
--- a/server/tests/fixtures/60fps_small-240p.torrent
+++ /dev/null
@@ -1 +0,0 @@
1d8:announce41:wss://peertube2.cpy.re:443/tracker/socket13:announce-listll41:wss://peertube2.cpy.re:443/tracker/socketel41:https://peertube2.cpy.re/tracker/announceee10:created by8:PeerTube13:creation datei1529593069e8:encoding5:UTF-84:infod6:lengthi30921e4:name20:60fps_small 240p.mp412:piece lengthi16384e6:pieces40:Ä–…+çéCFm7çc0ÏÅT-@2Ç6©0áMür|Rv›$˜h%e8:url-listl84:https://peertube2.cpy.re/static/webseed/2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.mp4ee \ No newline at end of file
diff --git a/server/tests/fixtures/video-720p.torrent b/server/tests/fixtures/video-720p.torrent
new file mode 100644
index 000000000..64bfd5220
--- /dev/null
+++ b/server/tests/fixtures/video-720p.torrent
Binary files differ
diff --git a/server/tests/utils/videos/video-imports.ts b/server/tests/utils/videos/video-imports.ts
index fa2f13b5e..59dfd481a 100644
--- a/server/tests/utils/videos/video-imports.ts
+++ b/server/tests/utils/videos/video-imports.ts
@@ -1,5 +1,5 @@
1import { VideoImportCreate } from '../../../../shared/models/videos' 1import { VideoImportCreate } from '../../../../shared/models/videos'
2import { makeGetRequest, makePostBodyRequest, makeUploadRequest } from '..' 2import { makeGetRequest, makeUploadRequest } from '..'
3 3
4function getYoutubeVideoUrl () { 4function getYoutubeVideoUrl () {
5 return 'https://youtu.be/msX3jv1XdvM' 5 return 'https://youtu.be/msX3jv1XdvM'
@@ -7,7 +7,7 @@ function getYoutubeVideoUrl () {
7 7
8function getMagnetURI () { 8function getMagnetURI () {
9 // tslint:disable:max-line-length 9 // tslint:disable:max-line-length
10 return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2F2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.torrent&xt=urn:btih:52bf3729e5859390a8751495196b5674a55c99f3&dn=60fps_small&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%2F2b8dbe74-9548-4f6f-a8da-986aed9e5e45-240.mp4' 10 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'
11} 11}
12 12
13function importVideo (url: string, token: string, attributes: VideoImportCreate) { 13function importVideo (url: string, token: string, attributes: VideoImportCreate) {
@@ -26,11 +26,15 @@ function importVideo (url: string, token: string, attributes: VideoImportCreate)
26 }) 26 })
27} 27}
28 28
29function getMyVideoImports (url: string, token: string) { 29function getMyVideoImports (url: string, token: string, sort?: string) {
30 const path = '/api/v1/users/me/videos/imports' 30 const path = '/api/v1/users/me/videos/imports'
31 31
32 const query = {}
33 if (sort) query['sort'] = sort
34
32 return makeGetRequest({ 35 return makeGetRequest({
33 url, 36 url,
37 query,
34 path, 38 path,
35 token, 39 token,
36 statusCodeExpected: 200 40 statusCodeExpected: 200