can simplify a bit with new functions
This commit is contained in:
parent
6645b99169
commit
e1add4f012
29
activity.go
29
activity.go
|
@ -58,9 +58,7 @@ func friendorfoe(ct string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostJunk(keyname string, key *rsa.PrivateKey, url string, j junk.Junk) error {
|
func PostJunk(keyname string, key *rsa.PrivateKey, url string, j junk.Junk) error {
|
||||||
var buf bytes.Buffer
|
return PostMsg(keyname, key, url, j.ToBytes())
|
||||||
j.Write(&buf)
|
|
||||||
return PostMsg(keyname, key, url, buf.Bytes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error {
|
func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error {
|
||||||
|
@ -914,11 +912,7 @@ func rubadubdub(user *WhatAbout, req junk.Junk) {
|
||||||
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
||||||
j["object"] = req
|
j["object"] = req
|
||||||
|
|
||||||
var buf bytes.Buffer
|
deliverate(0, user.Name, actor, j.ToBytes())
|
||||||
j.Write(&buf)
|
|
||||||
msg := buf.Bytes()
|
|
||||||
|
|
||||||
deliverate(0, user.Name, actor, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func itakeitallback(user *WhatAbout, xid string) {
|
func itakeitallback(user *WhatAbout, xid string) {
|
||||||
|
@ -937,11 +931,7 @@ func itakeitallback(user *WhatAbout, xid string) {
|
||||||
j["object"] = f
|
j["object"] = f
|
||||||
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
deliverate(0, user.Name, xid, j.ToBytes())
|
||||||
j.Write(&buf)
|
|
||||||
msg := buf.Bytes()
|
|
||||||
|
|
||||||
deliverate(0, user.Name, xid, msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func subsub(user *WhatAbout, xid string) {
|
func subsub(user *WhatAbout, xid string) {
|
||||||
|
@ -1158,9 +1148,8 @@ var oldjonks = cache.New(cache.Options{Filler: func(xid string) ([]byte, bool) {
|
||||||
donksforhonks([]*Honk{honk})
|
donksforhonks([]*Honk{honk})
|
||||||
_, j := jonkjonk(user, honk)
|
_, j := jonkjonk(user, honk)
|
||||||
j["@context"] = itiswhatitis
|
j["@context"] = itiswhatitis
|
||||||
var buf bytes.Buffer
|
|
||||||
j.Write(&buf)
|
return j.ToBytes(), true
|
||||||
return buf.Bytes(), true
|
|
||||||
}})
|
}})
|
||||||
|
|
||||||
func gimmejonk(xid string) ([]byte, bool) {
|
func gimmejonk(xid string) ([]byte, bool) {
|
||||||
|
@ -1172,9 +1161,7 @@ func gimmejonk(xid string) ([]byte, bool) {
|
||||||
func honkworldwide(user *WhatAbout, honk *Honk) {
|
func honkworldwide(user *WhatAbout, honk *Honk) {
|
||||||
jonk, _ := jonkjonk(user, honk)
|
jonk, _ := jonkjonk(user, honk)
|
||||||
jonk["@context"] = itiswhatitis
|
jonk["@context"] = itiswhatitis
|
||||||
var buf bytes.Buffer
|
msg := jonk.ToBytes()
|
||||||
jonk.Write(&buf)
|
|
||||||
msg := buf.Bytes()
|
|
||||||
|
|
||||||
rcpts := make(map[string]bool)
|
rcpts := make(map[string]bool)
|
||||||
for _, a := range honk.Audience {
|
for _, a := range honk.Audience {
|
||||||
|
@ -1238,9 +1225,7 @@ func junkuser(user *WhatAbout) []byte {
|
||||||
k["publicKeyPem"] = user.Key
|
k["publicKeyPem"] = user.Key
|
||||||
j["publicKey"] = k
|
j["publicKey"] = k
|
||||||
|
|
||||||
var buf bytes.Buffer
|
return j.ToBytes()
|
||||||
j.Write(&buf)
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldjonkers = cache.New(cache.Options{Filler: func(name string) ([]byte, bool) {
|
var oldjonkers = cache.New(cache.Options{Filler: func(name string) ([]byte, bool) {
|
||||||
|
|
8
web.go
8
web.go
|
@ -290,7 +290,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
io.Copy(&buf, r.Body)
|
io.Copy(&buf, r.Body)
|
||||||
payload := buf.Bytes()
|
payload := buf.Bytes()
|
||||||
j, err := junk.Read(bytes.NewReader(payload))
|
j, err := junk.FromBytes(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("bad payload: %s", err)
|
log.Printf("bad payload: %s", err)
|
||||||
io.WriteString(os.Stdout, "bad payload\n")
|
io.WriteString(os.Stdout, "bad payload\n")
|
||||||
|
@ -418,7 +418,7 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
io.Copy(&buf, r.Body)
|
io.Copy(&buf, r.Body)
|
||||||
payload := buf.Bytes()
|
payload := buf.Bytes()
|
||||||
j, err := junk.Read(bytes.NewReader(payload))
|
j, err := junk.FromBytes(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("bad payload: %s", err)
|
log.Printf("bad payload: %s", err)
|
||||||
io.WriteString(os.Stdout, "bad payload\n")
|
io.WriteString(os.Stdout, "bad payload\n")
|
||||||
|
@ -539,9 +539,7 @@ var oldoutbox = cache.New(cache.Options{Filler: func(name string) ([]byte, bool)
|
||||||
j["totalItems"] = len(jonks)
|
j["totalItems"] = len(jonks)
|
||||||
j["orderedItems"] = jonks
|
j["orderedItems"] = jonks
|
||||||
|
|
||||||
var buf bytes.Buffer
|
return j.ToBytes(), true
|
||||||
j.Write(&buf)
|
|
||||||
return buf.Bytes(), true
|
|
||||||
}, Duration: 1 * time.Minute})
|
}, Duration: 1 * time.Minute})
|
||||||
|
|
||||||
func outbox(w http.ResponseWriter, r *http.Request) {
|
func outbox(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
Loading…
Reference in New Issue