summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--handlers.go41
-rw-r--r--http.go4
-rw-r--r--http_test.go2
-rw-r--r--post.go19
-rw-r--r--query.go14
5 files changed, 54 insertions, 26 deletions
diff --git a/handlers.go b/handlers.go
index 2bf74f8..947c96a 100644
--- a/handlers.go
+++ b/handlers.go
@@ -7,6 +7,7 @@ import (
 	"log"
 	"net/http"
 	"os"
+	"strings"
 
 	"github.com/gorilla/mux"
 )
@@ -75,19 +76,21 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) {
 	// if there's no query, return everything in
 	// registry for a given endpoint
 	var out []string
-	if r.URL.Path == "/api/plain/users" {
+	switch r.URL.Path {
+	case "/api/plain/users":
 		out, err = twtxtCache.QueryUser("")
-	} else if r.URL.Path == "/api/plain/mentions" {
+
+	case "/api/plain/mentions":
 		out, err = twtxtCache.QueryInStatus("@<")
-	} else {
+
+	default:
 		out, err = twtxtCache.QueryAllStatuses()
 	}
-	if err != nil {
-		log500(w, r, err)
-		return
-	}
 
 	data := parseQueryOut(out)
+	if err != nil {
+		data = []byte("")
+	}
 
 	w.Header().Set("Content-Type", txtutf8)
 
@@ -133,11 +136,33 @@ func apiTagsHandler(w http.ResponseWriter, r *http.Request) {
 	vars := mux.Vars(r)
 	tags := vars["tags"]
 
-	out, err := twtxtCache.QueryInStatus(tags)
+	out, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+	tags = strings.ToLower(tags)
+	out2, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+	tags = strings.Title(tags)
+	out3, err := twtxtCache.QueryInStatus("#" + tags)
 	if err != nil {
 		log500(w, r, err)
 		return
 	}
+	tags = strings.ToUpper(tags)
+	out4, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+
+	out = append(out, out2...)
+	out = append(out, out3...)
+	out = append(out, out4...)
 
 	data := parseQueryOut(out)
 
diff --git a/http.go b/http.go
index b6c1cee..8ba0442 100644
--- a/http.go
+++ b/http.go
@@ -45,10 +45,10 @@ func log200(r *http.Request) {
 }
 
 // log output for 400s
-func log400(w http.ResponseWriter, r *http.Request, err error) {
+func log400(w http.ResponseWriter, r *http.Request, err string) {
 	uip := getIPFromCtx(r.Context())
 	log.Printf("*** %v :: 400 :: %v %v :: %v\n", uip, r.Method, r.URL, err)
-	http.Error(w, "400 Bad Request: "+err.Error(), http.StatusBadRequest)
+	http.Error(w, "400 Bad Request: "+err, http.StatusBadRequest)
 }
 
 // log output for 404s
diff --git a/http_test.go b/http_test.go
index 67ccc88..a3cc90d 100644
--- a/http_test.go
+++ b/http_test.go
@@ -12,7 +12,7 @@ func Test_log400(t *testing.T) {
 	t.Run("log400", func(t *testing.T) {
 		w := httptest.NewRecorder()
 		req := httptest.NewRequest("POST", "/400", nil)
-		log400(w, req, errors.New("400 Test"))
+		log400(w, req, "400 Test")
 		resp := w.Result()
 		if resp.StatusCode != http.StatusBadRequest {
 			t.Errorf("Didn't receive 400, received: %v\n", resp.StatusCode)
diff --git a/post.go b/post.go
index 25d1902..4078cf6 100644
--- a/post.go
+++ b/post.go
@@ -14,13 +14,14 @@ import (
 // registry before adding each user to the local cache.
 func apiPostUser(w http.ResponseWriter, r *http.Request) {
 	if err := r.ParseForm(); err != nil {
-		log400(w, r, err)
+		log400(w, r, err.Error())
 		return
 	}
+
 	nick := r.FormValue("nickname")
 	urls := r.FormValue("url")
 	if nick == "" || urls == "" {
-		log400(w, r, fmt.Errorf("Nickname or URL missing"))
+		log400(w, r, "Nickname or URL missing")
 		return
 	}
 
@@ -28,7 +29,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	out, remoteRegistry, err := registry.GetTwtxt(urls)
 	if err != nil {
-		log400(w, r, err)
+		log400(w, r, err.Error())
 		return
 	}
 
@@ -37,9 +38,8 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 		remoteRegistries.List = append(remoteRegistries.List, urls)
 		remoteRegistries.Mu.Unlock()
 
-		err := twtxtCache.ScrapeRemoteRegistry(urls)
-		if err != nil {
-			log400(w, r, err)
+		if err := twtxtCache.ScrapeRemoteRegistry(urls); err != nil {
+			log400(w, r, err.Error())
 			return
 		}
 		log200(r)
@@ -48,13 +48,12 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	statuses, err := registry.ParseUserTwtxt(out, nick, urls)
 	if err != nil {
-		log400(w, r, err)
+		log400(w, r, err.Error())
 		return
 	}
 
-	err = twtxtCache.AddUser(nick, urls, uip, statuses)
-	if err != nil {
-		log400(w, r, err)
+	if err := twtxtCache.AddUser(nick, urls, uip, statuses); err != nil {
+		log400(w, r, err.Error())
 		return
 	}
 
diff --git a/query.go b/query.go
index c47cfb0..156ccda 100644
--- a/query.go
+++ b/query.go
@@ -55,19 +55,23 @@ func apiEndpointQuery(w http.ResponseWriter, r *http.Request) error {
 	// something went very wrong.
 	switch endpoint {
 	case "users":
-		if urls != "" {
-			out2, err = twtxtCache.QueryUser(urls)
+		if query != "" {
+			out2, err = twtxtCache.QueryUser(query)
 			out = append(out, out2...)
 			apiErrCheck(err, r)
 		}
-		if query != "" {
-			out2, err = twtxtCache.QueryUser(query)
+		if urls != "" {
+			out2, err = twtxtCache.QueryUser(urls)
 			out = append(out, out2...)
 			apiErrCheck(err, r)
 		}
 
 	case "mentions":
-		out, err = twtxtCache.QueryInStatus(query)
+		if urls == "" {
+			return fmt.Errorf("missing URL in mention query")
+		}
+		urls += ">"
+		out, err = twtxtCache.QueryInStatus(urls)
 		apiErrCheck(err, r)
 
 	case "tweets":
d man page for rifle' href='/akspecs/ranger/commit/doc/rifle.1?id=a6836d5d2b809dab92c178c3678317d8c8f00220'>a6836d5d ^
57c2dff1 ^


bd56b253 ^

57c2dff1 ^

a6836d5d ^

57c2dff1 ^




a6836d5d ^

57c2dff1 ^




a6836d5d ^

57c2dff1 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242