diff options
author | Chocobozzz <me@florianbigard.com> | 2020-09-17 13:59:02 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-09 15:33:04 +0100 |
commit | de6310b2fcbb8a6b79c546b23dfa1920724faaa7 (patch) | |
tree | 57e73811ef2cf0c903782704284c9cbfc1598adb /server | |
parent | 1ef65f4c034cc53ab5d55417e52d60e1f7fc1ddb (diff) | |
download | PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.gz PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.tar.zst PeerTube-de6310b2fcbb8a6b79c546b23dfa1920724faaa7.zip |
Handle live federation
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/index.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 1 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 22 | ||||
-rw-r--r-- | server/lib/moderation.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-format-utils.ts | 5 | ||||
-rw-r--r-- | server/models/video/video.ts | 4 |
8 files changed, 23 insertions, 22 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 1539afc35..6357062bc 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -55,7 +55,6 @@ import { | |||
55 | videosUpdateValidator | 55 | videosUpdateValidator |
56 | } from '../../../middlewares' | 56 | } from '../../../middlewares' |
57 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 57 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
58 | import { TagModel } from '../../../models/video/tag' | ||
59 | import { VideoModel } from '../../../models/video/video' | 58 | import { VideoModel } from '../../../models/video/video' |
60 | import { VideoFileModel } from '../../../models/video/video-file' | 59 | import { VideoFileModel } from '../../../models/video/video-file' |
61 | import { abuseVideoRouter } from './abuse' | 60 | import { abuseVideoRouter } from './abuse' |
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 876cc7f50..7ff551ecd 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -62,6 +62,7 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
62 | if (!isBooleanValid(video.waitTranscoding)) video.waitTranscoding = false | 62 | if (!isBooleanValid(video.waitTranscoding)) video.waitTranscoding = false |
63 | if (!isBooleanValid(video.downloadEnabled)) video.downloadEnabled = true | 63 | if (!isBooleanValid(video.downloadEnabled)) video.downloadEnabled = true |
64 | if (!isBooleanValid(video.commentsEnabled)) video.commentsEnabled = false | 64 | if (!isBooleanValid(video.commentsEnabled)) video.commentsEnabled = false |
65 | if (!isBooleanValid(video.isLiveBroadcast)) video.isLiveBroadcast = false | ||
65 | 66 | ||
66 | return isActivityPubUrlValid(video.id) && | 67 | return isActivityPubUrlValid(video.id) && |
67 | isVideoNameValid(video.name) && | 68 | isVideoNameValid(video.name) && |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 74f1032e2..f84992489 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { isRedundancyAccepted } from '@server/lib/redundancy' | 1 | import { isRedundancyAccepted } from '@server/lib/redundancy' |
2 | import { ActivityCreate, CacheFileObject, VideoTorrentObject } from '../../../../shared' | 2 | import { ActivityCreate, CacheFileObject, VideoObject } from '../../../../shared' |
3 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' | 3 | import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 5 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -52,7 +52,7 @@ export { | |||
52 | // --------------------------------------------------------------------------- | 52 | // --------------------------------------------------------------------------- |
53 | 53 | ||
54 | async function processCreateVideo (activity: ActivityCreate, notify: boolean) { | 54 | async function processCreateVideo (activity: ActivityCreate, notify: boolean) { |
55 | const videoToCreateData = activity.object as VideoTorrentObject | 55 | const videoToCreateData = activity.object as VideoObject |
56 | 56 | ||
57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } | 57 | const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } |
58 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData, syncParam }) | 58 | const { video, created } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoToCreateData, syncParam }) |
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 1bdf23d6f..6d2fff3fe 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityUpdate, CacheFileObject, VideoTorrentObject } from '../../../../shared/models/activitypub' | 1 | import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub' |
2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' | 2 | import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' |
3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
@@ -55,7 +55,7 @@ export { | |||
55 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
56 | 56 | ||
57 | async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) { | 57 | async function processUpdateVideo (actor: MActorSignature, activity: ActivityUpdate) { |
58 | const videoObject = activity.object as VideoTorrentObject | 58 | const videoObject = activity.object as VideoObject |
59 | 59 | ||
60 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { | 60 | if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { |
61 | logger.debug('Video sent by update is not valid.', { videoObject }) | 61 | logger.debug('Video sent by update is not valid.', { videoObject }) |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 096884776..049e06cff 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | ActivityVideoUrlObject, | 15 | ActivityVideoUrlObject, |
16 | VideoState | 16 | VideoState |
17 | } from '../../../shared/index' | 17 | } from '../../../shared/index' |
18 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 18 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
19 | import { VideoPrivacy } from '../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../shared/models/videos' |
20 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 20 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
21 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 21 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
@@ -38,7 +38,6 @@ import { | |||
38 | } from '../../initializers/constants' | 38 | } from '../../initializers/constants' |
39 | import { sequelizeTypescript } from '../../initializers/database' | 39 | import { sequelizeTypescript } from '../../initializers/database' |
40 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 40 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
41 | import { TagModel } from '../../models/video/tag' | ||
42 | import { VideoModel } from '../../models/video/video' | 41 | import { VideoModel } from '../../models/video/video' |
43 | import { VideoCaptionModel } from '../../models/video/video-caption' | 42 | import { VideoCaptionModel } from '../../models/video/video-caption' |
44 | import { VideoCommentModel } from '../../models/video/video-comment' | 43 | import { VideoCommentModel } from '../../models/video/video-comment' |
@@ -104,7 +103,7 @@ async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVid | |||
104 | } | 103 | } |
105 | } | 104 | } |
106 | 105 | ||
107 | async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoTorrentObject }> { | 106 | async function fetchRemoteVideo (videoUrl: string): Promise<{ response: request.RequestResponse, videoObject: VideoObject }> { |
108 | const options = { | 107 | const options = { |
109 | uri: videoUrl, | 108 | uri: videoUrl, |
110 | method: 'GET', | 109 | method: 'GET', |
@@ -136,7 +135,7 @@ async function fetchRemoteVideoDescription (video: MVideoAccountLight) { | |||
136 | return body.description ? body.description : '' | 135 | return body.description ? body.description : '' |
137 | } | 136 | } |
138 | 137 | ||
139 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoTorrentObject) { | 138 | function getOrCreateVideoChannelFromVideoObject (videoObject: VideoObject) { |
140 | const channel = videoObject.attributedTo.find(a => a.type === 'Group') | 139 | const channel = videoObject.attributedTo.find(a => a.type === 'Group') |
141 | if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url) | 140 | if (!channel) throw new Error('Cannot find associated video channel to video ' + videoObject.url) |
142 | 141 | ||
@@ -155,7 +154,7 @@ type SyncParam = { | |||
155 | thumbnail: boolean | 154 | thumbnail: boolean |
156 | refreshVideo?: boolean | 155 | refreshVideo?: boolean |
157 | } | 156 | } |
158 | async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTorrentObject, syncParam: SyncParam) { | 157 | async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoObject, syncParam: SyncParam) { |
159 | logger.info('Adding likes/dislikes/shares/comments of video %s.', video.uuid) | 158 | logger.info('Adding likes/dislikes/shares/comments of video %s.', video.uuid) |
160 | 159 | ||
161 | const jobPayloads: ActivitypubHttpFetcherPayload[] = [] | 160 | const jobPayloads: ActivitypubHttpFetcherPayload[] = [] |
@@ -294,7 +293,7 @@ async function getOrCreateVideoAndAccountAndChannel ( | |||
294 | 293 | ||
295 | async function updateVideoFromAP (options: { | 294 | async function updateVideoFromAP (options: { |
296 | video: MVideoAccountLightBlacklistAllFiles | 295 | video: MVideoAccountLightBlacklistAllFiles |
297 | videoObject: VideoTorrentObject | 296 | videoObject: VideoObject |
298 | account: MAccountIdActor | 297 | account: MAccountIdActor |
299 | channel: MChannelDefault | 298 | channel: MChannelDefault |
300 | overrideTo?: string[] | 299 | overrideTo?: string[] |
@@ -538,7 +537,7 @@ function isAPHashTagObject (url: any): url is ActivityHashTagObject { | |||
538 | return url && url.type === 'Hashtag' | 537 | return url && url.type === 'Hashtag' |
539 | } | 538 | } |
540 | 539 | ||
541 | async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAccountLight, waitThumbnail = false) { | 540 | async function createVideo (videoObject: VideoObject, channel: MChannelAccountLight, waitThumbnail = false) { |
542 | logger.debug('Adding remote video %s.', videoObject.id) | 541 | logger.debug('Adding remote video %s.', videoObject.id) |
543 | 542 | ||
544 | const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, videoObject.to) | 543 | const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, videoObject.to) |
@@ -632,7 +631,7 @@ async function createVideo (videoObject: VideoTorrentObject, channel: MChannelAc | |||
632 | return { autoBlacklisted, videoCreated } | 631 | return { autoBlacklisted, videoCreated } |
633 | } | 632 | } |
634 | 633 | ||
635 | function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) { | 634 | function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoObject, to: string[] = []) { |
636 | const privacy = to.includes(ACTIVITY_PUB.PUBLIC) | 635 | const privacy = to.includes(ACTIVITY_PUB.PUBLIC) |
637 | ? VideoPrivacy.PUBLIC | 636 | ? VideoPrivacy.PUBLIC |
638 | : VideoPrivacy.UNLISTED | 637 | : VideoPrivacy.UNLISTED |
@@ -664,6 +663,7 @@ function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObjec | |||
664 | commentsEnabled: videoObject.commentsEnabled, | 663 | commentsEnabled: videoObject.commentsEnabled, |
665 | downloadEnabled: videoObject.downloadEnabled, | 664 | downloadEnabled: videoObject.downloadEnabled, |
666 | waitTranscoding: videoObject.waitTranscoding, | 665 | waitTranscoding: videoObject.waitTranscoding, |
666 | isLive: videoObject.isLiveBroadcast, | ||
667 | state: videoObject.state, | 667 | state: videoObject.state, |
668 | channelId: videoChannel.id, | 668 | channelId: videoChannel.id, |
669 | duration: parseInt(duration, 10), | 669 | duration: parseInt(duration, 10), |
@@ -732,7 +732,7 @@ function videoFileActivityUrlToDBAttributes ( | |||
732 | return attributes | 732 | return attributes |
733 | } | 733 | } |
734 | 734 | ||
735 | function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoTorrentObject, videoFiles: MVideoFile[]) { | 735 | function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObject: VideoObject, videoFiles: MVideoFile[]) { |
736 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] | 736 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] |
737 | if (playlistUrls.length === 0) return [] | 737 | if (playlistUrls.length === 0) return [] |
738 | 738 | ||
@@ -766,7 +766,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: MVideoId, videoObjec | |||
766 | return attributes | 766 | return attributes |
767 | } | 767 | } |
768 | 768 | ||
769 | function getThumbnailFromIcons (videoObject: VideoTorrentObject) { | 769 | function getThumbnailFromIcons (videoObject: VideoObject) { |
770 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) | 770 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) |
771 | // Fallback if there are not valid icons | 771 | // Fallback if there are not valid icons |
772 | if (validIcons.length === 0) validIcons = videoObject.icon | 772 | if (validIcons.length === 0) validIcons = videoObject.icon |
@@ -774,7 +774,7 @@ function getThumbnailFromIcons (videoObject: VideoTorrentObject) { | |||
774 | return minBy(validIcons, 'width') | 774 | return minBy(validIcons, 'width') |
775 | } | 775 | } |
776 | 776 | ||
777 | function getPreviewFromIcons (videoObject: VideoTorrentObject) { | 777 | function getPreviewFromIcons (videoObject: VideoObject) { |
778 | const validIcons = videoObject.icon.filter(i => i.width > PREVIEWS_SIZE.minWidth) | 778 | const validIcons = videoObject.icon.filter(i => i.width > PREVIEWS_SIZE.minWidth) |
779 | 779 | ||
780 | // FIXME: don't put a fallback here for compatibility with PeerTube <2.2 | 780 | // FIXME: don't put a fallback here for compatibility with PeerTube <2.2 |
diff --git a/server/lib/moderation.ts b/server/lib/moderation.ts index b140d5aa9..0ef26d53d 100644 --- a/server/lib/moderation.ts +++ b/server/lib/moderation.ts | |||
@@ -18,7 +18,7 @@ import { | |||
18 | MVideoAccountLightBlacklistAllFiles | 18 | MVideoAccountLightBlacklistAllFiles |
19 | } from '@server/types/models' | 19 | } from '@server/types/models' |
20 | import { ActivityCreate } from '../../shared/models/activitypub' | 20 | import { ActivityCreate } from '../../shared/models/activitypub' |
21 | import { VideoTorrentObject } from '../../shared/models/activitypub/objects' | 21 | import { VideoObject } from '../../shared/models/activitypub/objects' |
22 | import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object' | 22 | import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object' |
23 | import { VideoCreate, VideoImportCreate } from '../../shared/models/videos' | 23 | import { VideoCreate, VideoImportCreate } from '../../shared/models/videos' |
24 | import { VideoCommentCreate } from '../../shared/models/videos/video-comment.model' | 24 | import { VideoCommentCreate } from '../../shared/models/videos/video-comment.model' |
@@ -62,7 +62,7 @@ function isLocalVideoCommentReplyAccepted (_object: { | |||
62 | 62 | ||
63 | function isRemoteVideoAccepted (_object: { | 63 | function isRemoteVideoAccepted (_object: { |
64 | activity: ActivityCreate | 64 | activity: ActivityCreate |
65 | videoAP: VideoTorrentObject | 65 | videoAP: VideoObject |
66 | byActor: ActorModel | 66 | byActor: ActorModel |
67 | }): AcceptResult { | 67 | }): AcceptResult { |
68 | return { accepted: true } | 68 | return { accepted: true } |
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 0dbd92a43..92bde7773 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Video, VideoDetails } from '../../../shared/models/videos' | 1 | import { Video, VideoDetails } from '../../../shared/models/videos' |
2 | import { VideoModel } from './video' | 2 | import { VideoModel } from './video' |
3 | import { ActivityTagObject, ActivityUrlObject, VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 3 | import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' |
4 | import { MIMETYPES, WEBSERVER } from '../../initializers/constants' | 4 | import { MIMETYPES, WEBSERVER } from '../../initializers/constants' |
5 | import { VideoCaptionModel } from './video-caption' | 5 | import { VideoCaptionModel } from './video-caption' |
6 | import { | 6 | import { |
@@ -262,7 +262,7 @@ function addVideoFilesInAPAcc ( | |||
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject { | 265 | function videoModelToActivityPubObject (video: MVideoAP): VideoObject { |
266 | const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() | 266 | const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() |
267 | if (!video.Tags) video.Tags = [] | 267 | if (!video.Tags) video.Tags = [] |
268 | 268 | ||
@@ -351,6 +351,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject { | |||
351 | views: video.views, | 351 | views: video.views, |
352 | sensitive: video.nsfw, | 352 | sensitive: video.nsfw, |
353 | waitTranscoding: video.waitTranscoding, | 353 | waitTranscoding: video.waitTranscoding, |
354 | isLiveBroadcast: video.isLive, | ||
354 | state: video.state, | 355 | state: video.state, |
355 | commentsEnabled: video.commentsEnabled, | 356 | commentsEnabled: video.commentsEnabled, |
356 | downloadEnabled: video.downloadEnabled, | 357 | downloadEnabled: video.downloadEnabled, |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1037730e3..a3e3b6cfe 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -31,7 +31,7 @@ import { getServerActor } from '@server/models/application/application' | |||
31 | import { ModelCache } from '@server/models/model-cache' | 31 | import { ModelCache } from '@server/models/model-cache' |
32 | import { VideoFile } from '@shared/models/videos/video-file.model' | 32 | import { VideoFile } from '@shared/models/videos/video-file.model' |
33 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 33 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' |
34 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 34 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
35 | import { Video, VideoDetails } from '../../../shared/models/videos' | 35 | import { Video, VideoDetails } from '../../../shared/models/videos' |
36 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 36 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
37 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 37 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
@@ -1763,7 +1763,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1763 | return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, files) | 1763 | return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, files) |
1764 | } | 1764 | } |
1765 | 1765 | ||
1766 | toActivityPubObject (this: MVideoAP): VideoTorrentObject { | 1766 | toActivityPubObject (this: MVideoAP): VideoObject { |
1767 | return videoModelToActivityPubObject(this) | 1767 | return videoModelToActivityPubObject(this) |
1768 | } | 1768 | } |
1769 | 1769 | ||