fix(bot): show error message when content-type header is missing from avatar url response
This commit is contained in:
parent
2fe83fc18c
commit
3129f05b0f
@ -23,6 +23,9 @@ public static class AvatarUtils
|
|||||||
if (!PluralKit.Core.MiscUtils.TryMatchUri(url, out var uri))
|
if (!PluralKit.Core.MiscUtils.TryMatchUri(url, out var uri))
|
||||||
throw Errors.InvalidUrl;
|
throw Errors.InvalidUrl;
|
||||||
|
|
||||||
|
if (uri.Host.Contains("toyhou.se"))
|
||||||
|
throw new PKError("Due to server issues, PluralKit is unable to read images hosted on toyhou.se.");
|
||||||
|
|
||||||
url = TryRewriteCdnUrl(url);
|
url = TryRewriteCdnUrl(url);
|
||||||
|
|
||||||
var response = await client.GetAsync(url);
|
var response = await client.GetAsync(url);
|
||||||
@ -30,8 +33,16 @@ public static class AvatarUtils
|
|||||||
throw Errors.AvatarServerError(response.StatusCode);
|
throw Errors.AvatarServerError(response.StatusCode);
|
||||||
if (response.Content.Headers.ContentLength == null) // Check presence of content length
|
if (response.Content.Headers.ContentLength == null) // Check presence of content length
|
||||||
throw Errors.AvatarNotAnImage(null);
|
throw Errors.AvatarNotAnImage(null);
|
||||||
if (!acceptableMimeTypes.Contains(response.Content.Headers.ContentType.MediaType)) // Check MIME type
|
try
|
||||||
throw Errors.AvatarNotAnImage(response.Content.Headers.ContentType.MediaType);
|
{
|
||||||
|
if (!acceptableMimeTypes.Contains(response.Content.Headers.ContentType.MediaType)) // Check MIME type
|
||||||
|
throw Errors.AvatarNotAnImage(response.Content.Headers.ContentType.MediaType);
|
||||||
|
}
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{
|
||||||
|
throw new PKError("Could not verify avatar is an image. This can happen when the server sends a malformed response."
|
||||||
|
+ "\nPlease join the support server for help: <https://discord.gg/PczBt78>");
|
||||||
|
}
|
||||||
|
|
||||||
if (isFullSizeImage)
|
if (isFullSizeImage)
|
||||||
// no need to do size checking on banners
|
// no need to do size checking on banners
|
||||||
|
Loading…
Reference in New Issue
Block a user