Skip to content

Commit cf85134

Browse files
committed
Add frontend, beginning of GH API implementation (wip, borked)
1 parent df93ca1 commit cf85134

File tree

5 files changed

+139
-1
lines changed

5 files changed

+139
-1
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System.Net.Mime;
2+
using System.Text;
3+
using Serilog;
4+
5+
namespace ReplayBrowser.Helpers;
6+
7+
public class GitHubApiHelper
8+
{
9+
public GitHubAccount[] Contributors;
10+
private string APIToken;
11+
12+
public GitHubApiHelper(IConfiguration configuration)
13+
{
14+
try
15+
{
16+
APIToken = configuration.GetSection("GitHubAPIToken").ToString();
17+
}
18+
catch (Exception e)
19+
{
20+
Log.Error("GitHubAPIToken not set, contributors cannot be fetched.");
21+
}
22+
}
23+
24+
public async Task<GitHubAccount[]> GetContributors()
25+
{
26+
try
27+
{
28+
/*
29+
var client = new HttpClient();
30+
31+
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json");
32+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {APIToken}");
33+
client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28");
34+
35+
var request = new HttpRequestMessage
36+
{
37+
Method = HttpMethod.Get,
38+
RequestUri = new Uri("https://api.github.com/repos/Simyon264/ReplayBrowser/contributors")
39+
};
40+
*/
41+
42+
using (var httpClient = new HttpClient())
43+
{
44+
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.github.com/repos/Simyon264/ReplayBrowser/contributors"))
45+
{
46+
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.github+json");
47+
request.Headers.TryAddWithoutValidation("Authorization", $"Bearer {APIToken}");
48+
request.Headers.TryAddWithoutValidation("X-GitHub-Api-Version", "2022-11-28");
49+
50+
var response = await httpClient.SendAsync(request);
51+
52+
Log.Debug(response.ToString());
53+
response.EnsureSuccessStatusCode();
54+
55+
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
56+
Log.Information(responseBody);
57+
58+
return []; // where is my debug
59+
}
60+
}
61+
62+
//var response = await client.SendAsync(request).ConfigureAwait(false);
63+
64+
}
65+
catch (Exception e)
66+
{
67+
Log.Information($"Exception when querying GitHub: {e.Message}");
68+
return [];
69+
}
70+
}
71+
}
72+
73+
public struct GitHubAccount
74+
{
75+
private string AccountName;
76+
private string AccountImageURL;
77+
private string AccountLink;
78+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@page "/contributors"
2+
3+
@inject GitHubApiHelper GitHubApiHelper
4+
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using ReplayBrowser.Pages.Shared
7+
@using ReplayBrowser.Helpers
8+
9+
<PageTitle>Contributors</PageTitle>
10+
11+
<h3>Contributors</h3>
12+
13+
@foreach (var contrib in _contributors)
14+
{
15+
<ContributorCard ContributorName="" />
16+
}
17+
18+
19+
20+
@code {
21+
private GitHubAccount[]? _contributors = [];
22+
23+
protected async override Task OnInitializedAsync()
24+
{
25+
_contributors = await GitHubApiHelper.GetContributors();
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="card"
2+
style="display: flex; flex-direction: column; align-items: center; justify-content: center; width: 200px;">
3+
<div class="card-title">
4+
<br /><h4>@ContributorName</h4>
5+
</div>
6+
7+
<div>
8+
<div>
9+
<img src="@ContributorImage"
10+
style="width: 50px; height: 50px; border-radius: 100px; transform: translateX(calc(25.8px / 2))"
11+
alt="Profile Picture of the Contributor"
12+
/>
13+
</div>
14+
15+
<br />
16+
17+
<a href="@ContributorLink" class="btn btn-primary"
18+
style="margin-bottom: 25px">
19+
GitHub
20+
</a>
21+
</div>
22+
</div>
23+
24+
25+
@code {
26+
[Parameter] public required string ContributorName { get; set; }
27+
[Parameter] public required string ContributorImage { get; set; }
28+
[Parameter] public required string ContributorLink { get; set; }
29+
30+
31+
32+
}

ReplayBrowser/Pages/Shared/MainLayout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
<footer class="footer text-muted text-center">
111111
<div class="container">
112-
<p>Replay Browser is a project by Simyon, YuNii and Saphire. Source code available on <a href="https://github.com/Simyon264/ReplayBrowser">GitHub</a>.</p>
112+
<p>Replay Browser is a project by Simyon and <a href="/contributors">contributors</a>. Source code available on <a href="https://github.com/Simyon264/ReplayBrowser">GitHub</a>.</p>
113113
</div>
114114

115115
<div class="container">

ReplayBrowser/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void ConfigureServices(IServiceCollection services)
8585
services.AddSingleton<ReplayParserService>();
8686
services.AddSingleton<AnalyticsService>();
8787
services.AddSingleton<NoticeHelper>();
88+
services.AddSingleton<GitHubApiHelper>();
8889

8990
services.AddHostedService<BackgroundServiceStarter<ReplayParserService>>();
9091
services.AddHostedService<BackgroundServiceStarter<AccountService>>();

0 commit comments

Comments
 (0)