X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Fupdate-host.ts;h=ed8b999a9f42c8d43a24e2a1b9b0e1425b3a0516;hb=0c948c1659c0a6010f2bf58c402b1c9af192aa5e;hp=759443623ef74950c8cdfcb65cc9eb5b5422b6f8;hpb=98ec8b8e73a918d5680e6f13aaef56ca8756c2a8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 759443623..ed8b999a9 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -1,12 +1,14 @@ -import { database as db } from '../server/initializers/database' -import { getServerAccount } from '../server/helpers/utils' +import { getServerActor } from '../server/helpers/utils' +import { initDatabaseModels } from '../server/initializers' +import { ActorFollowModel } from '../server/models/activitypub/actor-follow' +import { VideoModel } from '../server/models/video/video' -db.init(true) +initDatabaseModels(true) .then(() => { - return getServerAccount() + return getServerActor() }) .then(serverAccount => { - return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined) + return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined) }) .then(res => { return res.total > 0 @@ -18,20 +20,15 @@ db.init(true) } console.log('Updating torrent files.') - return db.Video.list() + return VideoModel.list() }) - .then(videos => { - const tasks: Promise[] = [] - - videos.forEach(video => { - console.log('Updating video ' + video.uuid) - - video.VideoFiles.forEach(file => { - tasks.push(video.createTorrentAndSetInfoHash(file)) - }) - }) - - return Promise.all(tasks) + .then(async videos => { + for (const video of videos) { + for (const file of video.VideoFiles) { + await video.createTorrentAndSetInfoHash(file) + console.log('Updated video ' + video.uuid) + } + } }) .then(() => { process.exit(0)