diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-08 11:23:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-04-08 13:38:04 +0200 |
commit | 84531547bc0934a2abda586d539f7455b455d488 (patch) | |
tree | 128bf5f3a7f57e4e2f343d5da574a4e002163736 /server/lib/activitypub | |
parent | a0eeb45f14bab539f505861cad8f5d42d9ba30cb (diff) | |
download | PeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.gz PeerTube-84531547bc0934a2abda586d539f7455b455d488.tar.zst PeerTube-84531547bc0934a2abda586d539f7455b455d488.zip |
Add size info in db for actor images
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/actor.ts | 35 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 38 |
2 files changed, 41 insertions, 32 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 917fed6ec..eec951d4e 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts | |||
@@ -170,7 +170,13 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ | |||
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | type ImageInfo = { name: string, onDisk?: boolean, fileUrl: string } | 173 | type ImageInfo = { |
174 | name: string | ||
175 | fileUrl: string | ||
176 | height: number | ||
177 | width: number | ||
178 | onDisk?: boolean | ||
179 | } | ||
174 | async function updateActorImageInstance (actor: MActorImages, type: ActorImageType, imageInfo: ImageInfo | null, t: Transaction) { | 180 | async function updateActorImageInstance (actor: MActorImages, type: ActorImageType, imageInfo: ImageInfo | null, t: Transaction) { |
175 | const oldImageModel = type === ActorImageType.AVATAR | 181 | const oldImageModel = type === ActorImageType.AVATAR |
176 | ? actor.Avatar | 182 | ? actor.Avatar |
@@ -194,7 +200,9 @@ async function updateActorImageInstance (actor: MActorImages, type: ActorImageTy | |||
194 | filename: imageInfo.name, | 200 | filename: imageInfo.name, |
195 | onDisk: imageInfo.onDisk ?? false, | 201 | onDisk: imageInfo.onDisk ?? false, |
196 | fileUrl: imageInfo.fileUrl, | 202 | fileUrl: imageInfo.fileUrl, |
197 | type: type | 203 | height: imageInfo.height, |
204 | width: imageInfo.width, | ||
205 | type | ||
198 | }, { transaction: t }) | 206 | }, { transaction: t }) |
199 | 207 | ||
200 | setActorImage(actor, type, imageModel) | 208 | setActorImage(actor, type, imageModel) |
@@ -257,6 +265,8 @@ function getImageInfoIfExists (actorJSON: ActivityPubActor, type: ActorImageType | |||
257 | return { | 265 | return { |
258 | name: uuidv4() + extension, | 266 | name: uuidv4() + extension, |
259 | fileUrl: icon.url, | 267 | fileUrl: icon.url, |
268 | height: icon.height, | ||
269 | width: icon.width, | ||
260 | type | 270 | type |
261 | } | 271 | } |
262 | } | 272 | } |
@@ -408,6 +418,8 @@ function saveActorAndServerAndModelIfNotExist ( | |||
408 | const avatar = await ActorImageModel.create({ | 418 | const avatar = await ActorImageModel.create({ |
409 | filename: result.avatar.name, | 419 | filename: result.avatar.name, |
410 | fileUrl: result.avatar.fileUrl, | 420 | fileUrl: result.avatar.fileUrl, |
421 | width: result.avatar.width, | ||
422 | height: result.avatar.height, | ||
411 | onDisk: false, | 423 | onDisk: false, |
412 | type: ActorImageType.AVATAR | 424 | type: ActorImageType.AVATAR |
413 | }, { transaction: t }) | 425 | }, { transaction: t }) |
@@ -420,6 +432,8 @@ function saveActorAndServerAndModelIfNotExist ( | |||
420 | const banner = await ActorImageModel.create({ | 432 | const banner = await ActorImageModel.create({ |
421 | filename: result.banner.name, | 433 | filename: result.banner.name, |
422 | fileUrl: result.banner.fileUrl, | 434 | fileUrl: result.banner.fileUrl, |
435 | width: result.banner.width, | ||
436 | height: result.banner.height, | ||
423 | onDisk: false, | 437 | onDisk: false, |
424 | type: ActorImageType.BANNER | 438 | type: ActorImageType.BANNER |
425 | }, { transaction: t }) | 439 | }, { transaction: t }) |
@@ -470,20 +484,21 @@ function saveActorAndServerAndModelIfNotExist ( | |||
470 | } | 484 | } |
471 | } | 485 | } |
472 | 486 | ||
487 | type ImageResult = { | ||
488 | name: string | ||
489 | fileUrl: string | ||
490 | height: number | ||
491 | width: number | ||
492 | } | ||
493 | |||
473 | type FetchRemoteActorResult = { | 494 | type FetchRemoteActorResult = { |
474 | actor: MActor | 495 | actor: MActor |
475 | name: string | 496 | name: string |
476 | summary: string | 497 | summary: string |
477 | support?: string | 498 | support?: string |
478 | playlists?: string | 499 | playlists?: string |
479 | avatar?: { | 500 | avatar?: ImageResult |
480 | name: string | 501 | banner?: ImageResult |
481 | fileUrl: string | ||
482 | } | ||
483 | banner?: { | ||
484 | name: string | ||
485 | fileUrl: string | ||
486 | } | ||
487 | attributedTo: ActivityPubAttributedTo[] | 502 | attributedTo: ActivityPubAttributedTo[] |
488 | } | 503 | } |
489 | async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: number, result: FetchRemoteActorResult }> { | 504 | async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: number, result: FetchRemoteActorResult }> { |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { maxBy, minBy } from 'lodash' | 2 | import { maxBy, minBy } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import { basename, join } from 'path' | 4 | import { basename } from 'path' |
5 | import { Transaction } from 'sequelize/types' | 5 | import { Transaction } from 'sequelize/types' |
6 | import { ActorImageModel } from '@server/models/account/actor-image' | ||
7 | import { TrackerModel } from '@server/models/server/tracker' | 6 | import { TrackerModel } from '@server/models/server/tracker' |
8 | import { VideoLiveModel } from '@server/models/video/video-live' | 7 | import { VideoLiveModel } from '@server/models/video/video-live' |
9 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 8 | import { 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' |
20 | import { ActivityIconObject, ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' | 19 | import { ActivityTrackerUrlObject, VideoObject } from '../../../shared/models/activitypub/objects' |
21 | import { VideoPrivacy } from '../../../shared/models/videos' | 20 | import { VideoPrivacy } from '../../../shared/models/videos' |
22 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 21 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
23 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 22 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
@@ -35,7 +34,6 @@ import { doJSONRequest, PeerTubeRequestError } from '../../helpers/requests' | |||
35 | import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video' | 34 | import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video' |
36 | import { | 35 | import { |
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 | ||
900 | function getPreviewUrl (previewIcon: ActivityIconObject, video: MVideoWithHost) { | ||
901 | return previewIcon | ||
902 | ? previewIcon.url | ||
903 | : buildRemoteVideoBaseUrl(video, join(LAZY_STATIC_PATHS.PREVIEWS, ActorImageModel.generateFilename())) | ||
904 | } | ||
905 | |||
906 | function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { | 900 | function getTrackerUrls (object: VideoObject, video: MVideoWithHost) { |
907 | let wsFound = false | 901 | let wsFound = false |
908 | 902 | ||