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