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>
This commit is contained in:
parent
bafef1f8b4
commit
dabf1867fd
|
@ -225,20 +225,37 @@ export class ApPersonService implements OnModuleInit {
|
||||||
return null;
|
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 => {
|
const [avatar, banner] = await Promise.all([icon, image].map(img => {
|
||||||
if (img == null) return null;
|
// if we have an explicitly missing image, return an
|
||||||
if (user == null) throw new Error('failed to create user: user is null');
|
// 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);
|
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 {
|
return {
|
||||||
avatarId: avatar?.id ?? null,
|
...( avatar ? {
|
||||||
bannerId: banner?.id ?? null,
|
avatarId: avatar.id,
|
||||||
avatarUrl: avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null,
|
avatarUrl: avatar.url ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null,
|
||||||
bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
avatarBlurhash: avatar.blurhash,
|
||||||
avatarBlurhash: avatar?.blurhash ?? null,
|
} : {}),
|
||||||
bannerBlurhash: banner?.blurhash ?? null,
|
...( banner ? {
|
||||||
|
bannerId: banner.id,
|
||||||
|
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner) : null,
|
||||||
|
bannerBlurhash: banner.blurhash,
|
||||||
|
} : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2024.2.0-beta.8
|
* version: 2024.2.0-beta.8
|
||||||
* generatedAt: 2024-02-02T14:18:15.716Z
|
* generatedAt: 2024-02-04T11:51:13.598Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { SwitchCaseResponseType } from '../api.js';
|
import type { SwitchCaseResponseType } from '../api.js';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2024.2.0-beta.8
|
* version: 2024.2.0-beta.8
|
||||||
* generatedAt: 2024-02-02T14:18:15.712Z
|
* generatedAt: 2024-02-04T11:51:13.595Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2024.2.0-beta.8
|
* version: 2024.2.0-beta.8
|
||||||
* generatedAt: 2024-02-02T14:18:15.709Z
|
* generatedAt: 2024-02-04T11:51:13.593Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { operations } from './types.js';
|
import { operations } from './types.js';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2024.2.0-beta.8
|
* version: 2024.2.0-beta.8
|
||||||
* generatedAt: 2024-02-02T14:18:15.708Z
|
* generatedAt: 2024-02-04T11:51:13.592Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { components } from './types.js';
|
import { components } from './types.js';
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* version: 2024.2.0-beta.8
|
* version: 2024.2.0-beta.8
|
||||||
* generatedAt: 2024-02-02T14:18:15.529Z
|
* generatedAt: 2024-02-04T11:51:13.473Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue