X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fvideos.ts;h=506204674dbafad0f6bced6113d74b83a2e4ec85;hb=1e0741d16545ea720d04b566a808853b3975ea7f;hp=a5f58dd013c95769422cd393bd8eca018c9a89e0;hpb=db4b15f21fbf4e33434e930ffc7fb768cdcf9d42;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index a5f58dd01..506204674 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -1,7 +1,7 @@ import * as Bluebird from 'bluebird' import { maxBy, minBy } from 'lodash' import * as magnetUtil from 'magnet-uri' -import { basename, join } from 'path' +import { basename } from 'path' import { Transaction } from 'sequelize/types' import { TrackerModel } from '@server/models/server/tracker' import { VideoLiveModel } from '@server/models/video/video-live' @@ -16,7 +16,7 @@ import { ActivityUrlObject, ActivityVideoUrlObject } from '../../../shared/index' -import { ActivityIconObject, ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' +import { ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' import { VideoPrivacy } from '../../../shared/models/videos' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' @@ -30,11 +30,10 @@ import { isArray } from '../../helpers/custom-validators/misc' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' import { deleteNonExistingModels, resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' import { logger } from '../../helpers/logger' -import { doJSONRequest } from '../../helpers/requests' +import { doJSONRequest, PeerTubeRequestError } from '../../helpers/requests' import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video' import { ACTIVITY_PUB, - LAZY_STATIC_PATHS, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, PREVIEWS_SIZE, @@ -367,13 +366,13 @@ async function updateVideoFromAP (options: { if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) - if (videoUpdated.getPreview()) { - const previewUrl = getPreviewUrl(getPreviewFromIcons(videoObject), video) + const previewIcon = getPreviewFromIcons(videoObject) + if (videoUpdated.getPreview() && previewIcon) { const previewModel = createPlaceholderThumbnail({ - fileUrl: previewUrl, + fileUrl: previewIcon.url, video, type: ThumbnailType.PREVIEW, - size: PREVIEWS_SIZE + size: previewIcon }) await videoUpdated.addAndSaveThumbnail(previewModel, t) } @@ -523,14 +522,7 @@ async function refreshVideoIfNeeded (options: { : await VideoModel.loadByUrlAndPopulateAccount(options.video.url) try { - const { statusCode, videoObject } = await fetchRemoteVideo(video.url) - if (statusCode === HttpStatusCode.NOT_FOUND_404) { - logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url) - - // Video does not exist anymore - await video.destroy() - return undefined - } + const { videoObject } = await fetchRemoteVideo(video.url) if (videoObject === undefined) { logger.warn('Cannot refresh remote video %s: invalid body.', video.url) @@ -547,13 +539,21 @@ async function refreshVideoIfNeeded (options: { account: channelActor.VideoChannel.Account, channel: channelActor.VideoChannel } - await retryTransactionWrapper(updateVideoFromAP, updateOptions) + await updateVideoFromAP(updateOptions) await syncVideoExternalAttributes(video, videoObject, options.syncParam) ActorFollowScoreCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId) return video } catch (err) { + if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) { + logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url) + + // Video does not exist anymore + await video.destroy() + return undefined + } + logger.warn('Cannot refresh video %s.', options.video.url, { err }) ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId) @@ -627,15 +627,17 @@ async function createVideo (videoObject: VideoObject, channel: MChannelAccountLi if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) - const previewUrl = getPreviewUrl(getPreviewFromIcons(videoObject), videoCreated) - const previewModel = createPlaceholderThumbnail({ - fileUrl: previewUrl, - video: videoCreated, - type: ThumbnailType.PREVIEW, - size: PREVIEWS_SIZE - }) + const previewIcon = getPreviewFromIcons(videoObject) + if (previewIcon) { + const previewModel = createPlaceholderThumbnail({ + fileUrl: previewIcon.url, + video: videoCreated, + type: ThumbnailType.PREVIEW, + size: previewIcon + }) - if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t) + await videoCreated.addAndSaveThumbnail(previewModel, t) + } // Process files const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject.url) @@ -895,12 +897,6 @@ function getPreviewFromIcons (videoObject: VideoObject) { return maxBy(validIcons, 'width') } -function getPreviewUrl (previewIcon: ActivityIconObject, video: MVideoWithHost) { - return previewIcon - ? previewIcon.url - : buildRemoteVideoBaseUrl(video, join(LAZY_STATIC_PATHS.PREVIEWS, video.generatePreviewName())) -} - function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { let wsFound = false