Publish NostrServices.Client to NuGet
This commit is contained in:
parent
d2e9b07151
commit
067fe24eb7
@ -4,10 +4,19 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<RepositoryUrl>https://git.v0l.io/Kieran/NostrServices</RepositoryUrl>
|
||||
<Version>1.0.1</Version>
|
||||
<Authors>Kieran</Authors>
|
||||
<Description>Client wrapper for https://nostr.api.v0l.io</Description>
|
||||
<PackageProjectUrl>https://git.v0l.io/Kieran/NostrServices</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://mit-license.org/</PackageLicenseUrl>
|
||||
<PackageTags>nostr</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Nostr.Client" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Nostr.Client.Json;
|
||||
using Nostr.Client.Messages;
|
||||
|
||||
namespace NostrServices.Client;
|
||||
|
||||
@ -25,12 +27,42 @@ public class NostrServicesClient
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<NostrEvent?> Event(string id)
|
||||
{
|
||||
var rsp = await _client.GetAsync($"/api/v1/export/{id}");
|
||||
if (rsp.IsSuccessStatusCode)
|
||||
{
|
||||
var json = await rsp.Content.ReadAsStringAsync();
|
||||
return NostrJson.Deserialize<NostrEvent>(json);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public class NostrProfile
|
||||
{
|
||||
[JsonProperty("pubkey")]
|
||||
public byte[] PubKey { get; init; } = null!;
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string? Name { get; init; }
|
||||
|
||||
[JsonProperty("about")]
|
||||
public string? About { get; init; }
|
||||
|
||||
[JsonProperty("picture")]
|
||||
public string? Picture { get; init; }
|
||||
|
||||
[JsonProperty("nip05")]
|
||||
public string? Nip05 { get; init; }
|
||||
|
||||
[JsonProperty("lud16")]
|
||||
public string? LightningAddress { get; init; }
|
||||
|
||||
[JsonProperty("banner")]
|
||||
public string? Banner { get; init; }
|
||||
|
||||
[JsonProperty("created")]
|
||||
public DateTime Created { get; init; }
|
||||
}
|
||||
}
|
||||
|
3
NostrServices.Client/README.md
Normal file
3
NostrServices.Client/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
## NostrServices.Client
|
||||
|
||||
Simple class for calling https://nostr.api.v0l.io
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Nostr.Client.Json;
|
||||
using NostrServices.Services;
|
||||
|
||||
@ -15,6 +14,11 @@ public class ExportController : Controller
|
||||
_store = store;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get cached profile data
|
||||
/// </summary>
|
||||
/// <param name="id">The pubkey of the user</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("profile/{id}")]
|
||||
[Produces("application/json")]
|
||||
public async Task<IActionResult> GetProfile([FromRoute] string id)
|
||||
@ -25,7 +29,39 @@ public class ExportController : Controller
|
||||
if (nid.Hrp is "npub" or "nprofile")
|
||||
{
|
||||
var px = await _store.GetProfile(nid.Special);
|
||||
return Content(JsonConvert.SerializeObject(px, NostrSerializer.Settings), "application/json");
|
||||
if (px != default)
|
||||
{
|
||||
return Content(NostrJson.Serialize(px)!, "application/json");
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get cached event
|
||||
/// </summary>
|
||||
/// <param name="id">note1/nevent/naddr</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[Produces("application/json")]
|
||||
public async Task<IActionResult> GetEvent([FromRoute] string id)
|
||||
{
|
||||
var nid = await Extensions.TryParseIdentifier(id);
|
||||
if (nid != default)
|
||||
{
|
||||
if (nid.Hrp is "nevent" or "note" or "naddr")
|
||||
{
|
||||
var ex = await _store.GetEvent(nid);
|
||||
if (ex != default)
|
||||
{
|
||||
return Content(NostrJson.Serialize(ex.ToNostrEvent())!, "application/json");
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user