From 04a0ed13b40cd01a6ee3ec5f92e22bbbebe29374 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Jan 2024 08:57:57 +0100 Subject: [PATCH] Also update playlist URLs --- .../src/videos/playlists-command.ts | 2 +- packages/tests/src/cli/update-host.ts | 27 ++++++++++++ server/scripts/update-host.ts | 44 ++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/packages/server-commands/src/videos/playlists-command.ts b/packages/server-commands/src/videos/playlists-command.ts index 2e483f318..99f3e3c0d 100644 --- a/packages/server-commands/src/videos/playlists-command.ts +++ b/packages/server-commands/src/videos/playlists-command.ts @@ -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' ]) diff --git a/packages/tests/src/cli/update-host.ts b/packages/tests/src/cli/update-host.ts index e5f165e5e..38b160d2c 100644 --- a/packages/tests/src/cli/update-host.ts +++ b/packages/tests/src/cli/update-host.ts @@ -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) diff --git a/server/scripts/update-host.ts b/server/scripts/update-host.ts index d5c378e68..47b3362d3 100755 --- a/server/scripts/update-host.ts +++ b/server/scripts/update-host.ts @@ -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()