Verified Commit e6346d59 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce playlist command

parent 72cbfc56
......@@ -5,6 +5,7 @@ import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists'
import { Hooks } from '@server/lib/plugins/hooks'
import { getServerActor } from '@server/models/application/application'
import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models'
import { VideoPlaylistCreateResult, VideoPlaylistElementCreateResult } from '@shared/models'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model'
import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model'
......@@ -202,7 +203,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
id: videoPlaylistCreated.id,
shortUUID: uuidToShort(videoPlaylistCreated.uuid),
uuid: videoPlaylistCreated.uuid
}
} as VideoPlaylistCreateResult
})
}
......@@ -338,8 +339,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
return res.json({
videoPlaylistElement: {
id: playlistElement.id
}
}).end()
} as VideoPlaylistElementCreateResult
})
}
async function updateVideoPlaylistElement (req: express.Request, res: express.Response) {
......
......@@ -6,7 +6,6 @@ import { VideoPlaylistPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
cleanupTests,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
makeActivityPubGetRequest,
......@@ -74,9 +73,8 @@ describe('Test activitypub', function () {
}
{
const playlistAttrs = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
const resCreate = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
playlist = resCreate.body.videoPlaylist
const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
playlist = await servers[0].playlistsCommand.create({ attributes })
}
await doubleFollow(servers[0], servers[1])
......
......@@ -5,12 +5,10 @@ import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
closeAllSequelize,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
generateUserAccessToken,
getVideo,
getVideoPlaylist,
killallServers,
reRunServer,
ServerInfo,
......@@ -58,15 +56,15 @@ describe('Test AP refresher', function () {
}
{
const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
playlistUUID1 = res.body.videoPlaylist.uuid
const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const created = await servers[1].playlistsCommand.create({ attributes })
playlistUUID1 = created.uuid
}
{
const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs })
playlistUUID2 = res.body.videoPlaylist.uuid
const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id }
const created = await servers[1].playlistsCommand.create({ attributes })
playlistUUID2 = created.uuid
}
await doubleFollow(servers[0], servers[1])
......@@ -144,13 +142,13 @@ describe('Test AP refresher', function () {
// Change UUID so the remote server returns a 404
await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
await getVideoPlaylist(servers[0].url, playlistUUID1)
await getVideoPlaylist(servers[0].url, playlistUUID2)
await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 })
await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 })
await waitJobs(servers)
await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200)
await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404)
await servers[0].playlistsCommand.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
await servers[0].playlistsCommand.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
})
......
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import { VideoPlaylistPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
cleanupTests,
flushAndRunServer,
makeGetRequest,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
createVideoPlaylist,
setDefaultVideoChannel
setDefaultVideoChannel,
uploadVideo
} from '../../../../shared/extra-utils'
import { VideoPlaylistPrivacy } from '@shared/models'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
describe('Test services API validators', function () {
let server: ServerInfo
......@@ -34,17 +32,15 @@ describe('Test services API validators', function () {
}
{
const res = await createVideoPlaylist({
url: server.url,
token: server.accessToken,
playlistAttrs: {
const created = await server.playlistsCommand.create({
attributes: {
displayName: 'super playlist',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: server.videoChannel.id
}
})
playlistUUID = res.body.videoPlaylist.uuid
playlistUUID = created.uuid
}
})
......
......@@ -3,12 +3,8 @@
import 'mocha'
import * as chai from 'chai'
import {
addVideoInPlaylist,
cleanupTests,
createVideoPlaylist,
deleteVideoPlaylist,
flushAndRunMultipleServers,
getVideoPlaylistsList,
SearchCommand,
ServerInfo,
setAccessTokensToServers,
......@@ -46,16 +42,11 @@ describe('Test ActivityPub playlists search', function () {
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: servers[0].videoChannel.id
}
const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs: attributes })
playlistServer1UUID = res.body.videoPlaylist.uuid
const created = await servers[0].playlistsCommand.create({ attributes })
playlistServer1UUID = created.uuid
for (const videoId of [ video1, video2 ]) {
await addVideoInPlaylist({
url: servers[0].url,
token: servers[0].accessToken,
playlistId: playlistServer1UUID,
elementAttrs: { videoId }
})
await servers[0].playlistsCommand.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } })
}
}
......@@ -68,15 +59,10 @@ describe('Test ActivityPub playlists search', function () {
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: servers[1].videoChannel.id
}
const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs: attributes })
playlistServer2UUID = res.body.videoPlaylist.uuid
await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistServer2UUID,
elementAttrs: { videoId }
})
const created = await servers[1].playlistsCommand.create({ attributes })
playlistServer2UUID = created.uuid
await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } })
}
await waitJobs(servers)
......@@ -154,21 +140,16 @@ describe('Test ActivityPub playlists search', function () {
})
it('Should not list this remote playlist', async function () {
const res = await getVideoPlaylistsList(servers[0].url, 0, 10)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.have.lengthOf(1)
expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1')
const body = await servers[0].playlistsCommand.list({ start: 0, count: 10 })
expect(body.total).to.equal(1)
expect(body.data).to.have.lengthOf(1)
expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
})
it('Should update the playlist of server 2, and refresh it on server 1', async function () {
this.timeout(60000)
await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistServer2UUID,
elementAttrs: { videoId: video2Server2 }
})
await servers[1].playlistsCommand.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } })
await waitJobs(servers)
// Expire playlist
......@@ -192,7 +173,7 @@ describe('Test ActivityPub playlists search', function () {
it('Should delete playlist of server 2, and delete it on server 1', async function () {
this.timeout(60000)
await deleteVideoPlaylist(servers[1].url, servers[1].accessToken, playlistServer2UUID)
await servers[1].playlistsCommand.delete({ playlistId: playlistServer2UUID })
await waitJobs(servers)
// Expiration
......
......@@ -4,9 +4,7 @@ import 'mocha'
import * as chai from 'chai'
import { VideoPlaylistPrivacy } from '@shared/models'
import {
addVideoInPlaylist,
cleanupTests,
createVideoPlaylist,
flushAndRunServer,
SearchCommand,
ServerInfo,
......@@ -37,14 +35,9 @@ describe('Test playlists search', function () {
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: server.videoChannel.id
}
const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
await addVideoInPlaylist({
url: server.url,
token: server.accessToken,
playlistId: res.body.videoPlaylist.id,
elementAttrs: { videoId }
})
const created = await server.playlistsCommand.create({ attributes })
await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } })
}
{
......@@ -53,14 +46,9 @@ describe('Test playlists search', function () {
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: server.videoChannel.id
}
const res = await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
await addVideoInPlaylist({
url: server.url,
token: server.accessToken,
playlistId: res.body.videoPlaylist.id,
elementAttrs: { videoId }
})
const created = await server.playlistsCommand.create({ attributes })
await server.playlistsCommand.addElement({ playlistId: created.id, attributes: { videoId } })
}
{
......@@ -69,7 +57,7 @@ describe('Test playlists search', function () {
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: server.videoChannel.id
}
await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attributes })
await server.playlistsCommand.create({ attributes })
}
command = server.searchCommand
......
......@@ -4,8 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import { Video, VideoPlaylistPrivacy } from '@shared/models'
import {
addVideoInPlaylist,
createVideoPlaylist,
getVideosList,
ServerInfo,
setAccessTokensToServers,
......@@ -41,24 +39,20 @@ describe('Test services', function () {
}
{
const res = await createVideoPlaylist({
url: server.url,
token: server.accessToken,
playlistAttrs: {
const created = await server.playlistsCommand.create({
attributes: {
displayName: 'The Life and Times of Scrooge McDuck',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: server.videoChannel.id
}
})
playlistUUID = res.body.videoPlaylist.uuid
playlistUUID = created.uuid
playlistDisplayName = 'The Life and Times of Scrooge McDuck'
await addVideoInPlaylist({
url: server.url,
token: server.accessToken,
playlistId: res.body.videoPlaylist.id,
elementAttrs: {
await server.playlistsCommand.addElement({
playlistId: created.id,
attributes: {
videoId: video.id
}
})
......
......@@ -7,7 +7,6 @@ import {
addVideoCommentThread,
cleanupTests,
createUser,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
......@@ -178,10 +177,8 @@ describe('Test stats (excluding redundancy)', function () {
}
{
await createVideoPlaylist({
url: server.url,
token: server.accessToken,
playlistAttrs: {
await server.playlistsCommand.create({
attributes: {
displayName: 'playlist for count',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: channelId
......
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import * as chai from 'chai'
import 'mocha'
import * as chai from 'chai'
import {
addVideoInPlaylist,
cleanupTests,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
getVideoPlaylistsList,
removeVideoFromPlaylist,
reorderVideosPlaylist,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
......@@ -25,8 +20,8 @@ const expect = chai.expect
describe('Playlist thumbnail', function () {
let servers: ServerInfo[] = []
let playlistWithoutThumbnail: number
let playlistWithThumbnail: number
let playlistWithoutThumbnailId: number
let playlistWithThumbnailId: number
let withThumbnailE1: number
let withThumbnailE2: number
......@@ -37,15 +32,15 @@ describe('Playlist thumbnail', function () {
let video2: number
async function getPlaylistWithoutThumbnail (server: ServerInfo) {
const res = await getVideoPlaylistsList(server.url, 0, 10)
const body = await server.playlistsCommand.list({ start: 0, count: 10 })
return res.body.data.find(p => p.displayName === 'playlist without thumbnail')
return body.data.find(p => p.displayName === 'playlist without thumbnail')
}
async function getPlaylistWithThumbnail (server: ServerInfo) {
const res = await getVideoPlaylistsList(server.url, 0, 10)
const body = await server.playlistsCommand.list({ start: 0, count: 10 })
return res.body.data.find(p => p.displayName === 'playlist with thumbnail')
return body.data.find(p => p.displayName === 'playlist with thumbnail')
}
before(async function () {
......@@ -69,24 +64,20 @@ describe('Playlist thumbnail', function () {
it('Should automatically update the thumbnail when adding an element', async function () {
this.timeout(30000)
const res = await createVideoPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistAttrs: {
const created = await servers[1].playlistsCommand.create({
attributes: {
displayName: 'playlist without thumbnail',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: servers[1].videoChannel.id
}
})
playlistWithoutThumbnail = res.body.videoPlaylist.id
playlistWithoutThumbnailId = created.id
const res2 = await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithoutThumbnail,
elementAttrs: { videoId: video1 }
const added = await servers[1].playlistsCommand.addElement({
playlistId: playlistWithoutThumbnailId,
attributes: { videoId: video1 }
})
withoutThumbnailE1 = res2.body.videoPlaylistElement.id
withoutThumbnailE1 = added.id
await waitJobs(servers)
......@@ -99,25 +90,21 @@ describe('Playlist thumbnail', function () {
it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () {
this.timeout(30000)
const res = await createVideoPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistAttrs: {
const created = await servers[1].playlistsCommand.create({
attributes: {
displayName: 'playlist with thumbnail',
privacy: VideoPlaylistPrivacy.PUBLIC,
videoChannelId: servers[1].videoChannel.id,
thumbnailfile: 'thumbnail.jpg'
}
})
playlistWithThumbnail = res.body.videoPlaylist.id
playlistWithThumbnailId = created.id
const res2 = await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithThumbnail,
elementAttrs: { videoId: video1 }
const added = await servers[1].playlistsCommand.addElement({
playlistId: playlistWithThumbnailId,
attributes: { videoId: video1 }
})
withThumbnailE1 = res2.body.videoPlaylistElement.id
withThumbnailE1 = added.id
await waitJobs(servers)
......@@ -130,19 +117,15 @@ describe('Playlist thumbnail', function () {
it('Should automatically update the thumbnail when moving the first element', async function () {
this.timeout(30000)
const res = await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithoutThumbnail,
elementAttrs: { videoId: video2 }
const added = await servers[1].playlistsCommand.addElement({
playlistId: playlistWithoutThumbnailId,
attributes: { videoId: video2 }
})
withoutThumbnailE2 = res.body.videoPlaylistElement.id
withoutThumbnailE2 = added.id
await reorderVideosPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithoutThumbnail,
elementAttrs: {
await servers[1].playlistsCommand.reorderElements({
playlistId: playlistWithoutThumbnailId,
attributes: {
startPosition: 1,
insertAfterPosition: 2
}
......@@ -159,19 +142,15 @@ describe('Playlist thumbnail', function () {
it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () {
this.timeout(30000)
const res = await addVideoInPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithThumbnail,
elementAttrs: { videoId: video2 }
const added = await servers[1].playlistsCommand.addElement({
playlistId: playlistWithThumbnailId,
attributes: { videoId: video2 }
})
withThumbnailE2 = res.body.videoPlaylistElement.id
withThumbnailE2 = added.id
await reorderVideosPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithThumbnail,
elementAttrs: {
await servers[1].playlistsCommand.reorderElements({
playlistId: playlistWithThumbnailId,
attributes: {
startPosition: 1,
insertAfterPosition: 2
}
......@@ -188,11 +167,9 @@ describe('Playlist thumbnail', function () {
it('Should automatically update the thumbnail when deleting the first element', async function () {
this.timeout(30000)
await removeVideoFromPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithoutThumbnail,
playlistElementId: withoutThumbnailE1
await servers[1].playlistsCommand.removeElement({
playlistId: playlistWithoutThumbnailId,
elementId: withoutThumbnailE1
})
await waitJobs(servers)
......@@ -206,11 +183,9 @@ describe('Playlist thumbnail', function () {
it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () {
this.timeout(30000)
await removeVideoFromPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithThumbnail,
playlistElementId: withThumbnailE1
await servers[1].playlistsCommand.removeElement({
playlistId: playlistWithThumbnailId,
elementId: withThumbnailE1
})
await waitJobs(servers)
......@@ -224,11 +199,9 @@ describe('Playlist thumbnail', function () {
it('Should the thumbnail when we delete the last element', async function () {
this.timeout(30000)
await removeVideoFromPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithoutThumbnail,
playlistElementId: withoutThumbnailE2
await servers[1].playlistsCommand.removeElement({
playlistId: playlistWithoutThumbnailId,
elementId: withoutThumbnailE2
})
await waitJobs(servers)
......@@ -242,11 +215,9 @@ describe('Playlist thumbnail', function () {
it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () {
this.timeout(30000)
await removeVideoFromPlaylist({
url: servers[1].url,
token: servers[1].accessToken,
playlistId: playlistWithThumbnail,
playlistElementId: withThumbnailE2
await servers[1].playlistsCommand.removeElement({
playlistId: playlistWithThumbnailId,
elementId: withThumbnailE2
})
await waitJobs(servers)
......
This diff is collapsed.
......@@ -10,7 +10,6 @@ import {
buildServerDirectory,
cleanupTests,
CLICommand,
createVideoPlaylist,
doubleFollow,
flushAndRunMultipleServers,
killallServers,
......@@ -77,10 +76,8 @@ describe('Test prune storage scripts', function () {