mostly web, fixed a regression

This commit is contained in:
farhan 2020-12-29 17:30:26 +00:00
parent 5914fc0890
commit 20fb4ed76a
3 changed files with 7 additions and 11 deletions

View File

@ -22,6 +22,10 @@ const (
KEEPALIVE = 607 KEEPALIVE = 607
) )
type ObjectType struct {
Id string `json:"id"`
}
// Parsing Unmarshal JSON type // Parsing Unmarshal JSON type
type ReportPost struct { type ReportPost struct {

View File

@ -90,7 +90,6 @@ func check_post(uri string) (PostJson, error) {
selectRet := pool.QueryRow(context.Background(), "SELECT id, inReplyTo, published, summary, content, normalized, attributedto, posthash, received_at FROM posts WHERE id = $1", uri) selectRet := pool.QueryRow(context.Background(), "SELECT id, inReplyTo, published, summary, content, normalized, attributedto, posthash, received_at FROM posts WHERE id = $1", uri)
err := selectRet.Scan(&postjson.ID, &postjson.InReplyTo, &postjson.Published, &postjson.Summary, &postjson.Content, &postjson.normalized, &postjson.AttributedTo, &postjson.posthash, &postjson.receivedAt) err := selectRet.Scan(&postjson.ID, &postjson.InReplyTo, &postjson.Published, &postjson.Summary, &postjson.Content, &postjson.normalized, &postjson.AttributedTo, &postjson.posthash, &postjson.receivedAt)
if err == nil { if err == nil {
return postjson, nil return postjson, nil
} }
@ -101,7 +100,6 @@ func check_post(uri string) (PostJson, error) {
} }
postjson.instance = uri[8:endslash+8] postjson.instance = uri[8:endslash+8]
o := GetHTTPSession(postjson.instance) o := GetHTTPSession(postjson.instance)
req, _ := http.NewRequest("GET", uri, nil) req, _ := http.NewRequest("GET", uri, nil)
req.Header.Add("Accept", "application/ld+json") req.Header.Add("Accept", "application/ld+json")
@ -167,7 +165,7 @@ func check_user(uri string) (UserJson, error) {
selectRet := pool.QueryRow(context.Background(), "SELECT id, actor_type, inbox, outbox, followers, following, url, preferredUsername, name, summary, icon, image, publicKey, instance FROM accounts WHERE id = $1", uri) selectRet := pool.QueryRow(context.Background(), "SELECT id, actor_type, inbox, outbox, followers, following, url, preferredUsername, name, summary, icon, image, publicKey, instance FROM accounts WHERE id = $1", uri)
err := selectRet.Scan(&userjson.ID, &userjson.Type, &userjson.Inbox, &userjson.Outbox, &userjson.Followers, &userjson.Following, &userjson.Url, &userjson.PreferredUsername, &userjson.Name, &userjson.Summary, &userjson.Icon.Url, &userjson.Image.Url, &userjson.PublicKey.PublicKeyPem, &userjson.instance) err := selectRet.Scan(&userjson.ID, &userjson.Type, &userjson.Inbox, &userjson.Outbox, &userjson.Followers, &userjson.Following, &userjson.Url, &userjson.PreferredUsername, &userjson.Name, &userjson.Summary, &userjson.Icon.Url, &userjson.Image.Url, &userjson.PublicKey.PublicKeyPem, &userjson.instance)
if err == nil { if err == nil {
return userjson, errors.New("Unable to perform select on " + uri) return userjson, nil
} }
endslash := strings.Index(uri[8:], "/") endslash := strings.Index(uri[8:], "/")
if endslash == -1 { if endslash == -1 {

10
web.go
View File

@ -15,6 +15,7 @@ import (
// CreateObject - Used by post web receiver // CreateObject - Used by post web receiver
type CreateObject struct { type CreateObject struct {
ID string `json:"id"`
Actor string `json:"actor"` Actor string `json:"actor"`
Cc []string `json:"cc"` Cc []string `json:"cc"`
Content string `json:"content"` Content string `json:"content"`
@ -98,8 +99,6 @@ func webfinger(w http.ResponseWriter, r *http.Request) {
func inboxHandler() http.HandlerFunc { func inboxHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
fmt.Println("PATH --> ", r.URL.Path)
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -109,21 +108,16 @@ func inboxHandler() http.HandlerFunc {
var findtype RelayBase var findtype RelayBase
err = json.Unmarshal(body, &findtype) err = json.Unmarshal(body, &findtype)
fmt.Println(string(body))
switch findtype.Type { switch findtype.Type {
case "Create": case "Create":
var createobject CreateObject var createobject CreateObject
var newpost ReportPost
err = json.Unmarshal(findtype.Object, &createobject) err = json.Unmarshal(findtype.Object, &createobject)
if err != nil { if err != nil {
return return
} }
newpost.Uri = findtype.ID go check_post(createobject.ID)
log.Print(newpost.Uri)
case "Like": case "Like":
case "Announcement": case "Announcement":
case "Delete": case "Delete":