2019-10-21 11:13:07 -04:00
|
|
|
import { registerTSPaths } from '../server/helpers/register-ts-paths'
|
2019-11-27 05:38:40 -05:00
|
|
|
registerTSPaths()
|
|
|
|
|
2019-04-11 08:26:41 -04:00
|
|
|
import { WEBSERVER } from '../server/initializers/constants'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { ActorFollowModel } from '../server/models/actor/actor-follow'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../server/models/video/video'
|
2021-05-11 05:15:29 -04:00
|
|
|
import { ActorModel } from '../server/models/actor/actor'
|
2018-06-21 12:29:28 -04:00
|
|
|
import {
|
2020-11-20 05:21:08 -05:00
|
|
|
getLocalAccountActivityPubUrl,
|
|
|
|
getLocalVideoActivityPubUrl,
|
|
|
|
getLocalVideoAnnounceActivityPubUrl,
|
|
|
|
getLocalVideoChannelActivityPubUrl,
|
|
|
|
getLocalVideoCommentActivityPubUrl
|
2020-04-23 05:36:50 -04:00
|
|
|
} from '../server/lib/activitypub/url'
|
2018-06-21 12:29:28 -04:00
|
|
|
import { VideoShareModel } from '../server/models/video/video-share'
|
|
|
|
import { VideoCommentModel } from '../server/models/video/video-comment'
|
|
|
|
import { AccountModel } from '../server/models/account/account'
|
|
|
|
import { VideoChannelModel } from '../server/models/video/video-channel'
|
2020-05-07 08:58:24 -04:00
|
|
|
import { initDatabaseModels } from '../server/initializers/database'
|
2021-08-18 03:14:51 -04:00
|
|
|
import { updateTorrentUrls } from '@server/helpers/webtorrent'
|
2020-04-23 05:36:50 -04:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
2019-11-15 09:06:03 -05:00
|
|
|
|
2018-06-21 12:29:28 -04:00
|
|
|
run()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(-1)
|
2017-11-17 10:24:08 -05:00
|
|
|
})
|
2018-06-21 12:29:28 -04:00
|
|
|
|
|
|
|
async function run () {
|
|
|
|
await initDatabaseModels(true)
|
|
|
|
|
|
|
|
const serverAccount = await getServerActor()
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
|
|
|
|
const hasFollowing = res.total > 0
|
|
|
|
|
2017-11-17 10:24:08 -05:00
|
|
|
if (hasFollowing === true) {
|
2018-06-21 12:29:28 -04:00
|
|
|
throw new Error('Cannot update host because you follow other servers!')
|
2017-06-12 15:06:32 -04:00
|
|
|
}
|
2018-06-21 12:29:28 -04:00
|
|
|
}
|
2017-06-12 15:06:32 -04:00
|
|
|
|
2018-06-21 12:29:28 -04:00
|
|
|
console.log('Updating actors.')
|
|
|
|
|
|
|
|
const actors: ActorModel[] = await ActorModel.unscoped().findAll({
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: VideoChannelModel.unscoped(),
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: AccountModel.unscoped(),
|
|
|
|
required: false
|
2018-03-20 03:54:24 -04:00
|
|
|
}
|
2018-06-21 12:29:28 -04:00
|
|
|
]
|
|
|
|
})
|
|
|
|
for (const actor of actors) {
|
|
|
|
if (actor.isOwned() === false) continue
|
|
|
|
|
|
|
|
console.log('Updating actor ' + actor.url)
|
|
|
|
|
|
|
|
const newUrl = actor.Account
|
2020-11-20 05:21:08 -05:00
|
|
|
? getLocalAccountActivityPubUrl(actor.preferredUsername)
|
|
|
|
: getLocalVideoChannelActivityPubUrl(actor.preferredUsername)
|
2018-06-21 12:29:28 -04:00
|
|
|
|
|
|
|
actor.url = newUrl
|
|
|
|
actor.inboxUrl = newUrl + '/inbox'
|
|
|
|
actor.outboxUrl = newUrl + '/outbox'
|
2019-04-11 08:26:41 -04:00
|
|
|
actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
|
2018-06-21 12:29:28 -04:00
|
|
|
actor.followersUrl = newUrl + '/followers'
|
|
|
|
actor.followingUrl = newUrl + '/following'
|
|
|
|
|
|
|
|
await actor.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Updating video shares.')
|
|
|
|
|
|
|
|
const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
|
|
|
|
include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
|
2017-09-07 09:27:35 -04:00
|
|
|
})
|
2018-06-21 12:29:28 -04:00
|
|
|
for (const videoShare of videoShares) {
|
|
|
|
if (videoShare.Video.isOwned() === false) continue
|
|
|
|
|
|
|
|
console.log('Updating video share ' + videoShare.url)
|
|
|
|
|
2020-11-20 05:21:08 -05:00
|
|
|
videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
|
2018-06-21 12:29:28 -04:00
|
|
|
await videoShare.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Updating video comments.')
|
|
|
|
const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: VideoModel.unscoped()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: AccountModel.unscoped(),
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: ActorModel.unscoped()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-06-12 15:06:32 -04:00
|
|
|
})
|
2018-06-21 12:29:28 -04:00
|
|
|
for (const comment of videoComments) {
|
|
|
|
if (comment.isOwned() === false) continue
|
|
|
|
|
|
|
|
console.log('Updating comment ' + comment.url)
|
|
|
|
|
2020-11-20 05:21:08 -05:00
|
|
|
comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)
|
2018-06-21 12:29:28 -04:00
|
|
|
await comment.save()
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Updating video and torrent files.')
|
|
|
|
|
2021-02-16 10:25:53 -05:00
|
|
|
const localVideos = await VideoModel.listLocal()
|
|
|
|
for (const localVideo of localVideos) {
|
|
|
|
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(localVideo.id)
|
|
|
|
|
2019-01-29 02:37:25 -05:00
|
|
|
console.log('Updating video ' + video.uuid)
|
2018-06-21 12:29:28 -04:00
|
|
|
|
2020-11-20 05:21:08 -05:00
|
|
|
video.url = getLocalVideoActivityPubUrl(video)
|
2018-06-21 12:29:28 -04:00
|
|
|
await video.save()
|
|
|
|
|
|
|
|
for (const file of video.VideoFiles) {
|
|
|
|
console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
|
2021-08-18 03:14:51 -04:00
|
|
|
await updateTorrentUrls(video, file)
|
2021-07-23 05:20:00 -04:00
|
|
|
|
|
|
|
await file.save()
|
2018-06-21 12:29:28 -04:00
|
|
|
}
|
2019-01-29 02:37:25 -05:00
|
|
|
|
2021-07-23 05:20:00 -04:00
|
|
|
const playlist = video.getHLSPlaylist()
|
|
|
|
for (const file of (playlist?.VideoFiles || [])) {
|
|
|
|
console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
|
|
|
|
|
2021-08-18 03:14:51 -04:00
|
|
|
await updateTorrentUrls(video, file)
|
2019-01-29 02:37:25 -05:00
|
|
|
|
2021-07-23 05:20:00 -04:00
|
|
|
await file.save()
|
2019-01-29 02:37:25 -05:00
|
|
|
}
|
2018-06-21 12:29:28 -04:00
|
|
|
}
|
|
|
|
}
|