diff options
| author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2024-02-04 12:03:49 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-04 21:03:49 +0900 |
| commit | dabf1867fd5619d82b860482ffaf7908a4b9f0df (patch) | |
| tree | e51e1ebfe2b868d0dfe14533e21ce09e2fc70bab /packages/backend/src | |
| parent | ignore `instance.actor` when checking if there are local users (#13146) (diff) | |
| download | misskey-dabf1867fd5619d82b860482ffaf7908a4b9f0df.tar.gz misskey-dabf1867fd5619d82b860482ffaf7908a4b9f0df.tar.bz2 misskey-dabf1867fd5619d82b860482ffaf7908a4b9f0df.zip | |
keep cached avatar&banner when refresh fails to get new values (#13145)
* keep cached avatar&banner when refresh fails to get new values
when the remote explicitly tells us a user image is gone, we remove
our cached value, but if we fail to get the image, we keep whatever
value we already have
this should minimise the problem of avatars randomly disappearing
* autogen bits
* pnpm run build-misskey-js-with-types
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Diffstat (limited to 'packages/backend/src')
| -rw-r--r-- | packages/backend/src/core/activitypub/models/ApPersonService.ts | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index bf38d5fd60..aec34aeb54 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -225,20 +225,37 @@ export class ApPersonService implements OnModuleInit { return null; } - private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any): Promise<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'avatarUrl' | 'bannerUrl' | 'avatarBlurhash' | 'bannerBlurhash'>> { + private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any): Promise<Partial<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'avatarUrl' | 'bannerUrl' | 'avatarBlurhash' | 'bannerBlurhash'>>> { + if (user == null) throw new Error('failed to create user: user is null'); + const [avatar, banner] = await Promise.all([icon, image].map(img => { - if (img == null) return null; - if (user == null) throw new Error('failed to create user: user is null'); + // if we have an explicitly missing image, return an + // explicitly-null set of values + if ((img == null) || (typeof img === 'object' && img.url == null)) { + return { id: null, url: null, blurhash: null }; + } + return this.apImageService.resolveImage(user, img).catch(() => null); })); + /* + we don't want to return nulls on errors! if the database fields + are already null, nothing changes; if the database has old + values, we should keep those. The exception is if the remote has + actually removed the images: in that case, the block above + returns the special {id:null}&c value, and we return those + */ return { - avatarId: avatar?.id ?? null, - bannerId: banner?.id ?? null, - avatarUrl: avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null, - bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner) : null, - avatarBlurhash: avatar?.blurhash ?? null, - bannerBlurhash: banner?.blurhash ?? null, + ...( avatar ? { + avatarId: avatar.id, + avatarUrl: avatar.url ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null, + avatarBlurhash: avatar.blurhash, + } : {}), + ...( banner ? { + bannerId: banner.id, + bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner) : null, + bannerBlurhash: banner.blurhash, + } : {}), }; } |