import { expect } from 'chai'
import { createReadStream, stat } from 'fs-extra'
import got, { Response as GotResponse } from 'got'
-import { omit, pick } from 'lodash'
+import { omit } from 'lodash'
import validator from 'validator'
import { buildUUID } from '@server/helpers/uuid'
import { loadLanguages } from '@server/initializers/constants'
-import { HttpStatusCode } from '@shared/models'
+import { pick } from '@shared/core-utils'
import {
+ HttpStatusCode,
ResultList,
UserVideoRateType,
Video,
return id
}
+ async listFiles (options: OverrideCommandOptions & {
+ id: number | string
+ }) {
+ const video = await this.get(options)
+
+ const files = video.files || []
+ const hlsFiles = video.streamingPlaylists[0]?.files || []
+
+ return files.concat(hlsFiles)
+ }
+
// ---------------------------------------------------------------------------
listMyVideos (options: OverrideCommandOptions & {
// ---------------------------------------------------------------------------
+ async find (options: OverrideCommandOptions & {
+ name: string
+ }) {
+ const { data } = await this.list(options)
+
+ return data.find(v => v.name === options.name)
+ }
+
+ // ---------------------------------------------------------------------------
+
update (options: OverrideCommandOptions & {
id: number | string
attributes?: VideoEdit
attributes?: VideoEdit
mode?: 'legacy' | 'resumable' // default legacy
} = {}) {
- const { mode = 'legacy', expectedStatus } = options
+ const { mode = 'legacy' } = options
let defaultChannelId = 1
try {
...options.attributes
}
- const res = mode === 'legacy'
+ const created = mode === 'legacy'
? await this.buildLegacyUpload({ ...options, attributes })
: await this.buildResumeUpload({ ...options, attributes })
// Wait torrent generation
+ const expectedStatus = this.buildExpectedStatus({ ...options, defaultExpectedStatus: HttpStatusCode.OK_200 })
if (expectedStatus === HttpStatusCode.OK_200) {
let video: VideoDetails
do {
- video = await this.getWithToken({ ...options, id: video.uuid })
+ video = await this.getWithToken({ ...options, id: created.uuid })
await wait(50)
} while (!video.files[0].torrentUrl)
}
- return res
+ return created
}
async buildLegacyUpload (options: OverrideCommandOptions & {
async randomUpload (options: OverrideCommandOptions & {
wait?: boolean // default true
- additionalParams?: VideoEdit & { prefixName: string }
+ additionalParams?: VideoEdit & { prefixName?: string }
} = {}) {
const { wait = true, additionalParams } = options
const prefixName = additionalParams?.prefixName || ''
const name = prefixName + buildUUID()
- const attributes = { name, additionalParams }
+ const attributes = { name, ...additionalParams }
const result = await this.upload({ ...options, attributes })