diff options
author | Chocobozzz <me@florianbigard.com> | 2020-10-28 10:49:20 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | d846d99c6c81028bb7bd3cb20abd433cbf396a22 (patch) | |
tree | 1090abd56e9b2df82dd92783f499ac9f10fbd501 /server/lib/video.ts | |
parent | 31c82cd914e13dbf53280d0aad0740d70c414441 (diff) | |
download | PeerTube-d846d99c6c81028bb7bd3cb20abd433cbf396a22.tar.gz PeerTube-d846d99c6c81028bb7bd3cb20abd433cbf396a22.tar.zst PeerTube-d846d99c6c81028bb7bd3cb20abd433cbf396a22.zip |
Add modal to display live information
Diffstat (limited to 'server/lib/video.ts')
-rw-r--r-- | server/lib/video.ts | 28 |
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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { sequelizeTypescript } from '@server/initializers/database' | ||
2 | import { TagModel } from '@server/models/video/tag' | 3 | import { TagModel } from '@server/models/video/tag' |
3 | import { VideoModel } from '@server/models/video/video' | 4 | import { VideoModel } from '@server/models/video/video' |
4 | import { FilteredModelAttributes } from '@server/types' | 5 | import { FilteredModelAttributes } from '@server/types' |
5 | import { MTag, MThumbnail, MVideoTag, MVideoThumbnail } from '@server/types/models' | 6 | import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' |
6 | import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' | 7 | import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' |
8 | import { federateVideoIfNeeded } from './activitypub/videos' | ||
9 | import { Notifier } from './notifier' | ||
7 | import { createVideoMiniatureFromExisting } from './thumbnail' | 10 | import { createVideoMiniatureFromExisting } from './thumbnail' |
8 | 11 | ||
9 | function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { | 12 | function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { |
@@ -78,10 +81,33 @@ async function setVideoTags (options: { | |||
78 | } | 81 | } |
79 | } | 82 | } |
80 | 83 | ||
84 | async 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 | ||
83 | export { | 108 | export { |
84 | buildLocalVideoFromReq, | 109 | buildLocalVideoFromReq, |
110 | publishAndFederateIfNeeded, | ||
85 | buildVideoThumbnailsFromReq, | 111 | buildVideoThumbnailsFromReq, |
86 | setVideoTags | 112 | setVideoTags |
87 | } | 113 | } |