通常イベントをneventでアクセスできるようにした

This commit is contained in:
studiokaiji
2023-10-06 16:27:46 +09:00
parent 0ede40e9e7
commit eb512e167a
3 changed files with 71 additions and 24 deletions

View File

@@ -24,14 +24,32 @@ func Start(port string) {
r := gin.Default()
r.GET("/e/:idHex", func(ctx *gin.Context) {
// IDを取得
id := ctx.Param("idHex")
r.GET("/e/:hex_or_nevent", func(ctx *gin.Context) {
hexOrNevent := ctx.Param("hex_or_nevent")
ids := []string{}
// neventからIDを取得
if hexOrNevent[0:6] == "nevent" {
_, res, err := nip19.Decode(hexOrNevent)
if err != nil {
ctx.String(http.StatusBadRequest, "Invalid nevent")
return
}
data, ok := res.(nostr.EventPointer)
if !ok {
ctx.String(http.StatusBadRequest, "Failed to decode nevent")
return
}
ids = append(ids, data.ID)
}
// Poolからデータを取得する
ev := pool.QuerySingle(ctx, allRelays, nostr.Filter{
Kinds: []int{consts.KindWebhostHTML, consts.KindWebhostCSS, consts.KindWebhostJS, consts.KindWebhostPicture},
IDs: []string{id},
IDs: ids,
})
if ev != nil {
switch ev.Kind {