Improve update host script
authorChocobozzz <me@florianbigard.com>
Tue, 20 Mar 2018 07:54:24 +0000 (08:54 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Mar 2018 08:19:05 +0000 (09:19 +0100)
scripts/update-host.ts

index 3fb5f1972dd85b6491fed4d9979533743dbeefe7..ed8b999a9f42c8d43a24e2a1b9b0e1425b3a0516 100755 (executable)
@@ -22,18 +22,13 @@ initDatabaseModels(true)
     console.log('Updating torrent files.')
     return VideoModel.list()
   })
-  .then(videos => {
-    const tasks: Promise<any>[] = []
-
-    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)