-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
147 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package replicatr | ||
|
||
func (rl *Relay) handleCountRequest(ctx Ctx, ws *WebSocket, | ||
filter *Filter) (subtotal int64) { | ||
|
||
// overwrite the filter (for example, to eliminate some kinds or tags that | ||
// we know we don't support) | ||
for _, ovw := range rl.OverwriteCountFilter { | ||
ovw(ctx, filter) | ||
} | ||
// then check if we'll reject this filter | ||
for _, reject := range rl.RejectCountFilter { | ||
if rej, msg := reject(ctx, filter); rej { | ||
rl.E.Chk(ws.WriteJSON(NoticeEnvelope(msg))) | ||
return 0 | ||
} | ||
} | ||
// run the functions to count (generally it will be just one) | ||
var e error | ||
var res int64 | ||
for _, count := range rl.CountEvents { | ||
if res, e = count(ctx, filter); rl.E.Chk(e) { | ||
rl.E.Chk(ws.WriteJSON(NoticeEnvelope(e.Error()))) | ||
} | ||
subtotal += res | ||
} | ||
return | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package replicatr | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/nostr+json") | ||
info := rl.Info | ||
for _, ovw := range rl.OverwriteRelayInfo { | ||
info = ovw(r.Context(), r, info) | ||
} | ||
rl.E.Chk(json.NewEncoder(w).Encode(info)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package replicatr | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/rs/cors" | ||
) | ||
|
||
// ServeHTTP implements http.Handler interface. | ||
func (rl *Relay) ServeHTTP(w ResponseWriter, r *Request) { | ||
if rl.ServiceURL == "" { | ||
rl.ServiceURL = getServiceBaseURL(r) | ||
} | ||
if r.Header.Get("Upgrade") == "websocket" { | ||
rl.HandleWebsocket(w, r) | ||
} else if r.Header.Get("Accept") == "application/nostr+json" { | ||
cors.AllowAll().Handler(http.HandlerFunc(rl.HandleNIP11)).ServeHTTP(w, r) | ||
} else { | ||
rl.serveMux.ServeHTTP(w, r) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.