Refactor more

This commit is contained in:
Alexey Golub
2020-04-22 21:59:10 +03:00
parent dc79813ad7
commit 88a4fa792b
26 changed files with 117 additions and 99 deletions

View File

@@ -3,6 +3,7 @@ using System.Drawing;
using System.Linq;
using System.Text.Json;
using DiscordChatExporter.Domain.Discord.Models;
using DiscordChatExporter.Domain.Discord.Models.Common;
using DiscordChatExporter.Domain.Internal;
using Tyrrrz.Extensions;

View File

@@ -23,8 +23,6 @@ namespace DiscordChatExporter.Domain.Discord
_token = token;
_httpClient = httpClient;
_httpClient.BaseAddress = new Uri("https://discordapp.com/api/v6");
// Discord seems to always respond with 429 on the first request with unreasonable wait time (10+ minutes).
// For that reason the policy will start respecting their retry-after header only after Nth failed response.
_httpRequestPolicy = Policy
@@ -53,7 +51,9 @@ namespace DiscordChatExporter.Domain.Discord
{
using var response = await _httpRequestPolicy.ExecuteAsync(async () =>
{
using var request = new HttpRequestMessage(HttpMethod.Get, url);
var uri = new Uri(new Uri("https://discordapp.com/api/v6"), url);
using var request = new HttpRequestMessage(HttpMethod.Get, uri);
request.Headers.Authorization = _token.GetAuthenticationHeader();
return await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using DiscordChatExporter.Domain.Discord.Models.Common;
namespace DiscordChatExporter.Domain.Discord.Models
{

View File

@@ -1,4 +1,6 @@
namespace DiscordChatExporter.Domain.Discord.Models
using DiscordChatExporter.Domain.Discord.Models.Common;
namespace DiscordChatExporter.Domain.Discord.Models
{
// https://discordapp.com/developers/docs/resources/channel#channel-object-channel-types
// Order of enum fields needs to match the order in the docs.

View File

@@ -1,6 +1,6 @@
using System;
namespace DiscordChatExporter.Domain.Discord.Models
namespace DiscordChatExporter.Domain.Discord.Models.Common
{
// Loosely based on https://github.com/omar/ByteSize (MIT license)

View File

@@ -1,4 +1,4 @@
namespace DiscordChatExporter.Domain.Discord.Models
namespace DiscordChatExporter.Domain.Discord.Models.Common
{
public interface IHasId
{

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace DiscordChatExporter.Domain.Discord.Models
namespace DiscordChatExporter.Domain.Discord.Models.Common
{
public partial class IdBasedEqualityComparer : IEqualityComparer<IHasId>
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiscordChatExporter.Domain.Discord.Models.Common;
using DiscordChatExporter.Domain.Internal;
namespace DiscordChatExporter.Domain.Discord.Models

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiscordChatExporter.Domain.Discord.Models.Common;
namespace DiscordChatExporter.Domain.Discord.Models
{

View File

@@ -1,4 +1,5 @@
using System.Drawing;
using DiscordChatExporter.Domain.Discord.Models.Common;
namespace DiscordChatExporter.Domain.Discord.Models
{

View File

@@ -1,4 +1,5 @@
using System;
using DiscordChatExporter.Domain.Discord.Models.Common;
namespace DiscordChatExporter.Domain.Discord.Models
{