mirror of
https://github.com/github-tijlxyz/khatru-pyramid.git
synced 2025-04-19 10:21:18 +00:00
auto create users.json if it doesn't exist
This commit is contained in:
parent
7e6a3f00cb
commit
88b6fa0295
12
README.md
12
README.md
@ -4,6 +4,14 @@ A relay based on [Khatru](https://github.com/fiatjaf/khatru) with a invite hiera
|
||||
|
||||
### Deploy with docker
|
||||
|
||||
1. create and manually add a pubkey to users.json: `touch users.json && echo '{"your nostr hex pubkey":""}' > users.json`
|
||||
2. deploy with docker: `docker run -p 3334:3334 -v ./users.json:/app/users.json -v ./db:/app/db -e DOMAIN=yourdomain.example.com -e RELAY_NAME="your relay name" -e RELAY_PUBKEY="your nostr hex pubkey" tijlxyz/khatru-pyramid:latest`
|
||||
```
|
||||
docker run \
|
||||
-p 3334:3334 \
|
||||
-v ./users.json:/app/users.json \
|
||||
-v ./db:/app/db \
|
||||
-e DOMAIN=yourdomain.example.com \
|
||||
-e RELAY_NAME="your relay name" \
|
||||
-e RELAY_PUBKEY="your nostr hex pubkey" \
|
||||
tijlxyz/khatru-pyramid:latest
|
||||
```
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
# Server Settings
|
||||
DOMAIN="example.com"
|
||||
PORT="3334" # optional
|
||||
|
16
whitelist.go
16
whitelist.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -89,7 +90,20 @@ func removeDescendantsFromWhitelist(ancestor string) {
|
||||
func loadWhitelist() error {
|
||||
b, err := os.ReadFile(s.UserdataPath)
|
||||
if err != nil {
|
||||
return err
|
||||
// If the whitelist file does not exist, with RELAY_PUBKEY
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
whitelist[s.RelayPubkey] = ""
|
||||
jsonBytes, err := json.Marshal(&whitelist)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(s.UserdataPath, jsonBytes, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(b, &whitelist); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user