public static async Task SyncAvatarAsync(IDiscordUser user) { PutObjectRequest request = new PutObjectRequest(); request.BucketName = "miki-cdn"; request.Key = $"avatars/{user.Id}.png"; request.ContentType = "image/png"; request.CannedACL = new S3CannedACL("public-read"); string avatarUrl = user.GetAvatarUrl(); using (var client = new Rest.RestClient(avatarUrl, true)) { request.InputStream = await client.GetStreamAsync(); } var response = await Global.CdnClient.PutObjectAsync(request); if (response.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new AvatarSyncException(); } await MikiApp.Instance.GetService <BunnyCDNClient>() .PurgeCacheAsync($"https://mikido.b-cdn.net/avatars/{user.Id}.png"); using (var context = new MikiContext()) { User u = await User.GetAsync(context, user.Id, user.Username); u.AvatarUrl = u.Id.ToString(); await context.SaveChangesAsync(); } }
public static async Task SyncAvatarAsync(IDiscordUser user) { PutObjectRequest request = new PutObjectRequest(); request.BucketName = "miki-cdn"; request.Key = $"avatars/{user.Id}.png"; request.ContentType = "image/png"; request.CannedACL = new S3CannedACL("public-read"); string avatarUrl = user.GetAvatarUrl(); using (var client = new Rest.RestClient(avatarUrl, true)) { request.InputStream = await client.GetStreamAsync(); } var response = await Global.CdnClient.PutObjectAsync(request); if (response.HttpStatusCode != System.Net.HttpStatusCode.OK) { throw new AvatarSyncException(); } using (var context = new MikiContext()) { User u = await User.GetAsync(context, user); u.HeaderUrl = u.Id.ToString(); await context.SaveChangesAsync(); } await Global.RedisClient.UpsertAsync($"avatar:{user.Id}:synced", true); }