diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-01 08:50:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-01 13:37:40 +0100 |
commit | 7bde625050cb661f51db20992f9f3912a582fcee (patch) | |
tree | 974bbb37e4e435dd5df0fbd1253ed300c12b85db /scripts/migrations/peertube-4.2.ts | |
parent | 8d07888728bc5aabc7d0cd6211bc49fc45fd0353 (diff) | |
download | PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.tar.gz PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.tar.zst PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.zip |
Fill width of local avatars
Diffstat (limited to 'scripts/migrations/peertube-4.2.ts')
-rw-r--r-- | scripts/migrations/peertube-4.2.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/scripts/migrations/peertube-4.2.ts b/scripts/migrations/peertube-4.2.ts index 045c3e511..22f9ff9f0 100644 --- a/scripts/migrations/peertube-4.2.ts +++ b/scripts/migrations/peertube-4.2.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { minBy } from 'lodash' | 1 | import { minBy } from 'lodash' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { processImage } from '@server/helpers/image-utils' | 3 | import { getImageSize, processImage } from '@server/helpers/image-utils' |
4 | import { CONFIG } from '@server/initializers/config' | 4 | import { CONFIG } from '@server/initializers/config' |
5 | import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' | 5 | import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' |
6 | import { updateActorImages } from '@server/lib/activitypub/actors' | 6 | import { updateActorImages } from '@server/lib/activitypub/actors' |
@@ -51,6 +51,7 @@ async function run () { | |||
51 | 51 | ||
52 | for (const account of accounts) { | 52 | for (const account of accounts) { |
53 | try { | 53 | try { |
54 | await fillAvatarSizeIfNeeded(account) | ||
54 | await generateSmallerAvatarIfNeeded(account) | 55 | await generateSmallerAvatarIfNeeded(account) |
55 | } catch (err) { | 56 | } catch (err) { |
56 | console.error(`Cannot process account avatar ${account.name}`, err) | 57 | console.error(`Cannot process account avatar ${account.name}`, err) |
@@ -68,6 +69,22 @@ async function run () { | |||
68 | console.log('Generation finished!') | 69 | console.log('Generation finished!') |
69 | } | 70 | } |
70 | 71 | ||
72 | async function fillAvatarSizeIfNeeded (accountOrChannel: MAccountDefault | MChannelDefault) { | ||
73 | const avatars = accountOrChannel.Actor.Avatars | ||
74 | |||
75 | for (const avatar of avatars) { | ||
76 | if (avatar.width && avatar.height) continue | ||
77 | |||
78 | console.log('Filling size of avatars of %s.', accountOrChannel.name) | ||
79 | |||
80 | const { width, height } = await getImageSize(join(CONFIG.STORAGE.ACTOR_IMAGES, avatar.filename)) | ||
81 | avatar.width = width | ||
82 | avatar.height = height | ||
83 | |||
84 | await avatar.save() | ||
85 | } | ||
86 | } | ||
87 | |||
71 | async function generateSmallerAvatarIfNeeded (accountOrChannel: MAccountDefault | MChannelDefault) { | 88 | async function generateSmallerAvatarIfNeeded (accountOrChannel: MAccountDefault | MChannelDefault) { |
72 | const avatars = accountOrChannel.Actor.Avatars | 89 | const avatars = accountOrChannel.Actor.Avatars |
73 | if (avatars.length !== 1) { | 90 | if (avatars.length !== 1) { |