Also update playlist URLs
This commit is contained in:
parent
5cf5465d20
commit
04a0ed13b4
3 changed files with 71 additions and 2 deletions
|
@ -25,7 +25,7 @@ export class PlaylistsCommand extends AbstractCommand {
|
|||
count?: number
|
||||
sort?: string
|
||||
playlistType?: VideoPlaylistType_Type
|
||||
}) {
|
||||
} = {}) {
|
||||
const path = '/api/v1/video-playlists'
|
||||
const query = pick(options, [ 'start', 'count', 'sort', 'playlistType' ])
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@ import {
|
|||
makeActivityPubGetRequest,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultVideoChannel,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
import { parseTorrentVideo } from '@tests/shared/webtorrent.js'
|
||||
import { VideoPlaylistPrivacy } from '@peertube/peertube-models'
|
||||
|
||||
describe('Test update host scripts', function () {
|
||||
let server: PeerTubeServer
|
||||
|
@ -27,6 +29,7 @@ describe('Test update host scripts', function () {
|
|||
// Run server 2 to have transcoding enabled
|
||||
server = await createSingleServer(2, overrideConfig)
|
||||
await setAccessTokensToServers([ server ])
|
||||
await setDefaultVideoChannel([ server ])
|
||||
|
||||
// Upload two videos for our needs
|
||||
const { uuid: video1UUID } = await server.videos.upload()
|
||||
|
@ -47,6 +50,13 @@ describe('Test update host scripts', function () {
|
|||
const text = 'my super first comment'
|
||||
await server.comments.createThread({ videoId: video1UUID, text })
|
||||
|
||||
// Playlist
|
||||
{
|
||||
const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: server.store.channel.id }
|
||||
const playlist = await server.playlists.create({ attributes })
|
||||
await server.playlists.addElement({ playlistId: playlist.id, attributes: { videoId: video1UUID } })
|
||||
}
|
||||
|
||||
await waitJobs(server)
|
||||
})
|
||||
|
||||
|
@ -100,6 +110,23 @@ describe('Test update host scripts', function () {
|
|||
}
|
||||
})
|
||||
|
||||
it('Should have updated playlist url', async function () {
|
||||
const body = await server.playlists.list()
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
for (const playlist of body.data) {
|
||||
const { body } = await makeActivityPubGetRequest(server.url, '/video-playlists/' + playlist.uuid)
|
||||
expect(body.id).to.equal('http://127.0.0.1:9002/video-playlists/' + playlist.uuid)
|
||||
|
||||
const { data: elements } = await server.playlists.listVideos({ playlistId: playlist.id })
|
||||
|
||||
for (const element of elements) {
|
||||
const { body } = await makeActivityPubGetRequest(server.url, `/video-playlists/${playlist.uuid}/videos/${element.id}`)
|
||||
expect(body.id).to.equal(`http://127.0.0.1:9002/video-playlists/${playlist.uuid}/videos/${element.id}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should have updated torrent hosts', async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@ import {
|
|||
getLocalVideoActivityPubUrl,
|
||||
getLocalVideoAnnounceActivityPubUrl,
|
||||
getLocalVideoChannelActivityPubUrl,
|
||||
getLocalVideoCommentActivityPubUrl
|
||||
getLocalVideoCommentActivityPubUrl,
|
||||
getLocalVideoPlaylistActivityPubUrl,
|
||||
getLocalVideoPlaylistElementActivityPubUrl
|
||||
} from '@server/lib/activitypub/url.js'
|
||||
import { AccountModel } from '@server/models/account/account.js'
|
||||
import { ActorFollowModel } from '@server/models/actor/actor-follow.js'
|
||||
|
@ -17,6 +19,8 @@ import { VideoCommentModel } from '@server/models/video/video-comment.js'
|
|||
import { VideoShareModel } from '@server/models/video/video-share.js'
|
||||
import { VideoModel } from '@server/models/video/video.js'
|
||||
import { MActorAccount } from '@server/types/models/index.js'
|
||||
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
|
||||
import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element.js'
|
||||
|
||||
run()
|
||||
.then(() => process.exit(0))
|
||||
|
@ -122,6 +126,44 @@ async function run () {
|
|||
await comment.save()
|
||||
}
|
||||
|
||||
console.log('Updating video playlists.')
|
||||
const videoPlaylists: VideoPlaylistModel[] = await VideoPlaylistModel.findAll({
|
||||
include: [
|
||||
{
|
||||
model: AccountModel.unscoped(),
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
model: ActorModel.unscoped(),
|
||||
where: {
|
||||
serverId: null
|
||||
},
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
for (const playlist of videoPlaylists) {
|
||||
console.log('Updating video playlist ' + playlist.url)
|
||||
|
||||
playlist.url = getLocalVideoPlaylistActivityPubUrl(playlist)
|
||||
await playlist.save()
|
||||
|
||||
const elements: VideoPlaylistElementModel[] = await VideoPlaylistElementModel.findAll({
|
||||
where: {
|
||||
videoPlaylistId: playlist.id
|
||||
}
|
||||
})
|
||||
|
||||
for (const element of elements) {
|
||||
console.log('Updating video playlist element ' + element.url)
|
||||
|
||||
element.url = getLocalVideoPlaylistElementActivityPubUrl(playlist, element)
|
||||
await element.save()
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Updating video and torrent files.')
|
||||
|
||||
const ids = await VideoModel.listLocalIds()
|
||||
|
|
Loading…
Reference in a new issue