From f41b6e5ec431c88bc1d94e4832d8ba49ddc42004 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Tue, 5 Mar 2024 11:19:52 +0100 Subject: HomeserverEmulator work --- .../Controllers/Media/MediaController.cs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs (limited to 'Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs') diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs new file mode 100644 index 0000000..dba36d7 --- /dev/null +++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs @@ -0,0 +1,34 @@ +using LibMatrix.HomeserverEmulator.Services; +using Microsoft.AspNetCore.Mvc; + +namespace LibMatrix.HomeserverEmulator.Controllers.Media; + +[ApiController] +[Route("/_matrix/media/{version}/")] +public class MediaController(ILogger logger, TokenService tokenService, UserStore userStore, RoomStore roomStore) : ControllerBase { + [HttpPost("upload")] + public async Task UploadMedia([FromHeader(Name = "Content-Type")] string ContentType, [FromQuery] string filename, [FromBody] Stream file) { + var token = tokenService.GetAccessToken(HttpContext); + if (token == null) + throw new MatrixException() { + ErrorCode = "M_MISSING_TOKEN", + Error = "Missing token" + }; + + var user = await userStore.GetUserByToken(token); + if (user == null) + throw new MatrixException() { + ErrorCode = "M_UNKNOWN_TOKEN", + Error = "No such user" + }; + + + + var mediaId = Guid.NewGuid().ToString(); + var media = new { + content_uri = $"mxc://{tokenService.GenerateServerName(HttpContext)}/{mediaId}" + }; + return media; + + } +} \ No newline at end of file -- cgit 1.4.1