Implemented moonlight report endpoints
This commit is contained in:
parent
654f6bf3c1
commit
69a3834797
41
Moonlight/App/Http/Controllers/Api/Remote/DdosController.cs
Normal file
41
Moonlight/App/Http/Controllers/Api/Remote/DdosController.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using Logging.Net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moonlight.App.Http.Requests.Daemon;
|
||||
using Moonlight.App.Repositories;
|
||||
using Moonlight.App.Services;
|
||||
|
||||
namespace Moonlight.App.Http.Controllers.Api.Remote;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/remote/ddos")]
|
||||
public class DdosController : Controller
|
||||
{
|
||||
private readonly NodeRepository NodeRepository;
|
||||
private readonly MessageService MessageService;
|
||||
|
||||
public DdosController(NodeRepository nodeRepository, MessageService messageService)
|
||||
{
|
||||
NodeRepository = nodeRepository;
|
||||
MessageService = messageService;
|
||||
}
|
||||
|
||||
[HttpPost("update")]
|
||||
public async Task<ActionResult> Update([FromBody] DdosStatus ddosStatus)
|
||||
{
|
||||
var tokenData = Request.Headers.Authorization.ToString().Replace("Bearer ", "");
|
||||
var id = tokenData.Split(".")[0];
|
||||
var token = tokenData.Split(".")[1];
|
||||
|
||||
var node = NodeRepository.Get().FirstOrDefault(x => x.TokenId == id);
|
||||
|
||||
if (node == null)
|
||||
return NotFound();
|
||||
|
||||
if (token != node.Token)
|
||||
return Unauthorized();
|
||||
|
||||
await MessageService.Emit("node.ddos", ddosStatus);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
8
Moonlight/App/Http/Requests/Daemon/DdosStatus.cs
Normal file
8
Moonlight/App/Http/Requests/Daemon/DdosStatus.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Moonlight.App.Http.Requests.Daemon;
|
||||
|
||||
public class DdosStatus
|
||||
{
|
||||
public bool Ongoing { get; set; }
|
||||
public long Data { get; set; }
|
||||
public string Ip { get; set; } = "";
|
||||
}
|
Loading…
Reference in a new issue