aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/migrations/peertube-4.2.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-01 08:50:28 +0100
committerChocobozzz <me@florianbigard.com>2022-03-01 13:37:40 +0100
commit7bde625050cb661f51db20992f9f3912a582fcee (patch)
tree974bbb37e4e435dd5df0fbd1253ed300c12b85db /scripts/migrations/peertube-4.2.ts
parent8d07888728bc5aabc7d0cd6211bc49fc45fd0353 (diff)
downloadPeerTube-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.ts19
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 @@
1import { minBy } from 'lodash' 1import { minBy } from 'lodash'
2import { join } from 'path' 2import { join } from 'path'
3import { processImage } from '@server/helpers/image-utils' 3import { getImageSize, processImage } from '@server/helpers/image-utils'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' 5import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
6import { updateActorImages } from '@server/lib/activitypub/actors' 6import { 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
72async 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
71async function generateSmallerAvatarIfNeeded (accountOrChannel: MAccountDefault | MChannelDefault) { 88async 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) {