]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/update-host.js
Change licence to AGPL
[github/Chocobozzz/PeerTube.git] / scripts / update-host.js
index 8a17f24023f7e644f7e17fb86ffe93914a0f0738..8ae0f0d0e400e045f236ea6cb8d009913e5a16b1 100755 (executable)
@@ -2,40 +2,31 @@
 
 'use strict'
 
-// TODO: document this script
-
 const fs = require('fs')
-const mongoose = require('mongoose')
 const parseTorrent = require('parse-torrent')
 
 const constants = require('../server/initializers/constants')
-const database = require('../server/initializers/database')
-
-database.connect()
+const db = require('../server/initializers/database')
 
 const friends = require('../server/lib/friends')
-const Video = mongoose.model('Video')
-
-friends.hasFriends(function (err, hasFriends) {
-  if (err) throw err
 
-  if (hasFriends === true) {
-    console.log('Cannot update host because you have friends!')
-    process.exit(-1)
-  }
-
-  console.log('Updating videos host in database.')
-  Video.update({ }, { podHost: constants.CONFIG.WEBSERVER.HOST }, { multi: true }, function (err) {
+db.init(true, function () {
+  friends.hasFriends(function (err, hasFriends) {
     if (err) throw err
 
+    if (hasFriends === true) {
+      console.log('Cannot update host because you have friends!')
+      process.exit(-1)
+    }
+
     console.log('Updating torrent files.')
-    Video.find().lean().exec(function (err, videos) {
+    db.Video.list(function (err, videos) {
       if (err) throw err
 
       videos.forEach(function (video) {
-        const torrentName = video._id + '.torrent'
+        const torrentName = video.id + '.torrent'
         const torrentPath = constants.CONFIG.STORAGE.TORRENTS_DIR + torrentName
-        const filename = video._id + video.extname
+        const filename = video.id + video.extname
 
         const parsed = parseTorrent(fs.readFileSync(torrentPath))
         parsed.announce = [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOST + '/tracker/socket' ]