diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-03-05 11:19:52 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-03-05 11:19:52 +0100 |
commit | f41b6e5ec431c88bc1d94e4832d8ba49ddc42004 (patch) | |
tree | 503be94f5036f7cc221846c1eabf7c5edd107f1a /Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs | |
parent | Unknown changes (diff) | |
download | LibMatrix-f41b6e5ec431c88bc1d94e4832d8ba49ddc42004.tar.xz |
HomeserverEmulator work
Diffstat (limited to 'Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs')
-rw-r--r-- | Tests/LibMatrix.HomeserverEmulator/Controllers/Media/MediaController.cs | 34 |
1 files changed, 34 insertions, 0 deletions
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<MediaController> logger, TokenService tokenService, UserStore userStore, RoomStore roomStore) : ControllerBase { + [HttpPost("upload")] + public async Task<object> 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 |