WIP: Node. New generation #1

Draft
Difrex wants to merge 18 commits from ssr into master
3 changed files with 23 additions and 12 deletions
Showing only changes of commit 1fc788acf0 - Show all commits

View File

@ -80,13 +80,8 @@ func (es ESConf) UEHandler(w http.ResponseWriter, r *http.Request) {
LogRequest(r) LogRequest(r)
ch := make(chan []string)
// Get echolist // Get echolist
go func() { messages := es.GetUEchoMessageHashes(e)
ch <- es.GetUEchoMessageHashes(e)
}()
messages := <-ch
w.WriteHeader(200) w.WriteHeader(200)
w.Write([]byte(strings.Join(messages, "\n"))) w.Write([]byte(strings.Join(messages, "\n")))

View File

@ -114,11 +114,16 @@ func (es ESConf) GetEchoMessageHashes(echo string) []string {
} }
defer resp.Body.Close() defer resp.Body.Close()
var esr ESSearchResp content, err := ioutil.ReadAll(resp.Body)
err = json.NewDecoder(resp.Body).Decode(&esr) if err != nil {
log.Error(err.Error())
hashes = append(hashes, "error: Internal error")
return hashes
}
var esr ESSearchResp
err = json.Unmarshal(content, &esr)
if err != nil { if err != nil {
b, _ := ioutil.ReadAll(resp.Body)
log.Error(string(b))
log.Error(err.Error()) log.Error(err.Error())
hashes = append(hashes, "error: Internal error") hashes = append(hashes, "error: Internal error")
return hashes return hashes
@ -325,7 +330,7 @@ func (es ESConf) GetUEchoMessageHashes(echoes string) []string {
// Some20SimbolsHash333 // Some20SimbolsHash333
for k, v := range eh { for k, v := range eh {
echohashes = append(echohashes, k) echohashes = append(echohashes, k)
if k == "" { if k == "" || k == "\n" {
continue continue
} }
for _, e := range v { for _, e := range v {
@ -336,7 +341,7 @@ func (es ESConf) GetUEchoMessageHashes(echoes string) []string {
} }
} }
return echohashes return addNewLineToLastWord(echohashes)
} }
// GetXC implements /x/c // GetXC implements /x/c
@ -497,6 +502,7 @@ func (es ESConf) GetThreads(pageNum int, echoes ...string) (posts []i2es.ESDoc)
from := 30 * pageNum from := 30 * pageNum
rangeStr = fmt.Sprintf(`"from":"now-%dd","to":"now-%dd"`, from, to) rangeStr = fmt.Sprintf(`"from":"now-%dd","to":"now-%dd"`, from, to)
} }
log.Debug(rangeStr) log.Debug(rangeStr)
query := `{"sort":[{"date":{"order":"desc"}}],"aggs":{"topics":{"terms":{"field":"topicid.keyword","size":100},"aggs":{"post":{"top_hits":{"size":1,"sort":[{"date":{"order":"desc"}}],"_source":{"include": ["subg","author","date","echo","topicid","address", "repto"]}}}}}},"query":{"bool":{"must":[{"range":{"date":{` + rangeStr + `}}},{"constant_score":{"filter":{"terms":{"echo.keyword": [` + query := `{"sort":[{"date":{"order":"desc"}}],"aggs":{"topics":{"terms":{"field":"topicid.keyword","size":100},"aggs":{"post":{"top_hits":{"size":1,"sort":[{"date":{"order":"desc"}}],"_source":{"include": ["subg","author","date","echo","topicid","address", "repto"]}}}}}},"query":{"bool":{"must":[{"range":{"date":{` + rangeStr + `}}},{"constant_score":{"filter":{"terms":{"echo.keyword": [` +

View File

@ -11,6 +11,16 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
func addNewLineToLastWord(slice []string) []string {
l := len(slice) - 1
word := slice[l]
if strings.Contains(word, "\n") {
return slice
}
slice[l] = word + "\n"
return slice
}
func hashAndSalt(authString []byte) string { func hashAndSalt(authString []byte) string {
hash, err := bcrypt.GenerateFromPassword(authString, bcrypt.MinCost) hash, err := bcrypt.GenerateFromPassword(authString, bcrypt.MinCost)
if err != nil { if err != nil {