summary refs log tree commit diff
path: root/ModAS.Server/Controllers/AppService/TransactionsController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ModAS.Server/Controllers/AppService/TransactionsController.cs')
-rw-r--r--ModAS.Server/Controllers/AppService/TransactionsController.cs23
1 files changed, 13 insertions, 10 deletions
diff --git a/ModAS.Server/Controllers/AppService/TransactionsController.cs b/ModAS.Server/Controllers/AppService/TransactionsController.cs
index b74e1e1..53bfaf5 100644
--- a/ModAS.Server/Controllers/AppService/TransactionsController.cs
+++ b/ModAS.Server/Controllers/AppService/TransactionsController.cs
@@ -8,6 +8,7 @@ using LibMatrix.EventTypes.Spec;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration.Json;
 using ModAS.Server;
+using ModAS.Server.Attributes;
 using ModAS.Server.Services;
 using MxApiExtensions.Services;
 
@@ -26,16 +27,17 @@ public class TransactionsController(
     ];
 
     [HttpPut("/_matrix/app/v1/transactions/{txnId}")]
+    [UserAuth(AuthType = AuthType.Server)]
     public async Task<IActionResult> PutTransactions(string txnId) {
-        if (!Request.Headers.ContainsKey("Authorization")) {
-            Console.WriteLine("PutTransaction: missing authorization header");
-            return Unauthorized();
-        }
-
-        if (Request.GetTypedHeaders().Get<AuthenticationHeaderValue>("Authorization")?.Parameter != asr.HomeserverToken) {
-            Console.WriteLine($"PutTransaction: invalid authorization header: {Request.Headers["Authorization"]}");
-            return Unauthorized();
-        }
+        // if (!Request.Headers.ContainsKey("Authorization")) {
+        //     Console.WriteLine("PutTransaction: missing authorization header");
+        //     return Unauthorized();
+        // }
+        //
+        // if (Request.GetTypedHeaders().Get<AuthenticationHeaderValue>("Authorization")?.Parameter != asr.HomeserverToken) {
+        //     Console.WriteLine($"PutTransaction: invalid authorization header: {Request.Headers["Authorization"]}");
+        //     return Unauthorized();
+        // }
 
         var data = await JsonSerializer.DeserializeAsync<EventList>(Request.Body);
         Console.WriteLine(
@@ -53,7 +55,8 @@ public class TransactionsController(
         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}-{evt.StateKey}-{evt.Sender}.json", JsonSerializer.Serialize(evt));
+            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...");