aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r--server/lib/activitypub/videos.ts32
1 files changed, 18 insertions, 14 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 6c2095897..783f78d3e 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -3,12 +3,12 @@ import * as sequelize from 'sequelize'
3import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
4import { join } from 'path' 4import { join } from 'path'
5import * as request from 'request' 5import * as request from 'request'
6import { ActivityIconObject, VideoState } from '../../../shared/index' 6import { ActivityIconObject, ActivityVideoUrlObject, VideoState, ActivityUrlObject } from '../../../shared/index'
7import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 7import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
8import { VideoPrivacy } from '../../../shared/models/videos' 8import { VideoPrivacy } from '../../../shared/models/videos'
9import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' 9import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos'
10import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' 10import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
11import { resetSequelizeInstance, retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' 11import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
12import { logger } from '../../helpers/logger' 12import { logger } from '../../helpers/logger'
13import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' 13import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
14import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers' 14import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers'
@@ -17,7 +17,7 @@ import { TagModel } from '../../models/video/tag'
17import { VideoModel } from '../../models/video/video' 17import { VideoModel } from '../../models/video/video'
18import { VideoChannelModel } from '../../models/video/video-channel' 18import { VideoChannelModel } from '../../models/video/video-channel'
19import { VideoFileModel } from '../../models/video/video-file' 19import { VideoFileModel } from '../../models/video/video-file'
20import { getOrCreateActorAndServerAndModel, updateActorAvatarInstance } from './actor' 20import { getOrCreateActorAndServerAndModel } from './actor'
21import { addVideoComments } from './video-comments' 21import { addVideoComments } from './video-comments'
22import { crawlCollectionPage } from './crawl' 22import { crawlCollectionPage } from './crawl'
23import { sendCreateVideo, sendUpdateVideo } from './send' 23import { sendCreateVideo, sendUpdateVideo } from './send'
@@ -25,7 +25,6 @@ import { isArray } from '../../helpers/custom-validators/misc'
25import { VideoCaptionModel } from '../../models/video/video-caption' 25import { VideoCaptionModel } from '../../models/video/video-caption'
26import { JobQueue } from '../job-queue' 26import { JobQueue } from '../job-queue'
27import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher' 27import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher'
28import { getUrlFromWebfinger } from '../../helpers/webfinger'
29import { createRates } from './video-rates' 28import { createRates } from './video-rates'
30import { addVideoShares, shareVideoByServerAndChannel } from './share' 29import { addVideoShares, shareVideoByServerAndChannel } from './share'
31import { AccountModel } from '../../models/account/account' 30import { AccountModel } from '../../models/account/account'
@@ -137,10 +136,7 @@ async function videoActivityObjectToDBAttributes (
137} 136}
138 137
139function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObject: VideoTorrentObject) { 138function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObject: VideoTorrentObject) {
140 const mimeTypes = Object.keys(VIDEO_MIMETYPE_EXT) 139 const fileUrls = videoObject.url.filter(u => isActivityVideoUrlObject(u)) as ActivityVideoUrlObject[]
141 const fileUrls = videoObject.url.filter(u => {
142 return mimeTypes.indexOf(u.mimeType) !== -1 && u.mimeType.startsWith('video/')
143 })
144 140
145 if (fileUrls.length === 0) { 141 if (fileUrls.length === 0) {
146 throw new Error('Cannot find video files for ' + videoCreated.url) 142 throw new Error('Cannot find video files for ' + videoCreated.url)
@@ -331,8 +327,8 @@ async function refreshVideoIfNeeded (video: VideoModel): Promise<VideoModel> {
331 327
332 const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject) 328 const channelActor = await getOrCreateVideoChannelFromVideoObject(videoObject)
333 const account = await AccountModel.load(channelActor.VideoChannel.accountId) 329 const account = await AccountModel.load(channelActor.VideoChannel.accountId)
334 return updateVideoFromAP(video, videoObject, account.Actor, channelActor)
335 330
331 return updateVideoFromAP(video, videoObject, account, channelActor.VideoChannel)
336 } catch (err) { 332 } catch (err) {
337 logger.warn('Cannot refresh video.', { err }) 333 logger.warn('Cannot refresh video.', { err })
338 return video 334 return video
@@ -342,8 +338,8 @@ async function refreshVideoIfNeeded (video: VideoModel): Promise<VideoModel> {
342async function updateVideoFromAP ( 338async function updateVideoFromAP (
343 video: VideoModel, 339 video: VideoModel,
344 videoObject: VideoTorrentObject, 340 videoObject: VideoTorrentObject,
345 accountActor: ActorModel, 341 account: AccountModel,
346 channelActor: ActorModel, 342 channel: VideoChannelModel,
347 overrideTo?: string[] 343 overrideTo?: string[]
348) { 344) {
349 logger.debug('Updating remote video "%s".', videoObject.uuid) 345 logger.debug('Updating remote video "%s".', videoObject.uuid)
@@ -359,12 +355,12 @@ async function updateVideoFromAP (
359 355
360 // Check actor has the right to update the video 356 // Check actor has the right to update the video
361 const videoChannel = video.VideoChannel 357 const videoChannel = video.VideoChannel
362 if (videoChannel.Account.Actor.id !== accountActor.id) { 358 if (videoChannel.Account.id !== account.id) {
363 throw new Error('Account ' + accountActor.url + ' does not own video channel ' + videoChannel.Actor.url) 359 throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url)
364 } 360 }
365 361
366 const to = overrideTo ? overrideTo : videoObject.to 362 const to = overrideTo ? overrideTo : videoObject.to
367 const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, to) 363 const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to)
368 video.set('name', videoData.name) 364 video.set('name', videoData.name)
369 video.set('uuid', videoData.uuid) 365 video.set('uuid', videoData.uuid)
370 video.set('url', videoData.url) 366 video.set('url', videoData.url)
@@ -444,3 +440,11 @@ export {
444 addVideoShares, 440 addVideoShares,
445 createRates 441 createRates
446} 442}
443
444// ---------------------------------------------------------------------------
445
446function isActivityVideoUrlObject (url: ActivityUrlObject): url is ActivityVideoUrlObject {
447 const mimeTypes = Object.keys(VIDEO_MIMETYPE_EXT)
448
449 return mimeTypes.indexOf(url.mimeType) !== -1 && url.mimeType.startsWith('video/')
450}