Bug fixes

This commit is contained in:
2024-01-10 11:18:53 +00:00
parent 1360753d15
commit 55223c3bb7
3 changed files with 18 additions and 5 deletions

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Nostr.Client.Json;
using Nostr.Client.Messages; using Nostr.Client.Messages;
using NostrServices.Services; using NostrServices.Services;
@ -14,13 +16,24 @@ public class ImportController : Controller
_redisStore = redisStore; _redisStore = redisStore;
} }
/// <summary>
/// Import events in ND-JSON format
/// </summary>
/// <returns></returns>
[HttpPost] [HttpPost]
[Consumes("text/json", "application/json")] [Consumes("text/json", "application/json")]
public async Task<IActionResult> ImportEvent([FromBody] NostrEvent ev) public async Task<IActionResult> ImportEvent()
{ {
if (await _redisStore.StoreEvent(CompactEvent.FromNostrEvent(ev))) var cts = HttpContext.RequestAborted;
using var sr = new StreamReader(Request.Body);
while (await sr.ReadLineAsync(cts) is { } line)
{ {
return Accepted(); var ev = JsonConvert.DeserializeObject<NostrEvent>(line, NostrSerializer.Settings);
if (ev != default)
{
await _redisStore.StoreEvent(CompactEvent.FromNostrEvent(ev));
}
} }
return Ok(); return Ok();

View File

@ -55,7 +55,7 @@ public class OpenGraphController : Controller
{ {
try try
{ {
if (nid!.Hrp is "nevent" or "note") if (nid!.Hrp is "nevent" or "note" or "naddr")
{ {
var ev = await _redisStore.GetEvent(nid); var ev = await _redisStore.GetEvent(nid);
if (ev != default) if (ev != default)

View File

@ -39,7 +39,7 @@ public class RedisStore
return await _database.GetAsync<CompactProfile>(ProfileKey(id)); return await _database.GetAsync<CompactProfile>(ProfileKey(id));
} }
private string EventKey(NostrIdentifier id) => $"event:{id}"; private string EventKey(NostrIdentifier id) => $"event:{id.ToBech32()}";
private string ProfileKey(string id) => $"profile:{id}"; private string ProfileKey(string id) => $"profile:{id}";
} }