diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-19 11:24:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-19 13:41:47 +0100 |
commit | 56b13bd193b076d32925f0ad14b755b250b803a8 (patch) | |
tree | 02e07db886a1d416d4706e9eda03ddc084dd79ab /server | |
parent | 1a12adcd1e938a405e5caeaaaf5711f197cc6cf4 (diff) | |
download | PeerTube-56b13bd193b076d32925f0ad14b755b250b803a8.tar.gz PeerTube-56b13bd193b076d32925f0ad14b755b250b803a8.tar.zst PeerTube-56b13bd193b076d32925f0ad14b755b250b803a8.zip |
Fix federation of some videos
If we don't transcode additional resolutions, and user decided to wait
transcoding before publishing the video
Diffstat (limited to 'server')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0305-fix-unfederated-videos.ts | 52 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-file.ts | 16 |
3 files changed, 61 insertions, 9 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6e463a1d6..b326a6c7b 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -16,7 +16,7 @@ let config: IConfig = require('config') | |||
16 | 16 | ||
17 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
18 | 18 | ||
19 | const LAST_MIGRATION_VERSION = 300 | 19 | const LAST_MIGRATION_VERSION = 305 |
20 | 20 | ||
21 | // --------------------------------------------------------------------------- | 21 | // --------------------------------------------------------------------------- |
22 | 22 | ||
diff --git a/server/initializers/migrations/0305-fix-unfederated-videos.ts b/server/initializers/migrations/0305-fix-unfederated-videos.ts new file mode 100644 index 000000000..be206601f --- /dev/null +++ b/server/initializers/migrations/0305-fix-unfederated-videos.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize, | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` + | ||
11 | `(` + | ||
12 | `SELECT ` + | ||
13 | `video.url || '/announces/' || "videoChannel"."actorId" as url, ` + | ||
14 | `"videoChannel"."actorId" AS "actorId", ` + | ||
15 | `"video"."id" AS "videoId", ` + | ||
16 | `NOW() AS "createdAt", ` + | ||
17 | `NOW() AS "updatedAt" ` + | ||
18 | `FROM video ` + | ||
19 | `INNER JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id" ` + | ||
20 | `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` + | ||
21 | `) ` + | ||
22 | `ON CONFLICT DO NOTHING` | ||
23 | |||
24 | await utils.sequelize.query(query) | ||
25 | } | ||
26 | |||
27 | { | ||
28 | const query = `INSERT INTO "videoShare" (url, "actorId", "videoId", "createdAt", "updatedAt") ` + | ||
29 | `(` + | ||
30 | `SELECT ` + | ||
31 | `video.url || '/announces/' || (SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) as url, ` + | ||
32 | `(SELECT id FROM actor WHERE "preferredUsername" = 'peertube' ORDER BY id ASC LIMIT 1) AS "actorId", ` + | ||
33 | `"video"."id" AS "videoId", ` + | ||
34 | `NOW() AS "createdAt", ` + | ||
35 | `NOW() AS "updatedAt" ` + | ||
36 | `FROM video ` + | ||
37 | `WHERE "video"."remote" = false AND "video"."privacy" != 3 AND "video"."state" = 1` + | ||
38 | `) ` + | ||
39 | `ON CONFLICT DO NOTHING` | ||
40 | |||
41 | await utils.sequelize.query(query) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | function down (options) { | ||
46 | throw new Error('Not implemented.') | ||
47 | } | ||
48 | |||
49 | export { | ||
50 | up, | ||
51 | down | ||
52 | } | ||
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index ddbf6d1c2..3dca2937f 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts | |||
@@ -91,15 +91,15 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { | |||
91 | }) | 91 | }) |
92 | } | 92 | } |
93 | 93 | ||
94 | async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) { | 94 | async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { |
95 | if (video === undefined) return undefined | 95 | if (videoArg === undefined) return undefined |
96 | 96 | ||
97 | // Outside the transaction (IO on disk) | 97 | // Outside the transaction (IO on disk) |
98 | const { videoFileResolution } = await video.getOriginalFileResolution() | 98 | const { videoFileResolution } = await videoArg.getOriginalFileResolution() |
99 | 99 | ||
100 | return sequelizeTypescript.transaction(async t => { | 100 | return sequelizeTypescript.transaction(async t => { |
101 | // Maybe the video changed in database, refresh it | 101 | // Maybe the video changed in database, refresh it |
102 | const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) | 102 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) |
103 | // Video does not exist anymore | 103 | // Video does not exist anymore |
104 | if (!videoDatabase) return undefined | 104 | if (!videoDatabase) return undefined |
105 | 105 | ||
@@ -128,13 +128,13 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole | |||
128 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) | 128 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) |
129 | } else { | 129 | } else { |
130 | // No transcoding to do, it's now published | 130 | // No transcoding to do, it's now published |
131 | video.state = VideoState.PUBLISHED | 131 | videoDatabase.state = VideoState.PUBLISHED |
132 | video = await video.save({ transaction: t }) | 132 | videoDatabase = await videoDatabase.save({ transaction: t }) |
133 | 133 | ||
134 | logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid) | 134 | logger.info('No transcoding jobs created for video %s (no resolutions).', videoDatabase.uuid, { privacy: videoDatabase.privacy }) |
135 | } | 135 | } |
136 | 136 | ||
137 | return federateVideoIfNeeded(video, isNewVideo, t) | 137 | return federateVideoIfNeeded(videoDatabase, isNewVideo, t) |
138 | }) | 138 | }) |
139 | } | 139 | } |
140 | 140 | ||