mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
Migrate API to ASP.NET Core Auth services + refactor
This commit is contained in:
parent
7fde54050a
commit
627f544ee8
25 changed files with 289 additions and 141 deletions
|
|
@ -1,59 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
namespace PluralKit.API
|
||||
{
|
||||
public struct MessageReturn
|
||||
{
|
||||
[JsonProperty("timestamp")] public Instant Timestamp;
|
||||
[JsonProperty("id")] public string Id;
|
||||
[JsonProperty("original")] public string Original;
|
||||
[JsonProperty("sender")] public string Sender;
|
||||
[JsonProperty("channel")] public string Channel;
|
||||
|
||||
[JsonProperty("system")] public JObject System;
|
||||
[JsonProperty("member")] public JObject Member;
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("msg")]
|
||||
[Route( "v{version:apiVersion}/msg" )]
|
||||
public class MessageController: ControllerBase
|
||||
{
|
||||
private IDataStore _data;
|
||||
private TokenAuthService _auth;
|
||||
|
||||
public MessageController(IDataStore _data, TokenAuthService auth)
|
||||
{
|
||||
this._data = _data;
|
||||
_auth = auth;
|
||||
}
|
||||
|
||||
[HttpGet("{mid}")]
|
||||
public async Task<ActionResult<MessageReturn>> GetMessage(ulong mid)
|
||||
{
|
||||
var msg = await _data.GetMessage(mid);
|
||||
if (msg == null) return NotFound("Message not found.");
|
||||
|
||||
return new MessageReturn
|
||||
{
|
||||
Timestamp = Instant.FromUnixTimeMilliseconds((long) (msg.Message.Mid >> 22) + 1420070400000),
|
||||
Id = msg.Message.Mid.ToString(),
|
||||
Channel = msg.Message.Channel.ToString(),
|
||||
Sender = msg.Message.Sender.ToString(),
|
||||
Member = msg.Member.ToJson(_auth.ContextFor(msg.System)),
|
||||
System = msg.System.ToJson(_auth.ContextFor(msg.System)),
|
||||
Original = msg.Message.OriginalMid?.ToString()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue