aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r--server/lib/video.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/server/lib/video.ts b/server/lib/video.ts
index 6df41e6cd..81b7c4159 100644
--- a/server/lib/video.ts
+++ b/server/lib/video.ts
@@ -1,9 +1,12 @@
1import { Transaction } from 'sequelize/types' 1import { Transaction } from 'sequelize/types'
2import { sequelizeTypescript } from '@server/initializers/database'
2import { TagModel } from '@server/models/video/tag' 3import { TagModel } from '@server/models/video/tag'
3import { VideoModel } from '@server/models/video/video' 4import { VideoModel } from '@server/models/video/video'
4import { FilteredModelAttributes } from '@server/types' 5import { FilteredModelAttributes } from '@server/types'
5import { MTag, MThumbnail, MVideoTag, MVideoThumbnail } from '@server/types/models' 6import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models'
6import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' 7import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models'
8import { federateVideoIfNeeded } from './activitypub/videos'
9import { Notifier } from './notifier'
7import { createVideoMiniatureFromExisting } from './thumbnail' 10import { createVideoMiniatureFromExisting } from './thumbnail'
8 11
9function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { 12function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
@@ -78,10 +81,33 @@ async function setVideoTags (options: {
78 } 81 }
79} 82}
80 83
84async function publishAndFederateIfNeeded (video: MVideoUUID) {
85 const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
86 // Maybe the video changed in database, refresh it
87 const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
88 // Video does not exist anymore
89 if (!videoDatabase) return undefined
90
91 // We transcoded the video file in another format, now we can publish it
92 const videoPublished = await videoDatabase.publishIfNeededAndSave(t)
93
94 // If the video was not published, we consider it is a new one for other instances
95 await federateVideoIfNeeded(videoDatabase, videoPublished, t)
96
97 return { videoDatabase, videoPublished }
98 })
99
100 if (videoPublished) {
101 Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
102 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)
103 }
104}
105
81// --------------------------------------------------------------------------- 106// ---------------------------------------------------------------------------
82 107
83export { 108export {
84 buildLocalVideoFromReq, 109 buildLocalVideoFromReq,
110 publishAndFederateIfNeeded,
85 buildVideoThumbnailsFromReq, 111 buildVideoThumbnailsFromReq,
86 setVideoTags 112 setVideoTags
87} 113}