diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-21 18:49:43 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-21 18:59:56 -0400 |
commit | 4f0847bb24a5df77f88c883461491a2f6fd955d7 (patch) | |
tree | 0f9e2eef1f6bfa4f3a09370730ad8351c1ce24dd | |
parent | 61e81ea7acfc01e8b7ea33156a36c15b0674c79f (diff) | |
download | getwtxt-4f0847bb24a5df77f88c883461491a2f6fd955d7.tar.gz |
runtime bugs related to api output
-rw-r--r-- | cache.go | 8 | ||||
-rw-r--r-- | handlers.go | 2 | ||||
-rw-r--r-- | handlers_test.go | 2 | ||||
-rw-r--r-- | init.go | 2 | ||||
-rw-r--r-- | main.go | 1 | ||||
-rw-r--r-- | post.go | 6 |
6 files changed, 14 insertions, 7 deletions
diff --git a/cache.go b/cache.go index be3d7d3..6220b26 100644 --- a/cache.go +++ b/cache.go @@ -78,11 +78,11 @@ func pushDatabase() error { // be done at one time rather than // per entry. twtxtCache.Mu.RLock() - var dbBasket *leveldb.Batch + var dbBasket = &leveldb.Batch{} for k, v := range twtxtCache.Reg { dbBasket.Put([]byte(k+"*Nick"), []byte(v.Nick)) dbBasket.Put([]byte(k+"*URL"), []byte(v.URL)) - dbBasket.Put([]byte(k+"*IP"), []byte(v.IP)) + dbBasket.Put([]byte(k+"*IP"), []byte(v.IP.String())) dbBasket.Put([]byte(k+"*Date"), []byte(v.Date)) for i, e := range v.Status { rfc := i.Format(time.RFC3339) @@ -151,7 +151,7 @@ func pullDatabase() { for i := 0; i < ref.NumField(); i++ { f := ref.Field(i) - if f.String() == field { + if strings.Contains(f.String(), field) { f.Set(reflect.ValueOf(val)) break } @@ -161,7 +161,7 @@ func pullDatabase() { // If we're looking at a Status entry in the DB, // parse the time then add it to the TimeMap under // data.Status - thetime, err := time.Parse("RFC3339", split[2]) + thetime, err := time.Parse(time.RFC3339, split[2]) if err != nil { log.Printf("%v\n", err) } diff --git a/handlers.go b/handlers.go index 151eb60..2bf74f8 100644 --- a/handlers.go +++ b/handlers.go @@ -78,7 +78,7 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/api/plain/users" { out, err = twtxtCache.QueryUser("") } else if r.URL.Path == "/api/plain/mentions" { - out, err = twtxtCache.QueryInStatus(".txt>") + out, err = twtxtCache.QueryInStatus("@<") } else { out, err = twtxtCache.QueryAllStatuses() } diff --git a/handlers_test.go b/handlers_test.go index f240890..b409521 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -14,6 +14,8 @@ import ( var testport = fmt.Sprintf(":%v", confObj.port) func initTestConf() { + initConfig() + tmpls = initTemplates() logToNull() } diff --git a/init.go b/init.go index 8c96e72..b898ae8 100644 --- a/init.go +++ b/init.go @@ -42,7 +42,7 @@ var twtxtCache = registry.NewIndex() // remote registry listing var remoteRegistries = &RemoteRegistries{} -func init() { +func initGetwtxt() { checkFlags() titleScreen() initConfig() diff --git a/main.go b/main.go index 4d4ebd9..61acb42 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( ) func main() { + initGetwtxt() // StrictSlash(true) allows /api and /api/ // to serve the same content without duplicating diff --git a/post.go b/post.go index e829538..95cc6d3 100644 --- a/post.go +++ b/post.go @@ -20,6 +20,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) { nick := r.FormValue("nickname") urls := r.FormValue("url") if nick == "" || urls == "" { + _, _ = w.Write([]byte("400 Bad Request: Nickname or URL Missing\n")) log400(w, r, fmt.Errorf("nickname or URL missing")) return } @@ -28,6 +29,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) { out, remoteRegistry, err := registry.GetTwtxt(urls) if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err))) log400(w, r, err) return } @@ -39,6 +41,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) { err := twtxtCache.ScrapeRemoteRegistry(urls) if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err))) log400(w, r, err) return } @@ -46,8 +49,9 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) { return } - statuses, err := registry.ParseUserTwtxt(out) + statuses, err := registry.ParseUserTwtxt(out, nick, urls) if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err))) log400(w, r, err) return } |