Publish NostrServices.Client to NuGet
This commit is contained in:
@ -4,10 +4,19 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<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>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Nostr.Client" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Nostr.Client.Json;
|
||||||
|
using Nostr.Client.Messages;
|
||||||
|
|
||||||
namespace NostrServices.Client;
|
namespace NostrServices.Client;
|
||||||
|
|
||||||
@ -25,12 +27,42 @@ public class NostrServicesClient
|
|||||||
return default;
|
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
|
public class NostrProfile
|
||||||
{
|
{
|
||||||
|
[JsonProperty("pubkey")]
|
||||||
|
public byte[] PubKey { get; init; } = null!;
|
||||||
|
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public string? Name { get; init; }
|
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")]
|
[JsonProperty("lud16")]
|
||||||
public string? LightningAddress { get; init; }
|
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 Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Nostr.Client.Json;
|
using Nostr.Client.Json;
|
||||||
using NostrServices.Services;
|
using NostrServices.Services;
|
||||||
|
|
||||||
@ -15,6 +14,11 @@ public class ExportController : Controller
|
|||||||
_store = store;
|
_store = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get cached profile data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The pubkey of the user</param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet("profile/{id}")]
|
[HttpGet("profile/{id}")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public async Task<IActionResult> GetProfile([FromRoute] string id)
|
public async Task<IActionResult> GetProfile([FromRoute] string id)
|
||||||
@ -25,7 +29,39 @@ public class ExportController : Controller
|
|||||||
if (nid.Hrp is "npub" or "nprofile")
|
if (nid.Hrp is "npub" or "nprofile")
|
||||||
{
|
{
|
||||||
var px = await _store.GetProfile(nid.Special);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user