fix(bot): avoid 403 status codes on image upload (#611)

This commit is contained in:
Jake Fulmine 2024-02-09 04:38:17 +01:00 committed by GitHub
parent 823db4cd24
commit 8befb1c857
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 18 deletions

View file

@ -33,11 +33,14 @@ public static class ContextAvatarExt
// If we have an attachment, use that
if (ctx.Message.Attachments.FirstOrDefault() is { } attachment)
{
// XXX: strip query params from attachment URLs because of new Discord CDN shenanigans
// XXX: discord attachment URLs are unable to be validated without their query params
// keep both the URL with query (for validation) and the clean URL (for storage) around
var uriBuilder = new UriBuilder(attachment.ProxyUrl);
uriBuilder.Query = "";
return new ParsedImage { Url = uriBuilder.Uri.AbsoluteUri, Source = AvatarSource.Attachment };
ParsedImage img = new ParsedImage { Url = uriBuilder.Uri.AbsoluteUri, Source = AvatarSource.Attachment };
uriBuilder.Query = "";
img.CleanUrl = uriBuilder.Uri.AbsoluteUri;
return img;
}
// We should only get here if there are no arguments (which would get parsed as URL + throw if error)
@ -49,6 +52,7 @@ public static class ContextAvatarExt
public struct ParsedImage
{
public string Url;
public string? CleanUrl;
public AvatarSource Source;
public User? SourceUser;
}