forked from sim0n00ps/OF-DL
Compare commits
13 Commits
7e0fdb3ebf
...
b9591ab156
| Author | SHA1 | Date | |
|---|---|---|---|
| b9591ab156 | |||
| c87958f248 | |||
| cbaf108849 | |||
| 021e70cd09 | |||
| ea3346c454 | |||
| 161faac8a5 | |||
| fa01fbd2d4 | |||
| 45920ce3f4 | |||
| 5a44c082fb | |||
| 2fb90e1f34 | |||
| 5157b5dde1 | |||
| 28388257f8 | |||
| 60e74a130d |
@ -52,6 +52,29 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task SortBlockedAsync(string endpoint, string order = "recent", string direction = "desc")
|
||||
{
|
||||
Log.Debug($"Calling SortBlocked - {endpoint}");
|
||||
|
||||
try
|
||||
{
|
||||
var reqBody = new { order, direction };
|
||||
var result = new { success = false, canAddFriends = false };
|
||||
|
||||
string? body = await BuildHeaderAndExecuteRequests([], endpoint, GetHttpClient(), HttpMethod.Post, reqBody);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
result = JsonConvert.DeserializeAnonymousType(body, result);
|
||||
|
||||
if (result?.success != true)
|
||||
_eventHandler.OnMessage($"Failed to sort blocked (order: {order}, direction; {direction})! Endpoint: {endpoint}", "yellow");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionLoggerHelper.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount)
|
||||
{
|
||||
Dictionary<string, long> usersOfType = await _eventHandler.WithStatusAsync(
|
||||
|
||||
@ -6,4 +6,5 @@ public interface ICajetanApiService : IApiService
|
||||
Task<Dictionary<string, long>> GetUsersWithProgressAsync(string typeDisplay, string endpoint, string? typeParam, bool offsetByCount);
|
||||
Task<HashSet<long>> GetUsersWithUnreadMessagesAsync();
|
||||
Task MarkAsUnreadAsync(string endpoint);
|
||||
Task SortBlockedAsync(string endpoint, string order = "recent", string direction = "desc");
|
||||
}
|
||||
|
||||
@ -228,7 +228,9 @@ internal class Worker(IServiceProvider serviceProvider)
|
||||
const string OUTPUT_FILE_BLOCKED = "blocked-users.json";
|
||||
const string OUTPUT_FILE_EXPIRED = "expired-users.json";
|
||||
|
||||
await _apiService.SortBlockedAsync("/lists/blocked/sort");
|
||||
await GetUsersAsync("Blocked", "/users/blocked", OUTPUT_FILE_BLOCKED);
|
||||
|
||||
await GetUsersAsync("Expired", "/subscriptions/subscribes", OUTPUT_FILE_EXPIRED, typeParam: "expired", offsetByCount: false);
|
||||
|
||||
async Task GetUsersAsync(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)
|
||||
|
||||
@ -2773,11 +2773,11 @@ public class ApiService(IAuthService authService, IConfigService configService,
|
||||
|
||||
|
||||
protected async Task<string?> BuildHeaderAndExecuteRequests(Dictionary<string, string> getParams, string endpoint,
|
||||
HttpClient client, HttpMethod? method = null)
|
||||
HttpClient client, HttpMethod? method = null, object? reqBody = null)
|
||||
{
|
||||
Log.Debug("Calling BuildHeaderAndExecuteRequests");
|
||||
|
||||
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method);
|
||||
HttpRequestMessage request = await BuildHttpRequestMessage(getParams, endpoint, method, reqBody);
|
||||
using HttpResponseMessage response = await client.SendAsync(request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
@ -2789,7 +2789,7 @@ public class ApiService(IAuthService authService, IConfigService configService,
|
||||
|
||||
|
||||
protected Task<HttpRequestMessage> BuildHttpRequestMessage(Dictionary<string, string> getParams,
|
||||
string endpoint, HttpMethod? method = null)
|
||||
string endpoint, HttpMethod? method = null, object? reqBody = null)
|
||||
{
|
||||
Log.Debug("Calling BuildHttpRequestMessage");
|
||||
|
||||
@ -2802,6 +2802,9 @@ public class ApiService(IAuthService authService, IConfigService configService,
|
||||
|
||||
HttpRequestMessage request = new(method ?? HttpMethod.Get, $"{Constants.ApiUrl}{endpoint}{queryParams}");
|
||||
|
||||
if ((method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch) && reqBody != null)
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(reqBody, s_mJsonSerializerSettings), Encoding.UTF8, "application/json");
|
||||
|
||||
Log.Debug($"Full request URL: {Constants.ApiUrl}{endpoint}{queryParams}");
|
||||
|
||||
foreach (KeyValuePair<string, string> keyValuePair in headers)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user