Export controller

This commit is contained in:
Kieran 2024-01-13 16:49:08 +00:00
parent a22122e824
commit bb6fba1087
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941

View File

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Nostr.Client.Json;
using NostrServices.Services;
namespace NostrServices.Controllers;
[Route("/api/v1/export")]
public class ExportController : Controller
{
private readonly RedisStore _store;
public ExportController(RedisStore store)
{
_store = store;
}
[HttpGet("profile/{id}")]
[Produces("application/json")]
public async Task<IActionResult> GetProfile([FromRoute] string id)
{
var nid = await Extensions.TryParseIdentifier(id);
if (nid != default)
{
if (nid.Hrp is "npub" or "nprofile")
{
var px = await _store.GetProfile(nid.Special);
return Content(JsonConvert.SerializeObject(px, NostrSerializer.Settings), "application/json");
}
}
return BadRequest();
}
}