summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 9b5c1a6..140b1de 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -20,6 +20,8 @@ import (
"strings"
"sync"
"time"
+
+ "gitlab.com/rhogenson/roseh.moe/internal/wordlist"
)
var (
@@ -119,10 +121,6 @@ func favicon(w http.ResponseWriter, r *http.Request) {
}
var (
- //go:embed wordlist.txt
- wordListString string
- wordList = strings.Split(strings.TrimSuffix(wordListString, "\n"), "\n")
-
//go:embed templates/wormhole.html.template
wormholeTemplateString string
wormholeTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(wormholeTemplateString)).Lookup("outline")
@@ -133,15 +131,19 @@ type wormholeTemplateArgs struct {
Hole string
}
-func wormhole(w http.ResponseWriter, r *http.Request) {
+func makeHole() string {
const nWords = 10
buf := make([]byte, 2*nWords)
rand.Read(buf)
words := make([]string, nWords)
for i := range words {
- words[i] = wordList[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]
+ words[i] = wordlist.Words[binary.NativeEndian.Uint16(buf[2*i:])&0x1fff]
}
- if err := wormholeTemplate.Execute(w, wormholeTemplateArgs{Self: *selfURL, Hole: strings.Join(words, "-")}); err != nil {
+ return strings.Join(words, "-")
+}
+
+func wormhole(w http.ResponseWriter, r *http.Request) {
+ if err := wormholeTemplate.Execute(w, wormholeTemplateArgs{Self: *selfURL, Hole: makeHole()}); err != nil {
log.Printf("Warning: wormhole: %s", err)
}
}
@@ -160,7 +162,7 @@ var wormholeNotify = make(map[string]chan struct{})
func wormholeSend(w http.ResponseWriter, r *http.Request) {
reader, err := r.MultipartReader()
if err != nil {
- http.Error(w, "not a multipart/form-data request", http.StatusBadRequest)
+ http.Error(w, fmt.Sprintf("Not a multipart/form-data request: %s", err), http.StatusBadRequest)
return
}
for {