aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-08 11:23:45 +0200
committerChocobozzz <me@florianbigard.com>2021-04-08 13:38:04 +0200
commit84531547bc0934a2abda586d539f7455b455d488 (patch)
tree128bf5f3a7f57e4e2f343d5da574a4e002163736 /server/lib/activitypub/videos.ts
parenta0eeb45f14bab539f505861cad8f5d42d9ba30cb (diff)
downloadPeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.gz
PeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.zst
PeerTube-84531547bc0934a2abda586d539f7455b455d488.zip
Add size info in db for actor images
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r--server/lib/activitypub/videos.ts38
1 files changed, 16 insertions, 22 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 492b97b9e..9014791c0 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -1,9 +1,8 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { maxBy, minBy } from 'lodash' 2import { maxBy, minBy } from 'lodash'
3import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
4import { basename, join } from 'path' 4import { basename } from 'path'
5import { Transaction } from 'sequelize/types' 5import { Transaction } from 'sequelize/types'
6import { ActorImageModel } from '@server/models/account/actor-image'
7import { TrackerModel } from '@server/models/server/tracker' 6import { TrackerModel } from '@server/models/server/tracker'
8import { VideoLiveModel } from '@server/models/video/video-live' 7import { VideoLiveModel } from '@server/models/video/video-live'
9import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
@@ -17,7 +16,7 @@ import {
17 ActivityUrlObject, 16 ActivityUrlObject,
18 ActivityVideoUrlObject 17 ActivityVideoUrlObject
19} from '../../../shared/index' 18} from '../../../shared/index'
20import { ActivityIconObject, ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' 19import { ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects'
21import { VideoPrivacy } from '../../../shared/models/videos' 20import { VideoPrivacy } from '../../../shared/models/videos'
22import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 21import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
23import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 22import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -35,7 +34,6 @@ import { doJSONRequest, PeerTubeRequestError } from '../../helpers/requests'
35import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video' 34import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video'
36import { 35import {
37 ACTIVITY_PUB, 36 ACTIVITY_PUB,
38 LAZY_STATIC_PATHS,
39 MIMETYPES, 37 MIMETYPES,
40 P2P_MEDIA_LOADER_PEER_VERSION, 38 P2P_MEDIA_LOADER_PEER_VERSION,
41 PREVIEWS_SIZE, 39 PREVIEWS_SIZE,
@@ -368,13 +366,13 @@ async function updateVideoFromAP (options: {
368 366
369 if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) 367 if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t)
370 368
371 if (videoUpdated.getPreview()) { 369 const previewIcon = getPreviewFromIcons(videoObject)
372 const previewUrl = getPreviewUrl(getPreviewFromIcons(videoObject), video) 370 if (videoUpdated.getPreview() && previewIcon) {
373 const previewModel = createPlaceholderThumbnail({ 371 const previewModel = createPlaceholderThumbnail({
374 fileUrl: previewUrl, 372 fileUrl: previewIcon.url,
375 video, 373 video,
376 type: ThumbnailType.PREVIEW, 374 type: ThumbnailType.PREVIEW,
377 size: PREVIEWS_SIZE 375 size: previewIcon
378 }) 376 })
379 await videoUpdated.addAndSaveThumbnail(previewModel, t) 377 await videoUpdated.addAndSaveThumbnail(previewModel, t)
380 } 378 }
@@ -629,15 +627,17 @@ async function createVideo (videoObject: VideoObject, channel: MChannelAccountLi
629 627
630 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 628 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
631 629
632 const previewUrl = getPreviewUrl(getPreviewFromIcons(videoObject), videoCreated) 630 const previewIcon = getPreviewFromIcons(videoObject)
633 const previewModel = createPlaceholderThumbnail({ 631 if (previewIcon) {
634 fileUrl: previewUrl, 632 const previewModel = createPlaceholderThumbnail({
635 video: videoCreated, 633 fileUrl: previewIcon.url,
636 type: ThumbnailType.PREVIEW, 634 video: videoCreated,
637 size: PREVIEWS_SIZE 635 type: ThumbnailType.PREVIEW,
638 }) 636 size: previewIcon
637 })
639 638
640 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t) 639 await videoCreated.addAndSaveThumbnail(previewModel, t)
640 }
641 641
642 // Process files 642 // Process files
643 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject.url) 643 const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject.url)
@@ -897,12 +897,6 @@ function getPreviewFromIcons (videoObject: VideoObject) {
897 return maxBy(validIcons, 'width') 897 return maxBy(validIcons, 'width')
898} 898}
899 899
900function getPreviewUrl (previewIcon: ActivityIconObject, video: MVideoWithHost) {
901 return previewIcon
902 ? previewIcon.url
903 : buildRemoteVideoBaseUrl(video, join(LAZY_STATIC_PATHS.PREVIEWS, ActorImageModel.generateFilename()))
904}
905
906function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { 900function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
907 let wsFound = false 901 let wsFound = false
908 902