mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Support repos in authorcontrols/list
This commit is contained in:
parent
6ac8210570
commit
bfd55d3b24
@ -11,10 +11,12 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Nettle;
|
using Nettle;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
|
using Wabbajack.DTOs;
|
||||||
using Wabbajack.DTOs.GitHub;
|
using Wabbajack.DTOs.GitHub;
|
||||||
using Wabbajack.DTOs.JsonConverters;
|
using Wabbajack.DTOs.JsonConverters;
|
||||||
using Wabbajack.Networking.GitHub;
|
using Wabbajack.Networking.GitHub;
|
||||||
using Wabbajack.Paths.IO;
|
using Wabbajack.Paths.IO;
|
||||||
|
using Wabbajack.RateLimiter;
|
||||||
using Wabbajack.Server.DataModels;
|
using Wabbajack.Server.DataModels;
|
||||||
using Wabbajack.Server.Extensions;
|
using Wabbajack.Server.Extensions;
|
||||||
using Wabbajack.Server.Services;
|
using Wabbajack.Server.Services;
|
||||||
@ -32,10 +34,11 @@ public class AuthorControls : ControllerBase
|
|||||||
private readonly AppSettings _settings;
|
private readonly AppSettings _settings;
|
||||||
private readonly ILogger<AuthorControls> _logger;
|
private readonly ILogger<AuthorControls> _logger;
|
||||||
private readonly AuthorFiles _authorFiles;
|
private readonly AuthorFiles _authorFiles;
|
||||||
|
private readonly IResource<HttpClient> _limiter;
|
||||||
|
|
||||||
public AuthorControls(ILogger<AuthorControls> logger, QuickSync quickSync, HttpClient client,
|
public AuthorControls(ILogger<AuthorControls> logger, QuickSync quickSync, HttpClient client,
|
||||||
AppSettings settings, DTOSerializer dtos, AuthorFiles authorFiles,
|
AppSettings settings, DTOSerializer dtos, AuthorFiles authorFiles,
|
||||||
Client gitHubClient)
|
Client gitHubClient, IResource<HttpClient> limiter)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_quickSync = quickSync;
|
_quickSync = quickSync;
|
||||||
@ -44,6 +47,7 @@ public class AuthorControls : ControllerBase
|
|||||||
_dtos = dtos;
|
_dtos = dtos;
|
||||||
_gitHubClient = gitHubClient;
|
_gitHubClient = gitHubClient;
|
||||||
_authorFiles = authorFiles;
|
_authorFiles = authorFiles;
|
||||||
|
_limiter = limiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("login/{authorKey}")]
|
[Route("login/{authorKey}")]
|
||||||
@ -59,13 +63,37 @@ public class AuthorControls : ControllerBase
|
|||||||
public async Task<IActionResult> AuthorLists()
|
public async Task<IActionResult> AuthorLists()
|
||||||
{
|
{
|
||||||
var user = User.FindFirstValue(ClaimTypes.Name);
|
var user = User.FindFirstValue(ClaimTypes.Name);
|
||||||
List<string> lists = new();
|
var lists = (await LoadLists())
|
||||||
foreach (var file in Enum.GetValues<List>())
|
.Where(l => l.Maintainers.Contains(user))
|
||||||
lists.AddRange((await _gitHubClient.GetData(file)).Lists.Where(l => l.Maintainers.Contains(user))
|
.Select(l => l.NamespacedName)
|
||||||
.Select(lst => lst.NamespacedName));
|
.ToArray();
|
||||||
|
|
||||||
return Ok(lists);
|
return Ok(lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ModlistMetadata[]> LoadLists()
|
||||||
|
{
|
||||||
|
var repos = await LoadRepositories();
|
||||||
|
|
||||||
|
return await repos.PMapAll(async url =>
|
||||||
|
(await _client.GetFromJsonAsync<ModlistMetadata[]>(_limiter, new HttpRequestMessage(HttpMethod.Get, url.Value),
|
||||||
|
_dtos.Options))!.Select(meta =>
|
||||||
|
{
|
||||||
|
meta.RepositoryName = url.Key;
|
||||||
|
return meta;
|
||||||
|
}))
|
||||||
|
.SelectMany(x => x)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<string, Uri>> LoadRepositories()
|
||||||
|
{
|
||||||
|
var repositories = await _client.GetFromJsonAsync<Dictionary<string, Uri>>(_limiter,
|
||||||
|
new HttpRequestMessage(HttpMethod.Get,
|
||||||
|
"https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/repositories.json"), _dtos.Options);
|
||||||
|
return repositories!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Route("lists/download_metadata")]
|
[Route("lists/download_metadata")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@ -29,6 +29,8 @@ using Wabbajack.Server.DataModels;
|
|||||||
using Wabbajack.Server.Extensions;
|
using Wabbajack.Server.Extensions;
|
||||||
using Wabbajack.Server.Services;
|
using Wabbajack.Server.Services;
|
||||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||||
|
using Wabbajack.Networking.WabbajackClientApi;
|
||||||
|
using Client = Wabbajack.Networking.GitHub.Client;
|
||||||
|
|
||||||
namespace Wabbajack.Server;
|
namespace Wabbajack.Server;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user