diff options
Diffstat (limited to 'scripts/regenerate-thumbnails.ts')
-rw-r--r-- | scripts/regenerate-thumbnails.ts | 25 |
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 | ||
4 | import * as Bluebird from 'bluebird' | 4 | import * as Bluebird from 'bluebird' |
5 | import * as program from 'commander' | 5 | import * as program from 'commander' |
6 | import { pathExists } from 'fs-extra' | 6 | import { pathExists, remove } from 'fs-extra' |
7 | import { processImage } from '@server/helpers/image-utils' | 7 | import { processImage } from '@server/helpers/image-utils' |
8 | import { THUMBNAILS_SIZE } from '@server/initializers/constants' | 8 | import { THUMBNAILS_SIZE } from '@server/initializers/constants' |
9 | import { VideoModel } from '@server/models/video/video' | 9 | import { VideoModel } from '@server/models/video/video' |
10 | import { MVideo } from '@server/types/models' | 10 | import { MVideo } from '@server/types/models' |
11 | import { initDatabaseModels } from '@server/initializers/database' | 11 | import { initDatabaseModels } from '@server/initializers/database' |
12 | import { ActorImageModel } from '@server/models/account/actor-image' | ||
12 | 13 | ||
13 | program | 14 | program |
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 | } |