mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Remove previous thumbnail if needed
This commit is contained in:
parent
6302d599cd
commit
a35a22797c
15 changed files with 274 additions and 119 deletions
|
@ -173,7 +173,11 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
|
|||
|
||||
const thumbnailField = req.files['thumbnailfile']
|
||||
const thumbnailModel = thumbnailField
|
||||
? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist, false)
|
||||
? await createPlaylistMiniatureFromExisting({
|
||||
inputPath: thumbnailField[0].path,
|
||||
playlist: videoPlaylist,
|
||||
automaticallyGenerated: false
|
||||
})
|
||||
: undefined
|
||||
|
||||
const videoPlaylistCreated = await sequelizeTypescript.transaction(async t => {
|
||||
|
@ -211,7 +215,11 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
|
|||
|
||||
const thumbnailField = req.files['thumbnailfile']
|
||||
const thumbnailModel = thumbnailField
|
||||
? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylistInstance, false)
|
||||
? await createPlaylistMiniatureFromExisting({
|
||||
inputPath: thumbnailField[0].path,
|
||||
playlist: videoPlaylistInstance,
|
||||
automaticallyGenerated: false
|
||||
})
|
||||
: undefined
|
||||
|
||||
try {
|
||||
|
@ -474,7 +482,12 @@ async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbn
|
|||
}
|
||||
|
||||
const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoMiniature.filename)
|
||||
const thumbnailModel = await createPlaylistMiniatureFromExisting(inputPath, videoPlaylist, true, true)
|
||||
const thumbnailModel = await createPlaylistMiniatureFromExisting({
|
||||
inputPath,
|
||||
playlist: videoPlaylist,
|
||||
automaticallyGenerated: true,
|
||||
keepOriginal: true
|
||||
})
|
||||
|
||||
thumbnailModel.videoPlaylistId = videoPlaylist.id
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr
|
|||
|
||||
async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) {
|
||||
try {
|
||||
return createVideoMiniatureFromUrl(url, video, ThumbnailType.MINIATURE)
|
||||
return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.MINIATURE })
|
||||
} catch (err) {
|
||||
logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err })
|
||||
return undefined
|
||||
|
@ -291,14 +291,14 @@ async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) {
|
|||
|
||||
async function processPreviewFromUrl (url: string, video: MVideoThumbnail) {
|
||||
try {
|
||||
return createVideoMiniatureFromUrl(url, video, ThumbnailType.PREVIEW)
|
||||
return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.PREVIEW })
|
||||
} catch (err) {
|
||||
logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err })
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function insertIntoDB (parameters: {
|
||||
async function insertIntoDB (parameters: {
|
||||
video: MVideoThumbnail
|
||||
thumbnailModel: MThumbnail
|
||||
previewModel: MThumbnail
|
||||
|
@ -309,7 +309,7 @@ function insertIntoDB (parameters: {
|
|||
}): Promise<MVideoImportFormattable> {
|
||||
const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
|
||||
|
||||
return sequelizeTypescript.transaction(async t => {
|
||||
const videoImport = await sequelizeTypescript.transaction(async t => {
|
||||
const sequelizeOptions = { transaction: t }
|
||||
|
||||
// Save video object in database
|
||||
|
@ -339,4 +339,6 @@ function insertIntoDB (parameters: {
|
|||
|
||||
return videoImport
|
||||
})
|
||||
|
||||
return videoImport
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ async function addVideo (req: express.Request, res: express.Response) {
|
|||
const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({
|
||||
video,
|
||||
files: req.files,
|
||||
fallback: type => generateVideoMiniature(video, videoFile, type)
|
||||
fallback: type => generateVideoMiniature({ video, videoFile, type })
|
||||
})
|
||||
|
||||
// Create the torrent file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue