aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/regenerate-thumbnails.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-08 10:35:49 +0200
committerChocobozzz <me@florianbigard.com>2021-04-08 13:38:04 +0200
commita0eeb45f14bab539f505861cad8f5d42d9ba30cb (patch)
tree773eb5aa575c8ab870b9c84f686e6062aa58d9fd /scripts/regenerate-thumbnails.ts
parentca873292899c9a822a236556993916d98da14913 (diff)
downloadPeerTube-a0eeb45f14bab539f505861cad8f5d42d9ba30cb.tar.gz
PeerTube-a0eeb45f14bab539f505861cad8f5d42d9ba30cb.tar.zst
PeerTube-a0eeb45f14bab539f505861cad8f5d42d9ba30cb.zip
Update data in DB when regenerate thumbnails
Diffstat (limited to 'scripts/regenerate-thumbnails.ts')
-rw-r--r--scripts/regenerate-thumbnails.ts25
1 files changed, 19 insertions, 6 deletions
diff --git a/scripts/regenerate-thumbnails.ts b/scripts/regenerate-thumbnails.ts
index 04c6e2b74..0213b8a22 100644
--- a/scripts/regenerate-thumbnails.ts
+++ b/scripts/regenerate-thumbnails.ts
@@ -3,12 +3,13 @@ registerTSPaths()
3 3
4import * as Bluebird from 'bluebird' 4import * as Bluebird from 'bluebird'
5import * as program from 'commander' 5import * as program from 'commander'
6import { pathExists } from 'fs-extra' 6import { pathExists, remove } from 'fs-extra'
7import { processImage } from '@server/helpers/image-utils' 7import { processImage } from '@server/helpers/image-utils'
8import { THUMBNAILS_SIZE } from '@server/initializers/constants' 8import { THUMBNAILS_SIZE } from '@server/initializers/constants'
9import { VideoModel } from '@server/models/video/video' 9import { VideoModel } from '@server/models/video/video'
10import { MVideo } from '@server/types/models' 10import { MVideo } from '@server/types/models'
11import { initDatabaseModels } from '@server/initializers/database' 11import { initDatabaseModels } from '@server/initializers/database'
12import { ActorImageModel } from '@server/models/account/actor-image'
12 13
13program 14program
14 .description('Regenerate local thumbnails using preview files') 15 .description('Regenerate local thumbnails using preview files')
@@ -37,13 +38,8 @@ async function processVideo (videoArg: MVideo) {
37 const thumbnail = video.getMiniature() 38 const thumbnail = video.getMiniature()
38 const preview = video.getPreview() 39 const preview = video.getPreview()
39 40
40 const thumbnailPath = thumbnail.getPath()
41 const previewPath = preview.getPath() 41 const previewPath = preview.getPath()
42 42
43 if (!await pathExists(thumbnailPath)) {
44 throw new Error(`Thumbnail ${thumbnailPath} does not exist on disk`)
45 }
46
47 if (!await pathExists(previewPath)) { 43 if (!await pathExists(previewPath)) {
48 throw new Error(`Preview ${previewPath} does not exist on disk`) 44 throw new Error(`Preview ${previewPath} does not exist on disk`)
49 } 45 }
@@ -52,5 +48,22 @@ async function processVideo (videoArg: MVideo) {
52 width: THUMBNAILS_SIZE.width, 48 width: THUMBNAILS_SIZE.width,
53 height: THUMBNAILS_SIZE.height 49 height: THUMBNAILS_SIZE.height
54 } 50 }
51
52 const oldPath = thumbnail.getPath()
53
54 // Update thumbnail
55 thumbnail.filename = ActorImageModel.generateFilename()
56 thumbnail.width = size.width
57 thumbnail.height = size.height
58
59 const thumbnailPath = thumbnail.getPath()
55 await processImage(previewPath, thumbnailPath, size, true) 60 await processImage(previewPath, thumbnailPath, size, true)
61
62 // Save new attributes
63 await thumbnail.save()
64
65 // Remove old thumbnail
66 await remove(oldPath)
67
68 // Don't federate, remote instances will refresh the thumbnails after a while
56} 69}