Avatar: Ignore some errors when loading (#4902)

This commit is contained in:
zubiden 2024-08-29 15:53:00 +02:00 committed by Alexander Zinchuk
parent 877521617e
commit e5daa2dc20
2 changed files with 18 additions and 37 deletions

View File

@ -337,6 +337,14 @@ export async function downloadMedia(
}
}
if (err.message === 'FILE_ID_INVALID' && args.url.includes('avatar')) {
if (DEBUG) {
// eslint-disable-next-line no-console
console.warn('Inaccessible avatar image', args.url);
}
return undefined;
}
if (DEBUG) {
// eslint-disable-next-line no-console
console.error('Failed to download media', args.url, err);

View File

@ -702,45 +702,18 @@ class TelegramClient {
}
downloadProfilePhoto(entity, isBig = false) {
// ('User', 'Chat', 'UserFull', 'ChatFull')
const ENTITIES = [0x2da17977, 0xc5af5d94, 0x1f4661b9, 0xd49a2697];
// ('InputPeer', 'InputUser', 'InputChannel')
// const INPUTS = [0xc91c90b6, 0xe669bf46, 0x40f202fd]
// Todo account for input methods
const sizeType = isBig ? 'x' : 'm';
let photo;
if (!(ENTITIES.includes(entity.SUBCLASS_OF_ID))) {
photo = entity;
} else {
if (!entity.photo) {
// Special case: may be a ChatFull with photo:Photo
if (!entity.chatPhoto) {
return undefined;
}
const photo = entity.photo;
return this._downloadPhoto(
entity.chatPhoto, { sizeType },
);
}
photo = entity.photo;
}
if (!(photo instanceof constructors.UserProfilePhoto
|| photo instanceof constructors.ChatPhoto)) return undefined;
const dcId = photo.dcId;
const loc = new constructors.InputPeerPhotoFileLocation({
peer: utils.getInputPeer(entity),
photoId: photo.photoId,
big: isBig,
});
let dcId;
let loc;
if (photo instanceof constructors.UserProfilePhoto || photo instanceof constructors.ChatPhoto) {
dcId = photo.dcId;
loc = new constructors.InputPeerPhotoFileLocation({
peer: utils.getInputPeer(entity),
photoId: photo.photoId,
big: isBig,
});
} else {
// It doesn't make any sense to check if `photo` can be used
// as input location, because then this method would be able
// to "download the profile photo of a message", i.e. its
// media which should be done with `download_media` instead.
return undefined;
}
return this.downloadFile(loc, {
dcId,
});