blob: dba36d7599d36b00f6481772f013cd7d9913eaf8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
}
|