mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add size info in db for actor images
This commit is contained in:
@@ -170,7 +170,13 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ
|
||||
}
|
||||
}
|
||||
|
||||
type ImageInfo = { name: string, onDisk?: boolean, fileUrl: string }
|
||||
type ImageInfo = {
|
||||
name: string
|
||||
fileUrl: string
|
||||
height: number
|
||||
width: number
|
||||
onDisk?: boolean
|
||||
}
|
||||
async function updateActorImageInstance (actor: MActorImages, type: ActorImageType, imageInfo: ImageInfo | null, t: Transaction) {
|
||||
const oldImageModel = type === ActorImageType.AVATAR
|
||||
? actor.Avatar
|
||||
@@ -194,7 +200,9 @@ async function updateActorImageInstance (actor: MActorImages, type: ActorImageTy
|
||||
filename: imageInfo.name,
|
||||
onDisk: imageInfo.onDisk ?? false,
|
||||
fileUrl: imageInfo.fileUrl,
|
||||
type: type
|
||||
height: imageInfo.height,
|
||||
width: imageInfo.width,
|
||||
type
|
||||
}, { transaction: t })
|
||||
|
||||
setActorImage(actor, type, imageModel)
|
||||
@@ -257,6 +265,8 @@ function getImageInfoIfExists (actorJSON: ActivityPubActor, type: ActorImageType
|
||||
return {
|
||||
name: uuidv4() + extension,
|
||||
fileUrl: icon.url,
|
||||
height: icon.height,
|
||||
width: icon.width,
|
||||
type
|
||||
}
|
||||
}
|
||||
@@ -408,6 +418,8 @@ function saveActorAndServerAndModelIfNotExist (
|
||||
const avatar = await ActorImageModel.create({
|
||||
filename: result.avatar.name,
|
||||
fileUrl: result.avatar.fileUrl,
|
||||
width: result.avatar.width,
|
||||
height: result.avatar.height,
|
||||
onDisk: false,
|
||||
type: ActorImageType.AVATAR
|
||||
}, { transaction: t })
|
||||
@@ -420,6 +432,8 @@ function saveActorAndServerAndModelIfNotExist (
|
||||
const banner = await ActorImageModel.create({
|
||||
filename: result.banner.name,
|
||||
fileUrl: result.banner.fileUrl,
|
||||
width: result.banner.width,
|
||||
height: result.banner.height,
|
||||
onDisk: false,
|
||||
type: ActorImageType.BANNER
|
||||
}, { transaction: t })
|
||||
@@ -470,20 +484,21 @@ function saveActorAndServerAndModelIfNotExist (
|
||||
}
|
||||
}
|
||||
|
||||
type ImageResult = {
|
||||
name: string
|
||||
fileUrl: string
|
||||
height: number
|
||||
width: number
|
||||
}
|
||||
|
||||
type FetchRemoteActorResult = {
|
||||
actor: MActor
|
||||
name: string
|
||||
summary: string
|
||||
support?: string
|
||||
playlists?: string
|
||||
avatar?: {
|
||||
name: string
|
||||
fileUrl: string
|
||||
}
|
||||
banner?: {
|
||||
name: string
|
||||
fileUrl: string
|
||||
}
|
||||
avatar?: ImageResult
|
||||
banner?: ImageResult
|
||||
attributedTo: ActivityPubAttributedTo[]
|
||||
}
|
||||
async function fetchRemoteActor (actorUrl: string): Promise<{ statusCode?: number, result: FetchRemoteActorResult }> {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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 { ActorImageModel } from '@server/models/account/actor-image'
|
||||
import { TrackerModel } from '@server/models/server/tracker'
|
||||
import { VideoLiveModel } from '@server/models/video/video-live'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
@@ -17,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'
|
||||
@@ -35,7 +34,6 @@ 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,
|
||||
@@ -368,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)
|
||||
}
|
||||
@@ -629,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)
|
||||
@@ -897,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, ActorImageModel.generateFilename()))
|
||||
}
|
||||
|
||||
function getTrackerUrls (object: VideoObject, video: MVideoWithHost) {
|
||||
let wsFound = false
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ async function updateLocalActorImageFile (
|
||||
const actorImageInfo = {
|
||||
name: imageName,
|
||||
fileUrl: null,
|
||||
height: imageSize.height,
|
||||
width: imageSize.width,
|
||||
onDisk: true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { join } from 'path'
|
||||
import { ActorImageModel } from '@server/models/account/actor-image'
|
||||
|
||||
import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
|
||||
import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
|
||||
import { processImage } from '../helpers/image-utils'
|
||||
import { generateImageFilename, processImage } from '../helpers/image-utils'
|
||||
import { downloadImage } from '../helpers/requests'
|
||||
import { CONFIG } from '../initializers/config'
|
||||
import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants'
|
||||
@@ -12,7 +12,7 @@ import { MThumbnail } from '../types/models/video/thumbnail'
|
||||
import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
|
||||
import { getVideoFilePath } from './video-paths'
|
||||
|
||||
type ImageSize = { height: number, width: number }
|
||||
type ImageSize = { height?: number, width?: number }
|
||||
|
||||
function createPlaylistMiniatureFromExisting (options: {
|
||||
inputPath: string
|
||||
@@ -201,7 +201,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si
|
||||
: undefined
|
||||
|
||||
if (type === ThumbnailType.MINIATURE) {
|
||||
const filename = ActorImageModel.generateFilename()
|
||||
const filename = generateImageFilename()
|
||||
const basePath = CONFIG.STORAGE.THUMBNAILS_DIR
|
||||
|
||||
return {
|
||||
@@ -215,7 +215,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si
|
||||
}
|
||||
|
||||
if (type === ThumbnailType.PREVIEW) {
|
||||
const filename = ActorImageModel.generateFilename()
|
||||
const filename = generateImageFilename()
|
||||
const basePath = CONFIG.STORAGE.PREVIEWS_DIR
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user