persist contributor snapshots to DataDir
This commit is contained in:
parent
d9ce7c0fa3
commit
7da482f5ad
@ -8,7 +8,7 @@ public sealed class PluginBuilderOptions
|
||||
public string? DebugLogFile { get; init; }
|
||||
public LogEventLevel? DebugLogLevel { get; init; }
|
||||
public int LogRetainCount { get; init; } = 1;
|
||||
|
||||
public string PluginDataDir => Path.Combine(DataDir, "PluginData");
|
||||
public static PluginBuilderOptions ConfigureDataDirAndDebugLog(IConfiguration conf, IHostEnvironment env)
|
||||
{
|
||||
var dataDir =
|
||||
|
||||
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PluginBuilder.APIModels;
|
||||
using PluginBuilder.Components.PluginVersion;
|
||||
using PluginBuilder.Configuration;
|
||||
using PluginBuilder.Controllers.Logic;
|
||||
using PluginBuilder.DataModels;
|
||||
using PluginBuilder.JsonConverters;
|
||||
@ -27,6 +28,7 @@ public class HomeController(
|
||||
SignInManager<IdentityUser> signInManager,
|
||||
EmailService emailService,
|
||||
UserVerifiedLogic userVerifiedLogic,
|
||||
PluginBuilderOptions options,
|
||||
ServerEnvironment env,
|
||||
NostrService nostrService,
|
||||
ILogger<HomeController> logger)
|
||||
@ -475,7 +477,7 @@ public class HomeController(
|
||||
IsOwner = userId != null && userId == primaryOwnerId,
|
||||
PluginVersions = versions.ToList(),
|
||||
ShowHiddenNotice = (int)pluginDetails.visibility == (int)PluginVisibilityEnum.Hidden,
|
||||
Contributors = GithubService.LoadSnapshot(pluginSlug),
|
||||
Contributors = GithubService.LoadSnapshot(options.PluginDataDir, pluginSlug),
|
||||
RatingFilter = model.RatingFilter,
|
||||
OwnerGithubUrl = ownerGithubUrl,
|
||||
OwnerNostrUrl = ownerNostrUrl
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
{
|
||||
"contributors": [
|
||||
{
|
||||
"login": "rockstardev",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/5191402?v=4",
|
||||
"html_url": "https://github.com/rockstardev",
|
||||
"user_view_type": null,
|
||||
"contributions": 228
|
||||
},
|
||||
{
|
||||
"login": "TChukwuleta",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/47084273?v=4",
|
||||
"html_url": "https://github.com/TChukwuleta",
|
||||
"user_view_type": null,
|
||||
"contributions": 44
|
||||
},
|
||||
{
|
||||
"login": "monicamuyama",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/107669232?v=4",
|
||||
"html_url": "https://github.com/monicamuyama",
|
||||
"user_view_type": null,
|
||||
"contributions": 4
|
||||
},
|
||||
{
|
||||
"login": "NicolasDorier",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/3020646?v=4",
|
||||
"html_url": "https://github.com/NicolasDorier",
|
||||
"user_view_type": null,
|
||||
"contributions": 4
|
||||
},
|
||||
{
|
||||
"login": "thgO-O",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/107907441?v=4",
|
||||
"html_url": "https://github.com/thgO-O",
|
||||
"user_view_type": null,
|
||||
"contributions": 1
|
||||
},
|
||||
{
|
||||
"login": "yemmyharry",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/35658364?v=4",
|
||||
"html_url": "https://github.com/yemmyharry",
|
||||
"user_view_type": null,
|
||||
"contributions": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -2,6 +2,7 @@ using System.Threading.Channels;
|
||||
using System.Xml.Linq;
|
||||
using Dapper;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PluginBuilder.Configuration;
|
||||
using PluginBuilder.DataModels;
|
||||
using PluginBuilder.Events;
|
||||
using PluginBuilder.JsonConverters;
|
||||
@ -16,9 +17,11 @@ public class BuildService
|
||||
{
|
||||
private static readonly SemaphoreSlim _semaphore = new(5);
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly PluginBuilderOptions _options;
|
||||
|
||||
public BuildService(
|
||||
ILogger<BuildService> logger,
|
||||
PluginBuilderOptions options,
|
||||
ProcessRunner processRunner,
|
||||
DBConnectionFactory connectionFactory,
|
||||
EventAggregator eventAggregator,
|
||||
@ -26,6 +29,7 @@ public class BuildService
|
||||
IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
Logger = logger;
|
||||
_options = options;
|
||||
ProcessRunner = processRunner;
|
||||
ConnectionFactory = connectionFactory;
|
||||
EventAggregator = eventAggregator;
|
||||
@ -187,7 +191,7 @@ public class BuildService
|
||||
{
|
||||
var githubClient = _httpClientFactory.CreateClient(HttpClientNames.GitHub);
|
||||
var contributors = await GithubService.GetContributorsAsync(githubClient, buildInfo.GitRepository, buildInfo.PluginDir);
|
||||
await GithubService.SaveSnapshotAsync(pluginSlug, contributors);
|
||||
await GithubService.SaveSnapshotAsync(_options.PluginDataDir, pluginSlug, contributors);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
@ -68,11 +68,12 @@ public static class GithubService
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SaveSnapshotAsync(PluginSlug pluginSlug, List<GitHubContributor> contributors)
|
||||
public static async Task SaveSnapshotAsync(string pluginDataDir, PluginSlug pluginSlug, List<GitHubContributor> contributors)
|
||||
{
|
||||
var dir = Path.Combine(Directory.GetCurrentDirectory(), "PluginData");
|
||||
Directory.CreateDirectory(dir);
|
||||
var filePath = Path.Combine(dir, $"{pluginSlug}.json");
|
||||
if (!Directory.Exists(pluginDataDir))
|
||||
Directory.CreateDirectory(pluginDataDir);
|
||||
|
||||
var filePath = Path.Combine(pluginDataDir, $"{pluginSlug}.json");
|
||||
var data = new JObject
|
||||
{
|
||||
["contributors"] = JArray.FromObject(contributors)
|
||||
@ -80,11 +81,14 @@ public static class GithubService
|
||||
await File.WriteAllTextAsync(filePath, data.ToString(Formatting.Indented));
|
||||
}
|
||||
|
||||
public static List<GitHubContributor> LoadSnapshot(PluginSlug pluginSlug)
|
||||
public static List<GitHubContributor> LoadSnapshot(string pluginDataDir, PluginSlug pluginSlug)
|
||||
{
|
||||
if (!Directory.Exists(pluginDataDir))
|
||||
Directory.CreateDirectory(pluginDataDir);
|
||||
|
||||
try
|
||||
{
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "PluginData", $"{pluginSlug}.json");
|
||||
var filePath = Path.Combine(pluginDataDir, $"{pluginSlug}.json");
|
||||
if (!File.Exists(filePath))
|
||||
return new List<GitHubContributor>();
|
||||
|
||||
@ -95,6 +99,7 @@ public static class GithubService
|
||||
catch (Exception)
|
||||
{
|
||||
return new();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user