mirror of
https://github.com/fiatjaf/khatru.git
synced 2026-04-28 07:47:55 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa2ac552ea | ||
|
|
4e2b921af9 | ||
|
|
cf98cfc6d8 | ||
|
|
62a3b9b7d9 |
33
deleting.go
33
deleting.go
@@ -3,6 +3,8 @@ package khatru
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
)
|
)
|
||||||
@@ -10,10 +12,35 @@ import (
|
|||||||
func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) error {
|
func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) error {
|
||||||
// event deletion -- nip09
|
// event deletion -- nip09
|
||||||
for _, tag := range evt.Tags {
|
for _, tag := range evt.Tags {
|
||||||
if len(tag) >= 2 && tag[0] == "e" {
|
if len(tag) >= 2 {
|
||||||
// first we fetch the event
|
var f nostr.Filter
|
||||||
|
|
||||||
|
switch tag[0] {
|
||||||
|
case "e":
|
||||||
|
f = nostr.Filter{IDs: []string{tag[1]}}
|
||||||
|
case "a":
|
||||||
|
spl := strings.Split(tag[1], ":")
|
||||||
|
if len(spl) != 3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kind, err := strconv.Atoi(spl[0])
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
author := spl[1]
|
||||||
|
identifier := spl[2]
|
||||||
|
f = nostr.Filter{
|
||||||
|
Kinds: []int{kind},
|
||||||
|
Authors: []string{author},
|
||||||
|
Tags: nostr.TagMap{"d": []string{identifier}},
|
||||||
|
Until: &evt.CreatedAt,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, query := range rl.QueryEvents {
|
for _, query := range rl.QueryEvents {
|
||||||
ch, err := query(ctx, nostr.Filter{IDs: []string{tag[1]}})
|
ch, err := query(ctx, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ If on `RejectFilter` or `RejectEvent` you prefix the message with `auth-required
|
|||||||
relay.RejectFilter = append(relay.RejectFilter, func(ctx context.Context, filter nostr.Filter) (bool, string) {
|
relay.RejectFilter = append(relay.RejectFilter, func(ctx context.Context, filter nostr.Filter) (bool, string) {
|
||||||
return true, "auth-required: this query requires you to be authenticated"
|
return true, "auth-required: this query requires you to be authenticated"
|
||||||
})
|
})
|
||||||
relay.RejectEvent = append(relay.RejectFilter, func(ctx context.Context, event *nostr.Event) (bool, string) {
|
relay.RejectEvent = append(relay.RejectEvent, func(ctx context.Context, event *nostr.Event) (bool, string) {
|
||||||
return true, "auth-required: publishing this event requires authentication"
|
return true, "auth-required: publishing this event requires authentication"
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Other local key-value embedded databases that work the same way are [LMDB](https://pkg.go.dev/github.com/fiatjaf/eventstore/lmdb) and [BoltDB](https://pkg.go.dev/github.com/fiatjaf/eventstore/bolt).
|
[LMDB](https://pkg.go.dev/github.com/fiatjaf/eventstore/lmdb) works the same way.
|
||||||
|
|
||||||
[SQLite](https://pkg.go.dev/github.com/fiatjaf/eventstore/sqlite3) also stores things locally so it only needs a `Path`.
|
[SQLite](https://pkg.go.dev/github.com/fiatjaf/eventstore/sqlite3) also stores things locally so it only needs a `Path`.
|
||||||
|
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,12 +1,12 @@
|
|||||||
module github.com/fiatjaf/khatru
|
module github.com/fiatjaf/khatru
|
||||||
|
|
||||||
go 1.21.4
|
go 1.23
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fasthttp/websocket v1.5.7
|
github.com/fasthttp/websocket v1.5.7
|
||||||
github.com/fiatjaf/eventstore v0.5.1
|
github.com/fiatjaf/eventstore v0.5.1
|
||||||
github.com/nbd-wtf/go-nostr v0.34.5
|
github.com/nbd-wtf/go-nostr v0.34.5
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.0.2
|
github.com/puzpuzpuz/xsync/v3 v3.4.0
|
||||||
github.com/rs/cors v1.7.0
|
github.com/rs/cors v1.7.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
)
|
)
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -124,8 +124,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.0.2 h1:3yESHrRFYr6xzkz61LLkvNiPFXxJEAABanTQpKbAaew=
|
github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4=
|
||||||
github.com/puzpuzpuz/xsync/v3 v3.0.2/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||||
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||||
|
|||||||
Reference in New Issue
Block a user