diff options
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 32 |
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' | |||
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import * as request from 'request' | 5 | import * as request from 'request' |
6 | import { ActivityIconObject, VideoState } from '../../../shared/index' | 6 | import { ActivityIconObject, ActivityVideoUrlObject, VideoState, ActivityUrlObject } from '../../../shared/index' |
7 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 7 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
8 | import { VideoPrivacy } from '../../../shared/models/videos' | 8 | import { VideoPrivacy } from '../../../shared/models/videos' |
9 | import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' | 9 | import { sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' |
10 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 10 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
11 | import { resetSequelizeInstance, retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils' | 11 | import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | 13 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' |
14 | import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers' | 14 | import { ACTIVITY_PUB, CONFIG, REMOTE_SCHEME, sequelizeTypescript, VIDEO_MIMETYPE_EXT } from '../../initializers' |
@@ -17,7 +17,7 @@ import { TagModel } from '../../models/video/tag' | |||
17 | import { VideoModel } from '../../models/video/video' | 17 | import { VideoModel } from '../../models/video/video' |
18 | import { VideoChannelModel } from '../../models/video/video-channel' | 18 | import { VideoChannelModel } from '../../models/video/video-channel' |
19 | import { VideoFileModel } from '../../models/video/video-file' | 19 | import { VideoFileModel } from '../../models/video/video-file' |
20 | import { getOrCreateActorAndServerAndModel, updateActorAvatarInstance } from './actor' | 20 | import { getOrCreateActorAndServerAndModel } from './actor' |
21 | import { addVideoComments } from './video-comments' | 21 | import { addVideoComments } from './video-comments' |
22 | import { crawlCollectionPage } from './crawl' | 22 | import { crawlCollectionPage } from './crawl' |
23 | import { sendCreateVideo, sendUpdateVideo } from './send' | 23 | import { sendCreateVideo, sendUpdateVideo } from './send' |
@@ -25,7 +25,6 @@ import { isArray } from '../../helpers/custom-validators/misc' | |||
25 | import { VideoCaptionModel } from '../../models/video/video-caption' | 25 | import { VideoCaptionModel } from '../../models/video/video-caption' |
26 | import { JobQueue } from '../job-queue' | 26 | import { JobQueue } from '../job-queue' |
27 | import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher' | 27 | import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher' |
28 | import { getUrlFromWebfinger } from '../../helpers/webfinger' | ||
29 | import { createRates } from './video-rates' | 28 | import { createRates } from './video-rates' |
30 | import { addVideoShares, shareVideoByServerAndChannel } from './share' | 29 | import { addVideoShares, shareVideoByServerAndChannel } from './share' |
31 | import { AccountModel } from '../../models/account/account' | 30 | import { AccountModel } from '../../models/account/account' |
@@ -137,10 +136,7 @@ async function videoActivityObjectToDBAttributes ( | |||
137 | } | 136 | } |
138 | 137 | ||
139 | function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObject: VideoTorrentObject) { | 138 | function 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> { | |||
342 | async function updateVideoFromAP ( | 338 | async 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 | |||
446 | function 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 | } | ||