X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fvideo.ts;h=d03ab04529bb749b91fbeee9da692fb90979961b;hb=40c52969f731b9102d4b33c4f5a80bfbbc651894;hp=6df41e6cd910ea6a731f5017c0a9bf80766cbac6;hpb=1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/video.ts b/server/lib/video.ts index 6df41e6cd..d03ab0452 100644 --- a/server/lib/video.ts +++ b/server/lib/video.ts @@ -1,9 +1,12 @@ import { Transaction } from 'sequelize/types' +import { sequelizeTypescript } from '@server/initializers/database' import { TagModel } from '@server/models/video/tag' import { VideoModel } from '@server/models/video/video' import { FilteredModelAttributes } from '@server/types' -import { MTag, MThumbnail, MVideoTag, MVideoThumbnail } from '@server/types/models' +import { MTag, MThumbnail, MVideoTag, MVideoThumbnail, MVideoUUID } from '@server/types/models' import { ThumbnailType, VideoCreate, VideoPrivacy } from '@shared/models' +import { federateVideoIfNeeded } from './activitypub/videos' +import { Notifier } from './notifier' import { createVideoMiniatureFromExisting } from './thumbnail' function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes { @@ -78,10 +81,34 @@ async function setVideoTags (options: { } } +async function publishAndFederateIfNeeded (video: MVideoUUID, wasLive = false) { + const result = await sequelizeTypescript.transaction(async t => { + // Maybe the video changed in database, refresh it + const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) + // Video does not exist anymore + if (!videoDatabase) return undefined + + // We transcoded the video file in another format, now we can publish it + const videoPublished = await videoDatabase.publishIfNeededAndSave(t) + + // If the video was not published, we consider it is a new one for other instances + // Live videos are always federated, so it's not a new video + await federateVideoIfNeeded(videoDatabase, !wasLive && videoPublished, t) + + return { videoDatabase, videoPublished } + }) + + if (result?.videoPublished) { + Notifier.Instance.notifyOnNewVideoIfNeeded(result.videoDatabase) + Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(result.videoDatabase) + } +} + // --------------------------------------------------------------------------- export { buildLocalVideoFromReq, + publishAndFederateIfNeeded, buildVideoThumbnailsFromReq, setVideoTags }