+import { readFile } from 'fs'
import * as request from 'supertest'
import { join, isAbsolute } from 'path'
+import * as parseTorrent from 'parse-torrent'
import { makeGetRequest } from './requests'
import { readFilePromise } from './miscs'
+import { ServerInfo } from './servers'
type VideoAttributes = {
name?: string
}
function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) {
- const path = '/api/v1/videos'
+ const path = '/api/v1/videos/upload'
// Default attributes
let attributes = {
.field('name', attributes.name)
.field('category', attributes.category.toString())
.field('licence', attributes.licence.toString())
- .field('language', attributes.language.toString())
.field('nsfw', JSON.stringify(attributes.nsfw))
.field('description', attributes.description)
+ if (attributes.language !== undefined) {
+ req.field('language', attributes.language.toString())
+ }
+
for (let i = 0; i < attributes.tags.length; i++) {
req.field('tags[' + i + ']', attributes.tags[i])
}
.expect(specialStatus)
}
+function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolutionLabel: string) {
+ return new Promise<any>((res, rej) => {
+ const torrentName = videoUUID + '-' + resolutionLabel + '.torrent'
+ const torrentPath = join(__dirname, '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName)
+ readFile(torrentPath, (err, data) => {
+ if (err) return rej(err)
+
+ return res(parseTorrent(data))
+ })
+ })
+}
+
// ---------------------------------------------------------------------------
export {
testVideoImage,
uploadVideo,
updateVideo,
- rateVideo
+ rateVideo,
+ parseTorrentVideo
}