auto create users.json if it doesn't exist

This commit is contained in:
github-tijlxyz 2024-02-28 16:59:16 +01:00
parent 7e6a3f00cb
commit 88b6fa0295
No known key found for this signature in database
GPG Key ID: 2EB6AC84AFE26CD6
3 changed files with 25 additions and 4 deletions

View File

@ -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
```

View File

@ -1,4 +1,3 @@
# Server Settings
DOMAIN="example.com"
PORT="3334" # optional

View File

@ -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 {