diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actor.ts | 35 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 38 | ||||
-rw-r--r-- | server/lib/actor-image.ts | 2 | ||||
-rw-r--r-- | server/lib/thumbnail.ts | 10 |
4 files changed, 48 insertions, 37 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 | ||
diff --git a/server/lib/actor-image.ts b/server/lib/actor-image.ts index fa1a2a18a..f271f0b5b 100644 --- a/server/lib/actor-image.ts +++ b/server/lib/actor-image.ts | |||
@@ -34,6 +34,8 @@ async function updateLocalActorImageFile ( | |||
34 | const actorImageInfo = { | 34 | const actorImageInfo = { |
35 | name: imageName, | 35 | name: imageName, |
36 | fileUrl: null, | 36 | fileUrl: null, |
37 | height: imageSize.height, | ||
38 | width: imageSize.width, | ||
37 | onDisk: true | 39 | onDisk: true |
38 | } | 40 | } |
39 | 41 | ||
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index e1176ac08..cfee69cfc 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import { ActorImageModel } from '@server/models/account/actor-image' | 2 | |
3 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' | 3 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' |
4 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' | 4 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' |
5 | import { processImage } from '../helpers/image-utils' | 5 | import { generateImageFilename, processImage } from '../helpers/image-utils' |
6 | import { downloadImage } from '../helpers/requests' | 6 | import { downloadImage } from '../helpers/requests' |
7 | import { CONFIG } from '../initializers/config' | 7 | import { CONFIG } from '../initializers/config' |
8 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' | 8 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' |
@@ -12,7 +12,7 @@ import { MThumbnail } from '../types/models/video/thumbnail' | |||
12 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' | 12 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' |
13 | import { getVideoFilePath } from './video-paths' | 13 | import { getVideoFilePath } from './video-paths' |
14 | 14 | ||
15 | type ImageSize = { height: number, width: number } | 15 | type ImageSize = { height?: number, width?: number } |
16 | 16 | ||
17 | function createPlaylistMiniatureFromExisting (options: { | 17 | function createPlaylistMiniatureFromExisting (options: { |
18 | inputPath: string | 18 | inputPath: string |
@@ -201,7 +201,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si | |||
201 | : undefined | 201 | : undefined |
202 | 202 | ||
203 | if (type === ThumbnailType.MINIATURE) { | 203 | if (type === ThumbnailType.MINIATURE) { |
204 | const filename = ActorImageModel.generateFilename() | 204 | const filename = generateImageFilename() |
205 | const basePath = CONFIG.STORAGE.THUMBNAILS_DIR | 205 | const basePath = CONFIG.STORAGE.THUMBNAILS_DIR |
206 | 206 | ||
207 | return { | 207 | return { |
@@ -215,7 +215,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si | |||
215 | } | 215 | } |
216 | 216 | ||
217 | if (type === ThumbnailType.PREVIEW) { | 217 | if (type === ThumbnailType.PREVIEW) { |
218 | const filename = ActorImageModel.generateFilename() | 218 | const filename = generateImageFilename() |
219 | const basePath = CONFIG.STORAGE.PREVIEWS_DIR | 219 | const basePath = CONFIG.STORAGE.PREVIEWS_DIR |
220 | 220 | ||
221 | return { | 221 | return { |