mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 00:07:55 +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
|
|
@ -70,14 +70,18 @@ public class Member
|
|||
if (avatarArg != null)
|
||||
try
|
||||
{
|
||||
// XXX: strip query params from attachment URLs because of new Discord CDN shenanigans
|
||||
var uriBuilder = new UriBuilder(avatarArg.Url);
|
||||
// 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(avatarArg.ProxyUrl);
|
||||
ParsedImage img = new ParsedImage { Url = uriBuilder.Uri.AbsoluteUri, Source = AvatarSource.Attachment };
|
||||
|
||||
uriBuilder.Query = "";
|
||||
img.CleanUrl = uriBuilder.Uri.AbsoluteUri;
|
||||
|
||||
await AvatarUtils.VerifyAvatarOrThrow(_client, uriBuilder.Uri.AbsoluteUri);
|
||||
await ctx.Repository.UpdateMember(member.Id, new MemberPatch { AvatarUrl = uriBuilder.Uri.AbsoluteUri }, conn);
|
||||
await AvatarUtils.VerifyAvatarOrThrow(_client, img.Url);
|
||||
await ctx.Repository.UpdateMember(member.Id, new MemberPatch { AvatarUrl = img.CleanUrl ?? img.Url }, conn);
|
||||
|
||||
dispatchData.Add("avatar_url", avatarArg.Url);
|
||||
dispatchData.Add("avatar_url", img.CleanUrl);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue