mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 14:57:54 +00:00
fix(bot): avoid 403 status codes on image upload (#611)
This commit is contained in:
parent
823db4cd24
commit
8befb1c857
7 changed files with 36 additions and 18 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue