2023-09-06 20:49:18 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-02 09:29:54 -03:00
|
|
|
"fmt"
|
2023-09-06 20:49:18 +02:00
|
|
|
"net/http"
|
2023-10-11 00:19:33 +02:00
|
|
|
|
2023-11-02 20:59:50 -03:00
|
|
|
"github.com/nbd-wtf/go-nostr"
|
2023-10-28 21:40:54 -03:00
|
|
|
"github.com/nbd-wtf/go-nostr/nip19"
|
2023-10-18 11:58:09 -03:00
|
|
|
"github.com/theplant/htmlgo"
|
2023-09-06 20:49:18 +02:00
|
|
|
)
|
|
|
|
|
2023-10-11 00:19:33 +02:00
|
|
|
func inviteTreeHandler(w http.ResponseWriter, r *http.Request) {
|
2023-10-28 21:40:54 -03:00
|
|
|
content := inviteTreePageHTML(r.Context(), InviteTreePageParams{
|
2023-11-02 16:08:53 -03:00
|
|
|
loggedUser: getLoggedUser(r),
|
2023-10-28 21:40:54 -03:00
|
|
|
})
|
2023-10-18 11:58:09 -03:00
|
|
|
htmlgo.Fprint(w, baseHTML(content), r.Context())
|
2023-10-11 00:19:33 +02:00
|
|
|
}
|
2023-09-07 13:06:58 +02:00
|
|
|
|
2023-10-28 20:21:15 -03:00
|
|
|
func addToWhitelistHandler(w http.ResponseWriter, r *http.Request) {
|
2023-10-28 21:40:54 -03:00
|
|
|
loggedUser := getLoggedUser(r)
|
|
|
|
|
2023-10-28 20:21:15 -03:00
|
|
|
pubkey := r.PostFormValue("pubkey")
|
2023-10-28 21:40:54 -03:00
|
|
|
if pfx, value, err := nip19.Decode(pubkey); err == nil && pfx == "npub" {
|
|
|
|
pubkey = value.(string)
|
|
|
|
}
|
|
|
|
|
2024-02-05 11:32:41 -03:00
|
|
|
if loggedUser != s.RelayPubkey && hasInvitedAtLeast(loggedUser, s.MaxInvitesPerPerson) {
|
2024-02-02 09:29:54 -03:00
|
|
|
http.Error(w, fmt.Sprintf("cannot invite more than %d", s.MaxInvitesPerPerson), 403)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-29 13:45:46 -03:00
|
|
|
if err := addToWhitelist(pubkey, loggedUser); err != nil {
|
2023-10-28 20:21:15 -03:00
|
|
|
http.Error(w, "failed to add to whitelist: "+err.Error(), 500)
|
|
|
|
return
|
|
|
|
}
|
2023-11-02 16:08:53 -03:00
|
|
|
|
2023-11-02 10:08:33 -03:00
|
|
|
content := inviteTreeComponent(r.Context(), "", loggedUser)
|
2023-10-28 20:21:15 -03:00
|
|
|
htmlgo.Fprint(w, content, r.Context())
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeFromWhitelistHandler(w http.ResponseWriter, r *http.Request) {
|
2023-10-28 21:40:54 -03:00
|
|
|
loggedUser := getLoggedUser(r)
|
2023-10-28 20:21:15 -03:00
|
|
|
pubkey := r.PostFormValue("pubkey")
|
2023-10-29 13:45:46 -03:00
|
|
|
if err := removeFromWhitelist(pubkey, loggedUser); err != nil {
|
2023-10-28 20:21:15 -03:00
|
|
|
http.Error(w, "failed to remove from whitelist: "+err.Error(), 500)
|
|
|
|
return
|
|
|
|
}
|
2023-11-02 10:08:33 -03:00
|
|
|
content := inviteTreeComponent(r.Context(), "", loggedUser)
|
2023-10-28 20:21:15 -03:00
|
|
|
htmlgo.Fprint(w, content, r.Context())
|
|
|
|
}
|
|
|
|
|
2023-10-11 00:19:33 +02:00
|
|
|
func reportsViewerHandler(w http.ResponseWriter, r *http.Request) {
|
2023-11-02 20:59:50 -03:00
|
|
|
events, err := db.QueryEvents(r.Context(), nostr.Filter{
|
|
|
|
Kinds: []int{1984},
|
|
|
|
Limit: 52,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, "failed to query reports: "+err.Error(), 500)
|
|
|
|
return
|
|
|
|
}
|
2023-10-18 11:58:09 -03:00
|
|
|
|
2023-11-02 20:59:50 -03:00
|
|
|
content := reportsPageHTML(r.Context(), ReportsPageParams{
|
|
|
|
reports: events,
|
|
|
|
loggedUser: getLoggedUser(r),
|
|
|
|
})
|
|
|
|
htmlgo.Fprint(w, content, r.Context())
|
2023-09-07 13:06:58 +02:00
|
|
|
}
|
2024-11-01 00:19:37 -03:00
|
|
|
|
|
|
|
func joubleHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintf(w, `
|
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
2024-11-14 13:51:10 -03:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2024-11-01 00:19:37 -03:00
|
|
|
<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://unpkg.com/jouble/dist/index.js"></script>
|
|
|
|
<link rel="stylesheet" crossorigin href="https://unpkg.com/jouble/dist/index.css">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<div id="root"></div>
|
|
|
|
<script src="https://unpkg.com/window.nostr.js/dist/window.nostr.js"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`)
|
|
|
|
}
|