Verified Commit 91f8f8db authored by Chocobozzz's avatar Chocobozzz
Browse files

createThumbnail -> updateThumbnail

parent 1333ab1f
...@@ -18,7 +18,7 @@ import { sequelizeTypescript } from '../../initializers/database' ...@@ -18,7 +18,7 @@ import { sequelizeTypescript } from '../../initializers/database'
import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
import { getLocalVideoPlaylistActivityPubUrl, getLocalVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' import { getLocalVideoPlaylistActivityPubUrl, getLocalVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
import { JobQueue } from '../../lib/job-queue' import { JobQueue } from '../../lib/job-queue'
import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail' import { updatePlaylistMiniatureFromExisting } from '../../lib/thumbnail'
import { import {
asyncMiddleware, asyncMiddleware,
asyncRetryTransactionMiddleware, asyncRetryTransactionMiddleware,
...@@ -173,7 +173,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { ...@@ -173,7 +173,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
const thumbnailField = req.files['thumbnailfile'] const thumbnailField = req.files['thumbnailfile']
const thumbnailModel = thumbnailField const thumbnailModel = thumbnailField
? await createPlaylistMiniatureFromExisting({ ? await updatePlaylistMiniatureFromExisting({
inputPath: thumbnailField[0].path, inputPath: thumbnailField[0].path,
playlist: videoPlaylist, playlist: videoPlaylist,
automaticallyGenerated: false automaticallyGenerated: false
...@@ -215,7 +215,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) ...@@ -215,7 +215,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
const thumbnailField = req.files['thumbnailfile'] const thumbnailField = req.files['thumbnailfile']
const thumbnailModel = thumbnailField const thumbnailModel = thumbnailField
? await createPlaylistMiniatureFromExisting({ ? await updatePlaylistMiniatureFromExisting({
inputPath: thumbnailField[0].path, inputPath: thumbnailField[0].path,
playlist: videoPlaylistInstance, playlist: videoPlaylistInstance,
automaticallyGenerated: false automaticallyGenerated: false
...@@ -482,7 +482,7 @@ async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbn ...@@ -482,7 +482,7 @@ async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbn
} }
const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoMiniature.filename) const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoMiniature.filename)
const thumbnailModel = await createPlaylistMiniatureFromExisting({ const thumbnailModel = await updatePlaylistMiniatureFromExisting({
inputPath, inputPath,
playlist: videoPlaylist, playlist: videoPlaylist,
automaticallyGenerated: true, automaticallyGenerated: true,
......
...@@ -31,7 +31,7 @@ import { MIMETYPES } from '../../../initializers/constants' ...@@ -31,7 +31,7 @@ import { MIMETYPES } from '../../../initializers/constants'
import { sequelizeTypescript } from '../../../initializers/database' import { sequelizeTypescript } from '../../../initializers/database'
import { getLocalVideoActivityPubUrl } from '../../../lib/activitypub/url' import { getLocalVideoActivityPubUrl } from '../../../lib/activitypub/url'
import { JobQueue } from '../../../lib/job-queue/job-queue' import { JobQueue } from '../../../lib/job-queue/job-queue'
import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail' import { updateVideoMiniatureFromExisting, updateVideoMiniatureFromUrl } from '../../../lib/thumbnail'
import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
import { VideoModel } from '../../../models/video/video' import { VideoModel } from '../../../models/video/video'
...@@ -230,7 +230,7 @@ async function processThumbnail (req: express.Request, video: MVideoThumbnail) { ...@@ -230,7 +230,7 @@ async function processThumbnail (req: express.Request, video: MVideoThumbnail) {
if (thumbnailField) { if (thumbnailField) {
const thumbnailPhysicalFile = thumbnailField[0] const thumbnailPhysicalFile = thumbnailField[0]
return createVideoMiniatureFromExisting({ return updateVideoMiniatureFromExisting({
inputPath: thumbnailPhysicalFile.path, inputPath: thumbnailPhysicalFile.path,
video, video,
type: ThumbnailType.MINIATURE, type: ThumbnailType.MINIATURE,
...@@ -246,7 +246,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr ...@@ -246,7 +246,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr
if (previewField) { if (previewField) {
const previewPhysicalFile = previewField[0] const previewPhysicalFile = previewField[0]
return createVideoMiniatureFromExisting({ return updateVideoMiniatureFromExisting({
inputPath: previewPhysicalFile.path, inputPath: previewPhysicalFile.path,
video, video,
type: ThumbnailType.PREVIEW, type: ThumbnailType.PREVIEW,
...@@ -259,7 +259,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr ...@@ -259,7 +259,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr
async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) { async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) {
try { try {
return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.MINIATURE }) return updateVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.MINIATURE })
} catch (err) { } catch (err) {
logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err }) logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err })
return undefined return undefined
...@@ -268,7 +268,7 @@ async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) { ...@@ -268,7 +268,7 @@ async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) {
async function processPreviewFromUrl (url: string, video: MVideoThumbnail) { async function processPreviewFromUrl (url: string, video: MVideoThumbnail) {
try { try {
return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.PREVIEW }) return updateVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.PREVIEW })
} catch (err) { } catch (err) {
logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err }) logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err })
return undefined return undefined
......
...@@ -13,7 +13,7 @@ import { MVideoDetails, MVideoFullLight } from '@server/types/models' ...@@ -13,7 +13,7 @@ import { MVideoDetails, MVideoFullLight } from '@server/types/models'
import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared' import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { sequelizeTypescript } from '../../../initializers/database' import { sequelizeTypescript } from '../../../initializers/database'
import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' import { updateVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
import { VideoModel } from '../../../models/video/video' import { VideoModel } from '../../../models/video/video'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
...@@ -100,7 +100,7 @@ async function addLiveVideo (req: express.Request, res: express.Response) { ...@@ -100,7 +100,7 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
video, video,
files: req.files, files: req.files,
fallback: type => { fallback: type => {
return createVideoMiniatureFromExisting({ return updateVideoMiniatureFromExisting({
inputPath: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND, inputPath: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND,
video, video,
type, type,
......
...@@ -2,7 +2,7 @@ import { isArray } from '@server/helpers/custom-validators/misc' ...@@ -2,7 +2,7 @@ import { isArray } from '@server/helpers/custom-validators/misc'
import { logger, loggerTagsFactory } from '@server/helpers/logger' import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants' import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants'
import { sequelizeTypescript } from '@server/initializers/database' import { sequelizeTypescript } from '@server/initializers/database'
import { createPlaylistMiniatureFromUrl } from '@server/lib/thumbnail' import { updatePlaylistMiniatureFromUrl } from '@server/lib/thumbnail'
import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistModel } from '@server/models/video/video-playlist'
import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
import { FilteredModelAttributes } from '@server/types' import { FilteredModelAttributes } from '@server/types'
...@@ -98,7 +98,7 @@ async function fetchElementUrls (playlistObject: PlaylistObject) { ...@@ -98,7 +98,7 @@ async function fetchElementUrls (playlistObject: PlaylistObject) {
async function updatePlaylistThumbnail (playlistObject: PlaylistObject, playlist: MVideoPlaylistFull) { async function updatePlaylistThumbnail (playlistObject: PlaylistObject, playlist: MVideoPlaylistFull) {
if (playlistObject.icon) { if (playlistObject.icon) {
const thumbnailModel = await createPlaylistMiniatureFromUrl({ downloadUrl: playlistObject.icon.url, playlist }) const thumbnailModel = await updatePlaylistMiniatureFromUrl({ downloadUrl: playlistObject.icon.url, playlist })
await playlist.setAndSaveThumbnail(thumbnailModel, undefined) await playlist.setAndSaveThumbnail(thumbnailModel, undefined)
return return
......
...@@ -2,7 +2,7 @@ import { Transaction } from 'sequelize/types' ...@@ -2,7 +2,7 @@ import { Transaction } from 'sequelize/types'
import { checkUrlsSameHost } from '@server/helpers/activitypub' import { checkUrlsSameHost } from '@server/helpers/activitypub'
import { deleteNonExistingModels } from '@server/helpers/database-utils' import { deleteNonExistingModels } from '@server/helpers/database-utils'
import { logger, LoggerTagsFn } from '@server/helpers/logger' import { logger, LoggerTagsFn } from '@server/helpers/logger'
import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '@server/lib/thumbnail' import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail'
import { setVideoTags } from '@server/lib/video' import { setVideoTags } from '@server/lib/video'
import { VideoCaptionModel } from '@server/models/video/video-caption' import { VideoCaptionModel } from '@server/models/video/video-caption'
import { VideoFileModel } from '@server/models/video/video-file' import { VideoFileModel } from '@server/models/video/video-file'
...@@ -38,7 +38,7 @@ export abstract class APVideoAbstractBuilder { ...@@ -38,7 +38,7 @@ export abstract class APVideoAbstractBuilder {
} }
protected tryToGenerateThumbnail (video: MVideoThumbnail): Promise<MThumbnail> { protected tryToGenerateThumbnail (video: MVideoThumbnail): Promise<MThumbnail> {
return createVideoMiniatureFromUrl({ return updateVideoMiniatureFromUrl({
downloadUrl: getThumbnailFromIcons(this.videoObject).url, downloadUrl: getThumbnailFromIcons(this.videoObject).url,
video, video,
type: ThumbnailType.MINIATURE type: ThumbnailType.MINIATURE
...@@ -54,7 +54,7 @@ export abstract class APVideoAbstractBuilder { ...@@ -54,7 +54,7 @@ export abstract class APVideoAbstractBuilder {
const previewIcon = getPreviewFromIcons(this.videoObject) const previewIcon = getPreviewFromIcons(this.videoObject)
if (!previewIcon) return if (!previewIcon) return
const previewModel = createPlaceholderThumbnail({ const previewModel = updatePlaceholderThumbnail({
fileUrl: previewIcon.url, fileUrl: previewIcon.url,
video, video,
type: ThumbnailType.PREVIEW, type: ThumbnailType.PREVIEW,
......
...@@ -14,7 +14,7 @@ import { getVideoFilePath } from './video-paths' ...@@ -14,7 +14,7 @@ import { getVideoFilePath } from './video-paths'
type ImageSize = { height?: number, width?: number } type ImageSize = { height?: number, width?: number }
function createPlaylistMiniatureFromExisting (options: { function updatePlaylistMiniatureFromExisting (options: {
inputPath: string inputPath: string
playlist: MVideoPlaylistThumbnail playlist: MVideoPlaylistThumbnail
automaticallyGenerated: boolean automaticallyGenerated: boolean
...@@ -26,7 +26,7 @@ function createPlaylistMiniatureFromExisting (options: { ...@@ -26,7 +26,7 @@ function createPlaylistMiniatureFromExisting (options: {
const type = ThumbnailType.MINIATURE const type = ThumbnailType.MINIATURE
const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
return createThumbnailFromFunction({ return updateThumbnailFromFunction({
thumbnailCreator, thumbnailCreator,
filename, filename,
height, height,
...@@ -37,7 +37,7 @@ function createPlaylistMiniatureFromExisting (options: { ...@@ -37,7 +37,7 @@ function createPlaylistMiniatureFromExisting (options: {
}) })
} }
function createPlaylistMiniatureFromUrl (options: { function updatePlaylistMiniatureFromUrl (options: {
downloadUrl: string downloadUrl: string
playlist: MVideoPlaylistThumbnail playlist: MVideoPlaylistThumbnail
size?: ImageSize size?: ImageSize
...@@ -52,10 +52,10 @@ function createPlaylistMiniatureFromUrl (options: { ...@@ -52,10 +52,10 @@ function createPlaylistMiniatureFromUrl (options: {
: downloadUrl : downloadUrl
const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
} }
function createVideoMiniatureFromUrl (options: { function updateVideoMiniatureFromUrl (options: {
downloadUrl: string downloadUrl: string
video: MVideoThumbnail video: MVideoThumbnail
type: ThumbnailType type: ThumbnailType
...@@ -82,10 +82,10 @@ function createVideoMiniatureFromUrl (options: { ...@@ -82,10 +82,10 @@ function createVideoMiniatureFromUrl (options: {
return Promise.resolve() return Promise.resolve()
} }
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
} }
function createVideoMiniatureFromExisting (options: { function updateVideoMiniatureFromExisting (options: {
inputPath: string inputPath: string
video: MVideoThumbnail video: MVideoThumbnail
type: ThumbnailType type: ThumbnailType
...@@ -98,7 +98,7 @@ function createVideoMiniatureFromExisting (options: { ...@@ -98,7 +98,7 @@ function createVideoMiniatureFromExisting (options: {
const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
return createThumbnailFromFunction({ return updateThumbnailFromFunction({
thumbnailCreator, thumbnailCreator,
filename, filename,
height, height,
...@@ -123,7 +123,7 @@ function generateVideoMiniature (options: { ...@@ -123,7 +123,7 @@ function generateVideoMiniature (options: {
? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true)
: () => generateImageFromVideoFile(input, basePath, filename, { height, width }) : () => generateImageFromVideoFile(input, basePath, filename, { height, width })
return createThumbnailFromFunction({ return updateThumbnailFromFunction({
thumbnailCreator, thumbnailCreator,
filename, filename,
height, height,
...@@ -134,7 +134,7 @@ function generateVideoMiniature (options: { ...@@ -134,7 +134,7 @@ function generateVideoMiniature (options: {
}) })
} }
function createPlaceholderThumbnail (options: { function updatePlaceholderThumbnail (options: {
fileUrl: string fileUrl: string
video: MVideoThumbnail video: MVideoThumbnail
type: ThumbnailType type: ThumbnailType
...@@ -165,11 +165,11 @@ function createPlaceholderThumbnail (options: { ...@@ -165,11 +165,11 @@ function createPlaceholderThumbnail (options: {
export { export {
generateVideoMiniature, generateVideoMiniature,
createVideoMiniatureFromUrl, updateVideoMiniatureFromUrl,
createVideoMiniatureFromExisting, updateVideoMiniatureFromExisting,
createPlaceholderThumbnail, updatePlaceholderThumbnail,
createPlaylistMiniatureFromUrl, updatePlaylistMiniatureFromUrl,
createPlaylistMiniatureFromExisting updatePlaylistMiniatureFromExisting
} }
function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) { function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) {
...@@ -231,7 +231,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si ...@@ -231,7 +231,7 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si
return undefined return undefined
} }
async function createThumbnailFromFunction (parameters: { async function updateThumbnailFromFunction (parameters: {
thumbnailCreator: () => Promise<any> thumbnailCreator: () => Promise<any>
filename: string filename: string
height: number height: number
......
...@@ -10,7 +10,7 @@ import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } fro ...@@ -10,7 +10,7 @@ import { ThumbnailType, VideoCreate, VideoPrivacy, VideoTranscodingPayload } fro
import { federateVideoIfNeeded } from './activitypub/videos' import { federateVideoIfNeeded } from './activitypub/videos'
import { JobQueue } from './job-queue/job-queue' import { JobQueue } from './job-queue/job-queue'
import { Notifier } from './notifier' import { Notifier } from './notifier'
import { createVideoMiniatureFromExisting } from './thumbnail' import { updateVideoMiniatureFromExisting } from './thumbnail'
function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> { function buildLocalVideoFromReq (videoInfo: VideoCreate, channelId: number): FilteredModelAttributes<VideoModel> {
return { return {
...@@ -54,7 +54,7 @@ async function buildVideoThumbnailsFromReq (options: { ...@@ -54,7 +54,7 @@ async function buildVideoThumbnailsFromReq (options: {
const fields = files?.[p.fieldName] const fields = files?.[p.fieldName]
if (fields) { if (fields) {
return createVideoMiniatureFromExisting({ return updateVideoMiniatureFromExisting({
inputPath: fields[0].path, inputPath: fields[0].path,
video, video,
type: p.type, type: p.type,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment