]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix federation of some videos
authorChocobozzz <me@florianbigard.com>
Wed, 19 Dec 2018 10:24:34 +0000 (11:24 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 19 Dec 2018 12:41:47 +0000 (13:41 +0100)
If we don't transcode additional resolutions, and user decided to wait
transcoding before publishing the video

server/initializers/constants.ts
server/initializers/migrations/0305-fix-unfederated-videos.ts [new file with mode: 0644]
server/lib/job-queue/handlers/video-file.ts

index 6e463a1d601435fbe2cfcef1b15d0f9cdd23bcc1..b326a6c7bb4b8349a71b087432439d2f5bcbc626 100644 (file)
@@ -16,7 +16,7 @@ let config: IConfig = require('config')
 
 // ---------------------------------------------------------------------------
 
-const LAST_MIGRATION_VERSION = 300
+const LAST_MIGRATION_VERSION = 305
 
 // ---------------------------------------------------------------------------
 
diff --git a/server/initializers/migrations/0305-fix-unfederated-videos.ts b/server/initializers/migrations/0305-fix-unfederated-videos.ts
new file mode 100644 (file)
index 0000000..be20660
--- /dev/null
@@ -0,0 +1,52 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+  transaction: Sequelize.Transaction,
+  queryInterface: Sequelize.QueryInterface,
+  sequelize: Sequelize.Sequelize,
+  db: any
+}): Promise<void> {
+  {
+    const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
+      `(` +
+        `SELECT ` +
+        `video.url || '/announces/' || "videoChannel"."actorId" as url, ` +
+        `"videoChannel"."actorId" AS "actorId", ` +
+        `"video"."id" AS "videoId", ` +
+        `NOW() AS "createdAt", ` +
+        `NOW() AS "updatedAt" ` +
+        `FROM video ` +
+        `INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` +
+        `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
+      `) ` +
+      `ON CONFLICT DO NOTHING`
+
+    await utils.sequelize.query(query)
+  }
+
+  {
+    const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` +
+      `(` +
+        `SELECT ` +
+        `video.url || '/announces/' || (SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) as url, ` +
+        `(SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) AS "actorId", ` +
+        `"video"."id" AS "videoId", ` +
+        `NOW() AS "createdAt", ` +
+        `NOW() AS "updatedAt" ` +
+        `FROM video ` +
+        `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` +
+      `) ` +
+      `ON CONFLICT DO NOTHING`
+
+    await utils.sequelize.query(query)
+  }
+}
+
+function down (options) {
+  throw new Error('Not implemented.')
+}
+
+export {
+  up,
+  down
+}
index ddbf6d1c23c9890ef6f4cdee635b989dbc8f1fcb..3dca2937f6bfe77459a61d2cd0f145e1d0e9591f 100644 (file)
@@ -91,15 +91,15 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
   })
 }
 
-async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) {
-  if (video === undefined) return undefined
+async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) {
+  if (videoArg === undefined) return undefined
 
   // Outside the transaction (IO on disk)
-  const { videoFileResolution } = await video.getOriginalFileResolution()
+  const { videoFileResolution } = await videoArg.getOriginalFileResolution()
 
   return sequelizeTypescript.transaction(async t => {
     // Maybe the video changed in database, refresh it
-    const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
+    let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
     // Video does not exist anymore
     if (!videoDatabase) return undefined
 
@@ -128,13 +128,13 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole
       logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
     } else {
       // No transcoding to do, it's now published
-      video.state = VideoState.PUBLISHED
-      video = await video.save({ transaction: t })
+      videoDatabase.state = VideoState.PUBLISHED
+      videoDatabase = await videoDatabase.save({ transaction: t })
 
-      logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid)
+      logger.info('No transcoding jobs created for video %s (no resolutions).', videoDatabase.uuid, { privacy: videoDatabase.privacy })
     }
 
-    return federateVideoIfNeeded(video, isNewVideo, t)
+    return federateVideoIfNeeded(videoDatabase, isNewVideo, t)
   })
 }