diff options
author | Rory& <root@rory.gay> | 2023-12-31 16:38:20 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2023-12-31 16:38:20 +0100 |
commit | 05289f61d7bd0650ef511cc92a8a657c493dce30 (patch) | |
tree | ed38ef598f9e37eaaf294b8864f361553869ee3c /ModAS.Server/Controllers/AppService | |
parent | Add auth, start of commit script (diff) | |
download | ModAS-master.tar.xz |
Clean up swagger, clean up auth code HEAD github/master master
Diffstat (limited to 'ModAS.Server/Controllers/AppService')
-rw-r--r-- | ModAS.Server/Controllers/AppService/PingController.cs | 74 | ||||
-rw-r--r-- | ModAS.Server/Controllers/AppService/TransactionsController.cs | 1 |
2 files changed, 12 insertions, 63 deletions
diff --git a/ModAS.Server/Controllers/AppService/PingController.cs b/ModAS.Server/Controllers/AppService/PingController.cs index 7b073c1..6db9033 100644 --- a/ModAS.Server/Controllers/AppService/PingController.cs +++ b/ModAS.Server/Controllers/AppService/PingController.cs @@ -1,73 +1,21 @@ -using System.IO.Pipelines; -using System.Net; -using System.Net.Http.Headers; -using System.Text.Json; -using ArcaneLibs; -using LibMatrix; -using LibMatrix.EventTypes.Spec; +using System.Text.Json.Serialization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration.Json; -using ModAS.Server; +using Microsoft.OpenApi.Validations.Rules; using ModAS.Server.Attributes; -using ModAS.Server.Services; -using MxApiExtensions.Services; namespace ModAS.Server.Controllers.AppService; [ApiController] -public class PingController( - AppServiceRegistration asr, - ModASConfiguration config, - UserProviderService userProvider, - RoomContextService roomContextService, - RoomStateCacheService stateCacheService) : ControllerBase { - private static List<string> _ignoredInvalidationEvents { get; set; } = [ - RoomMessageEventContent.EventId, - RoomMessageReactionEventContent.EventId - ]; - - [HttpPut("/_matrix/app/v1/transactions/{txnId}")] +[ApiExplorerSettings(IgnoreApi = true)] //hide from swagger +public class PingController : ControllerBase { + [HttpPost("/_matrix/app/v1/ping")] [UserAuth(AuthType = AuthType.Server)] - public async Task<IActionResult> PutTransactions(string txnId) { - var data = await JsonSerializer.DeserializeAsync<EventList>(Request.Body); - Console.WriteLine( - $"PutTransaction: {txnId}: {data.Events.Count} events, {Util.BytesToString(Request.Headers.ContentLength ?? Request.ContentLength ?? Request.Body.Length)}"); - - if (!Directory.Exists("data")) - Directory.CreateDirectory("data"); - Directory.CreateDirectory($"data/{txnId}"); - // var pipe = PipeReader.Create(Request.Body); - // await using var file = System.IO.File.OpenWrite($"data/{txnId}"); - // await pipe.CopyToAsync(file); - // await pipe.CompleteAsync(); - // - // Console.WriteLine($"PutTransaction: {txnId}: {Util.BytesToString(file.Length)}"); - for (var i = 0; i < data.Events.Count; i++) { - var evt = data.Events[i]; - Console.WriteLine($"PutTransaction: {txnId}/{i}: {evt.Type} {evt.StateKey} {evt.Sender}"); - await System.IO.File.WriteAllTextAsync($"data/{txnId}/{i}-{evt.Type.Replace("/", "")}-{evt.StateKey.Replace("/", "")}-{evt.Sender?.Replace("/", "")}.json", - JsonSerializer.Serialize(evt)); - - if (evt.Sender.EndsWith(':' + config.ServerName)) { - Console.WriteLine("PutTransaction: sender is local user, updating data..."); - try { - var user = await userProvider.GetImpersonatedHomeserver(evt.Sender); - var rooms = await user.GetJoinedRooms(); - foreach (var room in rooms) { - await roomContextService.GetRoomContext(room); - } - } - catch (Exception e) { - Console.WriteLine($"PutTransaction: failed to update data: {e}"); - } - } - else - Console.WriteLine("PutTransaction: sender is remote user"); - - if (!string.IsNullOrWhiteSpace(evt.RoomId) && !_ignoredInvalidationEvents.Contains(evt.Type)) - await stateCacheService.InvalidateRoomState(evt.RoomId); - } - + public IActionResult PutTransactions([FromBody] TransactionIdContainer data) { return Ok(new { }); } + + public class TransactionIdContainer { + [JsonPropertyName("transaction_id")] + public string TransactionId { get; set; } + } } \ No newline at end of file diff --git a/ModAS.Server/Controllers/AppService/TransactionsController.cs b/ModAS.Server/Controllers/AppService/TransactionsController.cs index 53bfaf5..fd8a6d3 100644 --- a/ModAS.Server/Controllers/AppService/TransactionsController.cs +++ b/ModAS.Server/Controllers/AppService/TransactionsController.cs @@ -15,6 +15,7 @@ using MxApiExtensions.Services; namespace ModAS.Server.Controllers.AppService; [ApiController] +[ApiExplorerSettings(IgnoreApi = true)] //hide from swagger public class TransactionsController( AppServiceRegistration asr, ModASConfiguration config, |