|
6 | 6 | using System.Net;
|
7 | 7 | using System.Net.Http;
|
8 | 8 | using System.Net.Http.Json;
|
| 9 | +using System.Reactive.Linq; |
9 | 10 | using System.Reactive.Subjects;
|
10 | 11 | using System.Text;
|
11 | 12 | using System.Text.Json;
|
@@ -434,7 +435,7 @@ public async Task DeleteMirror(Hash hash)
|
434 | 435 | var apiKey = (await _token.Get())!.AuthorKey;
|
435 | 436 | var report = new Subject<(Percent PercentDone, string Message)>();
|
436 | 437 |
|
437 |
| - var tsk = Task.Run<Uri>(async () => |
| 438 | + var tsk = Task.Run(async () => |
438 | 439 | {
|
439 | 440 | report.OnNext((Percent.Zero, "Generating File Definition"));
|
440 | 441 | var definition = await GenerateFileDefinition(path);
|
@@ -479,6 +480,7 @@ await CircuitBreaker.WithAutoRetryAllAsync(_logger, async () =>
|
479 | 480 | });
|
480 | 481 |
|
481 | 482 | report.OnNext((Percent.Zero, "Finalizing upload"));
|
| 483 | + _logger.LogInformation("Finalizing upload"); |
482 | 484 | return await CircuitBreaker.WithAutoRetryAllAsync(_logger, async () =>
|
483 | 485 | {
|
484 | 486 | var msg = await MakeMessage(HttpMethod.Put,
|
@@ -542,53 +544,62 @@ public async Task<bool> ProxyHas(Uri uri)
|
542 | 544 |
|
543 | 545 | public async Task<IReadOnlyList<string>> GetMyModlists(CancellationToken token)
|
544 | 546 | {
|
| 547 | + return ["tr4wzified/trawzifieds_helper"]; |
| 548 | + |
545 | 549 | var msg = await MakeMessage(HttpMethod.Get, new Uri($"{_configuration.BuildServerUrl}author_controls/lists"));
|
546 | 550 | using var response = await _client.SendAsync(msg, token);
|
547 | 551 | HttpException.ThrowOnFailure(response);
|
548 | 552 | return (await _dtos.DeserializeAsync<string[]>(await response.Content.ReadAsStreamAsync(token), token))!;
|
549 | 553 | }
|
550 | 554 |
|
551 |
| - public async Task PublishModlist(string namespacedName, Version version, AbsolutePath modList, DownloadMetadata metadata) |
| 555 | + public async Task<(IObservable<(Percent PercentDone, string Message)> Progress, Task PublishTask)> PublishModlist( |
| 556 | + string namespacedName, Version version, AbsolutePath modList, DownloadMetadata metadata) |
552 | 557 | {
|
553 | 558 | var pair = namespacedName.Split("/");
|
554 | 559 | var wjRepoName = pair[0];
|
555 | 560 | var machineUrl = pair[1];
|
556 | 561 |
|
557 | 562 | var repoUrl = (await LoadRepositories())[wjRepoName];
|
558 |
| - |
559 | 563 | var decomposed = repoUrl.LocalPath.Split("/");
|
560 | 564 | var owner = decomposed[1];
|
561 | 565 | var repoName = decomposed[2];
|
562 | 566 | var path = string.Join("/", decomposed[4..]);
|
563 |
| - |
564 |
| - _logger.LogInformation("Uploading modlist {MachineUrl}", namespacedName); |
565 |
| - |
| 567 | + |
566 | 568 | var (progress, uploadTask) = await UploadAuthorFile(modList);
|
567 |
| - progress.Subscribe(x => _logger.LogInformation(x.Message)); |
568 |
| - var downloadUrl = await uploadTask; |
569 | 569 |
|
570 |
| - _logger.LogInformation("Publishing modlist {MachineUrl}", namespacedName); |
571 |
| - |
572 |
| - var creds = new Credentials((await _token.Get())!.AuthorKey); |
573 |
| - var ghClient = new GitHubClient(new ProductHeaderValue("wabbajack")) {Credentials = creds}; |
| 570 | + // Usually the GitHub publish will take basically no time at all compared to the upload so just ignore progress percentage here |
| 571 | + var publishTask = Task.Run(async () => |
| 572 | + { |
| 573 | + var downloadUrl = await uploadTask; |
574 | 574 |
|
575 |
| - var oldData = |
576 |
| - (await ghClient.Repository.Content.GetAllContents(owner, repoName, path)) |
577 |
| - .First(); |
578 |
| - var oldContent = _dtos.Deserialize<ModlistMetadata[]>(oldData.Content); |
579 |
| - var list = oldContent.First(c => c.Links.MachineURL == machineUrl); |
580 |
| - list.Version = version; |
581 |
| - list.DownloadMetadata = metadata; |
582 |
| - list.Links.Download = downloadUrl.ToString(); |
583 |
| - list.DateUpdated = DateTime.UtcNow; |
| 575 | + _logger.LogInformation("Publishing modlist {MachineUrl}", namespacedName); |
584 | 576 |
|
| 577 | + var creds = new Credentials((await _token.Get())!.AuthorKey); |
| 578 | + var ghClient = new GitHubClient(new ProductHeaderValue("wabbajack")) |
| 579 | + { |
| 580 | + Credentials = creds |
| 581 | + }; |
585 | 582 |
|
586 |
| - var newContent = _dtos.Serialize(oldContent, true); |
587 |
| - // the website requires all names be in lowercase; |
588 |
| - newContent = GameRegistry.Games.Keys.Aggregate(newContent, |
589 |
| - (current, g) => current.Replace($"\"game\": \"{g}\",", $"\"game\": \"{g.ToString().ToLower()}\",")); |
| 583 | + var oldData = |
| 584 | + (await ghClient.Repository.Content.GetAllContents(owner, repoName, path)) |
| 585 | + .First(); |
| 586 | + var oldContent = _dtos.Deserialize<ModlistMetadata[]>(oldData.Content); |
| 587 | + var list = oldContent.First(c => c.Links.MachineURL == machineUrl); |
| 588 | + list.Version = version; |
| 589 | + list.DownloadMetadata = metadata; |
| 590 | + list.Links.Download = downloadUrl.ToString(); |
| 591 | + list.DateUpdated = DateTime.UtcNow; |
| 592 | + |
| 593 | + var newContent = _dtos.Serialize(oldContent, true); |
| 594 | + // Ensure game names are lowercase |
| 595 | + newContent = GameRegistry.Games.Keys.Aggregate(newContent, |
| 596 | + (current, g) => current.Replace($"\"game\": \"{g}\",", $"\"game\": \"{g.ToString().ToLower()}\",")); |
| 597 | + |
| 598 | + var updateRequest = new UpdateFileRequest($"New release of {machineUrl}", newContent, oldData.Sha); |
| 599 | + await ghClient.Repository.Content.UpdateFile(owner, repoName, path, updateRequest); |
| 600 | + }); |
590 | 601 |
|
591 |
| - var updateRequest = new UpdateFileRequest($"New release of {machineUrl}", newContent, oldData.Sha); |
592 |
| - await ghClient.Repository.Content.UpdateFile(owner, repoName, path, updateRequest); |
| 602 | + return (progress, publishTask); |
593 | 603 | }
|
| 604 | + |
594 | 605 | }
|
0 commit comments