-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boiler plate for replay upload at end of game
- Loading branch information
Showing
8 changed files
with
109 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/cli/src/Worms.Cli.Resources/Remote/Replays/RemoteReplay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Worms.Cli.Resources.Remote.Replays; | ||
|
||
public record RemoteReplay(string Id); |
41 changes: 41 additions & 0 deletions
41
src/cli/src/Worms.Cli.Resources/Remote/Replays/RemoteReplayCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Serilog; | ||
|
||
namespace Worms.Cli.Resources.Remote.Replays; | ||
|
||
internal class RemoteReplayCreator : IResourceCreator<RemoteReplay, string> | ||
{ | ||
private readonly IWormsServerApi _api; | ||
|
||
public RemoteReplayCreator(IWormsServerApi api) | ||
{ | ||
_api = api; | ||
} | ||
|
||
public async Task<RemoteReplay> Create(string parameters, ILogger logger, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var apiReplay = await _api.CreateReplay(parameters); | ||
return new RemoteReplay(apiReplay.Id); | ||
} | ||
catch (HttpRequestException e) | ||
{ | ||
switch (e.StatusCode) | ||
{ | ||
case HttpStatusCode.Unauthorized: | ||
logger.Warning( | ||
"You don't have access to the Worms Hub. Please run worms auth or contact an admin"); | ||
break; | ||
default: | ||
logger.Error(e, "An error occured calling the Worms Hub API"); | ||
break; | ||
} | ||
|
||
return new RemoteReplay(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/hub/src/Worms.Gateway/Controllers/ReplaysController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Worms.Gateway.Dtos; | ||
|
||
namespace Worms.Gateway.Controllers; | ||
|
||
public class ReplaysController : V1ApiController | ||
{ | ||
[HttpPost] | ||
public ActionResult<ReplayDto> Post(IFormFile replayFile) | ||
{ | ||
Console.WriteLine(replayFile.FileName); | ||
return new ReplayDto("0"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Worms.Gateway.Dtos; | ||
|
||
public record ReplayDto(string Id); |