Compare commits

..

5 Commits
v0.3.1 ... main

Author SHA1 Message Date
fiatjaf
5e9a09b3c5 fix report page. 2025-04-25 22:02:36 -03:00
fiatjaf
66e0c849fc "browse" goes to jumble instead of self-hosted jouble. 2025-04-25 17:48:41 -03:00
fiatjaf
34ab0272c7 authorize 30023. 2025-04-25 16:01:19 -03:00
fiatjaf
c4a241a99f stop ratelimiting events. 2025-04-24 14:01:48 -03:00
fiatjaf
cbc84a2004 changes, support 1111 counts, 39701 bookmarks. 2025-04-24 14:01:48 -03:00
5 changed files with 52 additions and 55 deletions

View File

@ -91,31 +91,3 @@ func reportsViewerHandler(w http.ResponseWriter, r *http.Request) {
reportsPage(events, getLoggedUser(r)).Render(r.Context(), w) reportsPage(events, getLoggedUser(r)).Render(r.Context(), w)
} }
func joubleHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pyramid</title>
<script>
window.relayGroups = [{
groupName: 'pyramid',
relayUrls: [location.href.replace('http', 'ws').replace('/browse', '')],
isActive: true,
}]
window.hideRelaySettings = true
</script>
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/jouble@0.0.6/dist/index.js"></script>
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/npm/jouble@0.0.6/dist/index.css">
</head>
<body>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/window.nostr.js@0.4.7/dist/window.nostr.min.js"></script>
</body>
</html>
`)
}

View File

@ -21,7 +21,7 @@ templ layout(loggedUser string) {
</div> </div>
<nav class="flex flex-1 items-center justify-center"> <nav class="flex flex-1 items-center justify-center">
<a href="/" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium" hx-boost="true" hx-target="main" hx-select="main">invite tree</a> <a href="/" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium" hx-boost="true" hx-target="main" hx-select="main">invite tree</a>
<a href="/browse" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium">browse</a> <a target="_blank" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium" _="on load set my href to `https://jumble.social/?r=${location.hostname}`">browse</a>
<a href="/reports" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium" hx-boost="true" hx-target="main" hx-select="main">reports</a> <a href="/reports" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium" hx-boost="true" hx-target="main" hx-select="main">reports</a>
if loggedUser == s.RelayPubkey { if loggedUser == s.RelayPubkey {
<a href="/cleanup" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium">clear stuff</a> <a href="/cleanup" class="text-gray-600 hover:bg-gray-200 rounded-md px-3 py-2 font-medium">clear stuff</a>

10
main.go
View File

@ -9,6 +9,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"github.com/fiatjaf/eventstore/lmdb" "github.com/fiatjaf/eventstore/lmdb"
"github.com/fiatjaf/khatru" "github.com/fiatjaf/khatru"
@ -90,7 +91,13 @@ func main() {
} }
relay.Info.Software = "https://github.com/github-tijlxyz/khatru-pyramid" relay.Info.Software = "https://github.com/github-tijlxyz/khatru-pyramid"
policies.ApplySaneDefaults(relay) relay.RejectFilter = append(relay.RejectFilter,
policies.NoComplexFilters,
policies.FilterIPRateLimiter(20, time.Minute, 100),
)
relay.RejectConnection = append(relay.RejectConnection,
policies.ConnectionRateLimiter(1, time.Minute*5, 100),
)
relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent) relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent)
relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents) relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents)
@ -128,7 +135,6 @@ func main() {
relay.Router().HandleFunc("/remove-from-whitelist", removeFromWhitelistHandler) relay.Router().HandleFunc("/remove-from-whitelist", removeFromWhitelistHandler)
relay.Router().HandleFunc("/cleanup", cleanupStuffFromExcludedUsersHandler) relay.Router().HandleFunc("/cleanup", cleanupStuffFromExcludedUsersHandler)
relay.Router().HandleFunc("/reports", reportsViewerHandler) relay.Router().HandleFunc("/reports", reportsViewerHandler)
relay.Router().HandleFunc("/browse/", joubleHandler)
relay.Router().Handle("/static/", http.FileServer(http.FS(static))) relay.Router().Handle("/static/", http.FileServer(http.FS(static)))
relay.Router().HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) { relay.Router().HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
if s.RelayIcon != "" { if s.RelayIcon != "" {

View File

@ -68,6 +68,7 @@ var supportedKinds = []uint16{
30015, 30015,
30818, 30818,
30819, 30819,
30023,
30030, 30030,
30078, 30078,
30311, 30311,

View File

@ -1,12 +1,13 @@
package main package main
import "github.com/nbd-wtf/go-nostr" import "github.com/nbd-wtf/go-nostr"
import "github.com/nbd-wtf/go-nostr/nip19"
templ reportsPage(reports chan *nostr.Event, loggedUser string) { templ reportsPage(reports chan *nostr.Event, loggedUser string) {
@layout(loggedUser) { @layout(loggedUser) {
<div> <div class="max-w-4xl mx-auto">
<h1 class="text-xl p-4">reports received</h1> <h1 class="text-xl p-4">reports received</h1>
<div> <div class="space-y-4 p-4">
for report := range reports { for report := range reports {
<div> <div>
if e := report.Tags.Find("e"); e != nil { if e := report.Tags.Find("e"); e != nil {
@ -23,7 +24,8 @@ templ reportsPage(reports chan *nostr.Event, loggedUser string) {
templ eventReportComponent(e nostr.Tag, report *nostr.Event) { templ eventReportComponent(e nostr.Tag, report *nostr.Event) {
if res, _ := sys.StoreRelay.QuerySync(ctx, nostr.Filter{IDs: []string{e[1]}}); len(res) > 0 { if res, _ := sys.StoreRelay.QuerySync(ctx, nostr.Filter{IDs: []string{e[1]}}); len(res) > 0 {
<div> <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
<div class="flex justify-between items-start">
<div class="font-lg"> <div class="font-lg">
<span class="font-semibold"> <span class="font-semibold">
if len(e) >= 3 { if len(e) >= 3 {
@ -32,19 +34,26 @@ templ eventReportComponent(e nostr.Tag, report *nostr.Event) {
</span> </span>
{ " report" } { " report" }
</div> </div>
<div>by @userNameComponent(sys.FetchProfileMetadata(ctx, report.PubKey))</div> <div class="text-sm text-gray-500">
<div class="p-3">{ report.Content }</div> { report.CreatedAt.Time().Format("Jan 2, 2006 3:04 PM") }
<div> </div>
event reported: </div>
<div class="text-mono">{ res[0].String() }</div> {{ npub, _ := nip19.EncodePublicKey(report.PubKey) }}
<div class="mt-2 text-sm text-gray-600">by <a class="hover:underline" title={ report.PubKey } href={ templ.SafeURL("nostr:" + npub) }><nostr-name pubkey={ report.PubKey }></nostr-name></a></div>
if report.Content != "" {
<div class="mt-3 p-3 bg-gray-50 rounded">{ report.Content }</div>
}
<div class="mt-3">
<div class="text-sm text-gray-600">event reported:</div>
<div class="mt-1 font-mono text-sm bg-gray-50 p-2 rounded overflow-auto whitespace-pre-wrap break-all">{ res[0].String() }</div>
</div> </div>
</div> </div>
} }
} }
templ profileReportComponent(p nostr.Tag, report *nostr.Event) { templ profileReportComponent(p nostr.Tag, report *nostr.Event) {
if isPublicKeyInWhitelist(p[1]) { <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
<div> <div class="flex justify-between items-start">
<div class="font-lg"> <div class="font-lg">
<span class="font-semibold"> <span class="font-semibold">
if len(p) >= 3 { if len(p) >= 3 {
@ -53,14 +62,23 @@ templ profileReportComponent(p nostr.Tag, report *nostr.Event) {
</span> </span>
{ " report" } { " report" }
</div> </div>
<div>by @userNameComponent(sys.FetchProfileMetadata(ctx, report.PubKey))</div> <div class="text-sm text-gray-500">
<div class="p-3">{ report.Content }</div> { report.CreatedAt.Time().Format("Jan 2, 2006 3:04 PM") }
<div> </div>
profile reported: </div>
<a href={ templ.URL("https://njump.me/p/" + report.PubKey) } target="_blank" class="font-mono py-1"> {{ npub, _ := nip19.EncodePublicKey(report.PubKey) }}
<nostr-name pubkey={ report.PubKey }>{ report.PubKey }</nostr-name> <div class="mt-2 text-sm text-gray-600">by <a class="hover:underline" title={ report.PubKey } href={ templ.SafeURL("nostr:" + npub) }><nostr-name pubkey={ report.PubKey }></nostr-name></a></div>
if report.Content != "" {
<div class="mt-3 p-3 bg-gray-50 rounded">{ report.Content }</div>
}
<div class="mt-3">
<div class="text-sm text-gray-600">profile reported:</div>
<div class="mt-1">
{{ npubt, _ := nip19.EncodePublicKey(p[1]) }}
<a href={ templ.URL("nostr:" + npubt) } target="_blank" class="text-sm hover:underline">
<nostr-name pubkey={ p[1] }></nostr-name>
</a> </a>
</div> </div>
</div> </div>
} </div>
} }