aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/audience.ts12
-rw-r--r--server/lib/activitypub/process/process-view.ts3
-rw-r--r--server/lib/activitypub/send/utils.ts4
-rw-r--r--server/lib/activitypub/videos.ts46
4 files changed, 46 insertions, 19 deletions
diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts
index f2ab54cf7..39caeef7b 100644
--- a/server/lib/activitypub/audience.ts
+++ b/server/lib/activitypub/audience.ts
@@ -4,7 +4,15 @@ import { ACTIVITY_PUB } from '../../initializers/constants'
4import { ActorModel } from '../../models/activitypub/actor' 4import { ActorModel } from '../../models/activitypub/actor'
5import { VideoModel } from '../../models/video/video' 5import { VideoModel } from '../../models/video/video'
6import { VideoShareModel } from '../../models/video/video-share' 6import { VideoShareModel } from '../../models/video/video-share'
7import { MActorFollowersUrl, MActorLight, MCommentOwner, MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../../typings/models' 7import {
8 MActorFollowersUrl,
9 MActorLight,
10 MCommentOwner,
11 MCommentOwnerVideo,
12 MVideo,
13 MVideoAccountLight,
14 MVideoId
15} from '../../typings/models'
8 16
9function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience { 17function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
10 return { 18 return {
@@ -48,7 +56,7 @@ function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[
48 } 56 }
49} 57}
50 58
51async function getActorsInvolvedInVideo (video: MVideo, t: Transaction) { 59async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
52 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t) 60 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t)
53 61
54 const videoAll = video as VideoModel 62 const videoAll = video as VideoModel
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts
index df29ee968..b3b6c933d 100644
--- a/server/lib/activitypub/process/process-view.ts
+++ b/server/lib/activitypub/process/process-view.ts
@@ -23,7 +23,8 @@ async function processCreateView (activity: ActivityView | ActivityCreate, byAct
23 23
24 const options = { 24 const options = {
25 videoObject, 25 videoObject,
26 fetchType: 'only-video' as 'only-video' 26 fetchType: 'only-immutable-attributes' as 'only-immutable-attributes',
27 allowRefresh: false as false
27 } 28 }
28 const { video } = await getOrCreateVideoAndAccountAndChannel(options) 29 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
29 30
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts
index 0d67bb3d6..9436daf17 100644
--- a/server/lib/activitypub/send/utils.ts
+++ b/server/lib/activitypub/send/utils.ts
@@ -7,7 +7,7 @@ import { JobQueue } from '../../job-queue'
7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' 7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
8import { getServerActor } from '../../../helpers/utils' 8import { getServerActor } from '../../../helpers/utils'
9import { afterCommitIfTransaction } from '../../../helpers/database-utils' 9import { afterCommitIfTransaction } from '../../../helpers/database-utils'
10import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight } from '../../../typings/models' 10import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../../typings/models'
11import { ContextType } from '@server/helpers/activitypub' 11import { ContextType } from '@server/helpers/activitypub'
12 12
13async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { 13async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
@@ -43,7 +43,7 @@ async function forwardVideoRelatedActivity (
43 activity: Activity, 43 activity: Activity,
44 t: Transaction, 44 t: Transaction,
45 followersException: MActorWithInboxes[] = [], 45 followersException: MActorWithInboxes[] = [],
46 video: MVideo 46 video: MVideoId
47) { 47) {
48 // Mastodon does not add our announces in audience, so we forward to them manually 48 // Mastodon does not add our announces in audience, so we forward to them manually
49 const additionalActors = await getActorsInvolvedInVideo(video, t) 49 const additionalActors = await getActorsInvolvedInVideo(video, t)
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 9e43caa20..7d8296e45 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -68,7 +68,7 @@ import {
68 MVideoAPWithoutCaption, 68 MVideoAPWithoutCaption,
69 MVideoFile, 69 MVideoFile,
70 MVideoFullLight, 70 MVideoFullLight,
71 MVideoId, 71 MVideoId, MVideoImmutable,
72 MVideoThumbnail 72 MVideoThumbnail
73} from '../../typings/models' 73} from '../../typings/models'
74import { MThumbnail } from '../../typings/models/video/thumbnail' 74import { MThumbnail } from '../../typings/models/video/thumbnail'
@@ -200,24 +200,41 @@ async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTo
200 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })) 200 await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload }))
201} 201}
202 202
203function getOrCreateVideoAndAccountAndChannel (options: { 203type GetVideoResult <T> = Promise<{
204 video: T
205 created: boolean
206 autoBlacklisted?: boolean
207}>
208
209type GetVideoParamAll = {
204 videoObject: { id: string } | string 210 videoObject: { id: string } | string
205 syncParam?: SyncParam 211 syncParam?: SyncParam
206 fetchType?: 'all' 212 fetchType?: 'all'
207 allowRefresh?: boolean 213 allowRefresh?: boolean
208}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }> 214}
209function getOrCreateVideoAndAccountAndChannel (options: { 215
216type GetVideoParamImmutable = {
210 videoObject: { id: string } | string 217 videoObject: { id: string } | string
211 syncParam?: SyncParam 218 syncParam?: SyncParam
212 fetchType?: VideoFetchByUrlType 219 fetchType: 'only-immutable-attributes'
213 allowRefresh?: boolean 220 allowRefresh: false
214}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> 221}
215async function getOrCreateVideoAndAccountAndChannel (options: { 222
223type GetVideoParamOther = {
216 videoObject: { id: string } | string 224 videoObject: { id: string } | string
217 syncParam?: SyncParam 225 syncParam?: SyncParam
218 fetchType?: VideoFetchByUrlType 226 fetchType?: 'all' | 'only-video'
219 allowRefresh?: boolean // true by default 227 allowRefresh?: boolean
220}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> { 228}
229
230function getOrCreateVideoAndAccountAndChannel (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>
231function getOrCreateVideoAndAccountAndChannel (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable>
232function getOrCreateVideoAndAccountAndChannel (
233 options: GetVideoParamOther
234): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail>
235async function getOrCreateVideoAndAccountAndChannel (
236 options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther
237): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
221 // Default params 238 // Default params
222 const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false } 239 const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false }
223 const fetchType = options.fetchType || 'all' 240 const fetchType = options.fetchType || 'all'
@@ -225,12 +242,13 @@ async function getOrCreateVideoAndAccountAndChannel (options: {
225 242
226 // Get video url 243 // Get video url
227 const videoUrl = getAPId(options.videoObject) 244 const videoUrl = getAPId(options.videoObject)
228
229 let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) 245 let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
246
230 if (videoFromDatabase) { 247 if (videoFromDatabase) {
231 if (videoFromDatabase.isOutdated() && allowRefresh === true) { 248 // If allowRefresh is true, we could not call this function using 'only-immutable-attributes' fetch type
249 if (allowRefresh === true && (videoFromDatabase as MVideoThumbnail).isOutdated()) {
232 const refreshOptions = { 250 const refreshOptions = {
233 video: videoFromDatabase, 251 video: videoFromDatabase as MVideoThumbnail,
234 fetchedType: fetchType, 252 fetchedType: fetchType,
235 syncParam 253 syncParam
236 } 254 }