Skip to content

Commit 6a86f2f

Browse files
committed
Add detail string to download page
1 parent 7694366 commit 6a86f2f

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

ReplayBrowser/Controllers/DataController.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ public DownloadProgress GetDownloadProgress()
4040
return new DownloadProgress()
4141
{
4242
Progress = ReplayParserService.DownloadProgress.ToDictionary(x => x.Key, x => x.Value),
43-
Status = ReplayParserService.Status.ToFriendlyString()
43+
Status = ReplayParserService.Status.ToFriendlyString(),
44+
Details = ReplayParserService.Details
4445
};
4546
}
4647
}
4748

4849
public class DownloadProgress
4950
{
50-
public string Status { get; set; }
51-
public Dictionary<string, double> Progress { get; set; }
51+
public required string Status { get; set; }
52+
public required Dictionary<string, double> Progress { get; set; }
53+
54+
public required string Details { get; set; }
5255
}

ReplayBrowser/Pages/Downloads.razor

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<h3>Downloads</h3>
77
<p>Here you can see the progress of the internal downloads of the website.<br/>The website looks for new replays every 10th minute. So 12:00, 12:10, 12:20, 12:30, etc.</p>
8-
<p>Status: <b id="status-text">Waiting...</b></p>
8+
<p>Status: <b id="status-text">Waiting...</b> <span id="details"></span></p>
99

1010
<table class="table table-striped">
1111
<thead>
@@ -20,20 +20,26 @@
2020
</table>
2121

2222
<script>
23-
var Downloads = [];
24-
var Status = "";
23+
let Downloads = [];
24+
let Status = "";
25+
let Details = "";
2526
26-
// Every second, fetch active downloads from the server using JQuery
2727
setInterval(() => {
28+
download();
29+
}, 500);
30+
31+
function download() {
2832
$.get('/api/Data/download-progress', (data) => {
2933
Downloads = data.progress;
3034
Status = data.status;
35+
Details = data.details;
3136
updateDownloads();
3237
});
33-
}, 1000);
38+
}
39+
3440
3541
function updateDownloads() {
36-
var downloads = document.getElementById('downloads');
42+
let downloads = document.getElementById('downloads');
3743
downloads.innerHTML = '';
3844
if (Object.keys(Downloads).length === 0) {
3945
document.getElementById('download-text-no').style.display = 'block';
@@ -42,20 +48,21 @@
4248
}
4349
4450
document.getElementById('status-text').innerText = Status;
51+
document.getElementById('details').innerText = Details;
4552
46-
for (var key in Downloads) {
47-
var row = document.createElement('tr');
48-
var filename = document.createElement('td');
49-
var progressCell = document.createElement('td');
53+
for (let key in Downloads) {
54+
let row = document.createElement('tr');
55+
let filename = document.createElement('td');
56+
let progressCell = document.createElement('td');
5057
5158
filename.innerText = key;
5259
53-
var progressBar = document.createElement('progress');
60+
let progressBar = document.createElement('progress');
5461
progressBar.value = Downloads[key];
5562
progressBar.max = 1;
5663
progressCell.appendChild(progressBar);
57-
58-
var percentage = document.createElement('span');
64+
65+
let percentage = document.createElement('span');
5966
percentage.innerText = (Downloads[key] * 100).toFixed(2) + '%';
6067
progressCell.appendChild(percentage);
6168
@@ -64,4 +71,6 @@
6471
downloads.appendChild(row);
6572
}
6673
}
74+
75+
download();
6776
</script>

ReplayBrowser/Services/ReplayParser/Providers/ReplayProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public abstract class ReplayProvider
77
public HttpClient GetHttpClient()
88
{
99
var httpClient = new HttpClient();
10-
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
1110
httpClient.DefaultRequestHeaders.Add("User-Agent", "ReplayBrowser");
1211
return httpClient;
1312
}

ReplayBrowser/Services/ReplayParser/ReplayParserService.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ReplayParserService : IHostedService, IDisposable
1616
public static List<string> Queue = new();
1717
public static ConcurrentDictionary<string, double> DownloadProgress = new();
1818
public static ParserStatus Status = ParserStatus.Off;
19+
public static string Details = "";
1920

2021
/// <summary>
2122
/// Since the Replay Meta file was added just yesterday, we want to cut off all replays that were uploaded before that.
@@ -68,6 +69,7 @@ private async Task FetchReplays(CancellationToken token, StorageUrl[] storageUrl
6869
while (!token.IsCancellationRequested)
6970
{
7071
Status = ParserStatus.Discovering;
72+
Details = $"0/{storageUrls.Length}";
7173
foreach (var storageUrl in storageUrls)
7274
{
7375
Log.Information("Fetching replays from " + storageUrl);
@@ -80,6 +82,8 @@ private async Task FetchReplays(CancellationToken token, StorageUrl[] storageUrl
8082
{
8183
Log.Error(e, "Error while fetching replays from " + storageUrl);
8284
}
85+
86+
Details = $"{Array.IndexOf(storageUrls, storageUrl) + 1}/{storageUrls.Length}";
8387
}
8488

8589
var now = DateTime.Now;
@@ -88,20 +92,30 @@ private async Task FetchReplays(CancellationToken token, StorageUrl[] storageUrl
8892
await ConsumeQueue(token);
8993
Log.Information("Next run in " + delay.TotalMinutes + " minutes.");
9094
Status = ParserStatus.Idle;
95+
Details = "";
9196
await Task.Delay(delay, token);
9297
}
9398
}
9499

95100
private async Task ConsumeQueue(CancellationToken token)
96101
{
97-
DownloadProgress.Clear();
102+
if (Queue.Count > 0)
103+
{
104+
DownloadProgress.Clear();
105+
}
106+
107+
var total = Queue.Count;
108+
var completed = 0;
109+
98110
// Consume the queue.
99111
while (Queue.Count > 0)
100112
{
101113
var timeoutToken = new CancellationTokenSource(10000);
102114
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, timeoutToken.Token);
103115
var startTime = DateTime.Now;
104116
// Clear the download progress.
117+
Details = $"{completed}/{total}";
118+
105119
DownloadProgress.Clear();
106120
Status = ParserStatus.Downloading;
107121
var tasks = new List<Task>();
@@ -131,6 +145,8 @@ private async Task ConsumeQueue(CancellationToken token)
131145
client.DefaultRequestHeaders.Add("User-Agent", "ReplayBrowser");
132146
Log.Information("Downloading " + replay);
133147
var fileStream = await client.GetStreamAsync(replay, progress, token);
148+
completed++;
149+
Details = $"{completed}/{total}";
134150
Replay? parsedReplay = null;
135151
try
136152
{

0 commit comments

Comments
 (0)