ApplySaneDefaults()

This commit is contained in:
fiatjaf
2024-04-19 15:38:32 -03:00
parent 8557c7a8dc
commit 8b1a7f2195
2 changed files with 24 additions and 0 deletions

View File

@@ -128,3 +128,13 @@ Fear no more. Using the https://github.com/fiatjaf/eventstore module you get a b
relay.CountEvents = append(relay.CountEvents, db.CountEvents)
relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent)
```
### But I don't want to write a bunch of custom policies!
Fear no more. We have a bunch of common policies written in the `github.com/fiatjaf/khatru/policies` package and also a handpicked selection of base sane defaults, which you can apply with:
```go
policies.ApplySaneDefaults(relay)
```
Contributions to this are very much welcomed.

14
policies/sane_defaults.go Normal file
View File

@@ -0,0 +1,14 @@
package policies
import "github.com/fiatjaf/khatru"
func ApplySaneDefaults(relay *khatru.Relay) {
relay.RejectEvent = append(relay.RejectEvent,
RejectEventsWithBase64Media,
)
relay.RejectFilter = append(relay.RejectFilter,
NoEmptyFilters,
NoComplexFilters,
)
}