deleting comments
This commit is contained in:
parent
39b53ed45c
commit
28fa8ab5ec
25
db.go
25
db.go
@ -5,8 +5,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
// "time"
|
||||
)
|
||||
|
||||
func postHandler(reportPostChan chan ReportPost) {
|
||||
@ -16,29 +14,6 @@ func postHandler(reportPostChan chan ReportPost) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func check_user(uri string) (AccountType, error) {
|
||||
conn, _:= pool.Acquire(context.Background())
|
||||
defer conn.Release()
|
||||
|
||||
var accountData AccountType
|
||||
|
||||
//var q string
|
||||
//var Acct string
|
||||
//err := conn.QueryRow(context.Background(), "SELECT acct, avatar, bot, created_at, display_name FROM accounts WHERE uri = $1", uri).Scan(&accountData.Acct, &(accountData.Avatar), &(q), &accountData.Created_at, &accountData.Display_name)
|
||||
var timez time.Time
|
||||
row := conn.QueryRow(context.Background(), "SELECT acct, avatar, bot, created_at, display_name, FROM accounts WHERE uri = $1", uri)
|
||||
err := row.Scan(&accountData.Acct, &accountData.Avatar, &accountData.Bot, &timez, &accountData.Display_name)
|
||||
if err != nil {
|
||||
return accountData, err
|
||||
}
|
||||
accountData.Url = uri
|
||||
accountData.Created_at = timez.Format(time.RFC3339)
|
||||
spew.Dump(accountData)
|
||||
return accountData, err
|
||||
}
|
||||
*/
|
||||
|
||||
func writePost(reportpost ReportPost) {
|
||||
conn, err := pool.Acquire(context.Background())
|
||||
if err != nil {
|
||||
|
69
poll.go
69
poll.go
@ -50,75 +50,6 @@ type PostInfo struct {
|
||||
Content string `"json:content"`
|
||||
}
|
||||
|
||||
/*
|
||||
func fetch_user_info(http_client http.Client, uri string) (UserInfo, error) {
|
||||
var userinfo UserInfo
|
||||
accounttype, err := check_user(uri)
|
||||
if err == nil {
|
||||
userinfo.Id = uri
|
||||
userinfo.Type = uri
|
||||
if accounttype.Bot {
|
||||
userinfo.Type = "Bot"
|
||||
} else {
|
||||
userinfo.Type = "Person"
|
||||
}
|
||||
userinfo.PreferredUsername = accounttype.Display_name
|
||||
// userInfo.Url = Icon =
|
||||
// userInfo.iconData = ImageData
|
||||
userinfo.Icon.Type = "Image"
|
||||
userinfo.Icon.Url = accounttype.Avatar
|
||||
log.Print("This exit path!!!")
|
||||
return userinfo, nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return UserInfo{}, err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept", "application/ld+json")
|
||||
|
||||
resp, err := http_client.Do(req)
|
||||
if err != nil {
|
||||
return UserInfo{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&userinfo)
|
||||
if err != nil {
|
||||
return UserInfo{}, err
|
||||
}
|
||||
|
||||
return userinfo, nil
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
func fetch_post(http_client http.Client, uri string) (PostInfo, error) {
|
||||
var postinfo PostInfo
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return PostInfo{}, err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept", "application/ld+json")
|
||||
|
||||
resp, err := http_client.Do(req)
|
||||
if err != nil {
|
||||
return PostInfo{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&postinfo)
|
||||
if err != nil {
|
||||
return PostInfo{}, err
|
||||
}
|
||||
|
||||
return postinfo, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_client http.Client) {
|
||||
newposts := make([]ReportPost, 0)
|
||||
|
||||
|
37
retrieve.go
37
retrieve.go
@ -8,8 +8,6 @@ import (
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
"time"
|
||||
"net/http"
|
||||
// "io/ioutil"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
type ImageType struct {
|
||||
@ -95,8 +93,6 @@ func GetHTTPSession(endpoint string) (RunningInstance) {
|
||||
}
|
||||
|
||||
func check_post(uri string) (PostJson, error) {
|
||||
// conn, _:= pool.Acquire(context.Background())
|
||||
// defer conn.Release()
|
||||
connrequest := ConnRequest{}
|
||||
connrequest.conn = make(chan *pgxpool.Conn)
|
||||
connrequest.b = make(chan bool)
|
||||
@ -145,7 +141,7 @@ func check_post(uri string) (PostJson, error) {
|
||||
_, err = myconn.Exec(context.Background(), "INSERT INTO posts (id, inreplyto, published, summary, content, normalized, attributedto, posthash, instance) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)", postjson.ID, postjson.InReplyTo, postjson.Published, postjson.Summary, postjson.Content, postjson.normalized, postjson.AttributedTo, postjson.posthash, postjson.instance)
|
||||
close(connrequest.b)
|
||||
if err != nil {
|
||||
log.Print("INSERT posts ", err)
|
||||
log.Print("INSERT posts error: ", err)
|
||||
return postjson, err
|
||||
}
|
||||
|
||||
@ -159,8 +155,6 @@ func check_post(uri string) (PostJson, error) {
|
||||
}
|
||||
|
||||
func check_user(uri string) (UserJson, error) {
|
||||
// conn, _:= pool.Acquire(context.Background())
|
||||
// defer conn.Release()
|
||||
connrequest := ConnRequest{}
|
||||
connrequest.conn = make(chan *pgxpool.Conn)
|
||||
connrequest.b = make(chan bool)
|
||||
@ -181,19 +175,18 @@ func check_user(uri string) (UserJson, error) {
|
||||
userjson.instance = uri[8:endslash+8]
|
||||
|
||||
o := GetHTTPSession(userjson.instance)
|
||||
//client := http.Client{}
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
req.Header.Add("Accept", "application/ld+json")
|
||||
|
||||
resp, err := o.client.Do(req)
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
log.Print("Retrieval error: ", err)
|
||||
return userjson, err
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&userjson)
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
log.Print("Retrieval error: ", err)
|
||||
return userjson, err
|
||||
}
|
||||
|
||||
@ -206,31 +199,9 @@ func check_user(uri string) (UserJson, error) {
|
||||
_, err = myconn.Exec(context.Background(), "INSERT INTO accounts (id, actor_type, inbox, outbox, followers, following, url, preferredUsername, name, summary, icon, image, publicKey, instance) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", 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)
|
||||
close(connrequest.b)
|
||||
if err != nil {
|
||||
//log.Fatal("INSERT accounts ", err)
|
||||
log.Print("INSERT accounts error: ", err)
|
||||
return userjson, err
|
||||
}
|
||||
|
||||
return userjson, nil
|
||||
}
|
||||
|
||||
//var pool *pgxpool.Pool
|
||||
|
||||
/*
|
||||
func main() {
|
||||
getDbPool()
|
||||
|
||||
// userjson := check_user("https://islamicate.space/users/fikran")
|
||||
// _ = check_user("https://social.farhan.codes/users/testacct555")
|
||||
// postjson := spew.Dump(userjson)
|
||||
|
||||
postjson, err := check_post("https://social.farhan.codes/objects/39cb2c26-153e-4e2e-bb3e-4d6971c04df1")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("The error is: ", err)
|
||||
}
|
||||
|
||||
fmt.Println(postjson)
|
||||
|
||||
// check_post("https://honk.tedunangst.com/u/tedu/h/v1Mz2rgpw1b45g99vS")
|
||||
}
|
||||
*/
|
||||
|
@ -2,10 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
// "crypto/sha1"
|
||||
"encoding/json"
|
||||
// "fmt"
|
||||
// "html"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -29,7 +26,6 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
|
||||
for _, extaccount := range settings.Externalaccounts {
|
||||
if extaccount.Endpoint == endpoint {
|
||||
// use_auth = true
|
||||
get_client(endpoint, &http_client)
|
||||
|
||||
client_id, client_secret, err = get_client(endpoint, &http_client)
|
||||
@ -42,9 +38,6 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
log.Print("Unable to login: ", err)
|
||||
return
|
||||
}
|
||||
// This needs to updated with the time
|
||||
// last_refresh := time.Now().Unix()
|
||||
_ = time.Now().Unix()
|
||||
|
||||
req.Header.Add("Authorization", oauthData.Access_token)
|
||||
|
||||
|
1
web.go
1
web.go
@ -144,7 +144,6 @@ func usersFedilogueFollowers(w http.ResponseWriter, r *http.Request) {
|
||||
followersmap["@context"] = context
|
||||
|
||||
staticjson := "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://" + host + "/schemas/litepub-0.1.jsonld\",{\"@language\":\"und\"}],\"first\":{\"id\":\"https://" + host + "/users/fedilogue/followers?page=1\",\"next\":\"https://" + host + "/users/fedilogue/followers?page=2\",\"orderedItems\":[\"https://mastodon.host/users/federationbot\"],\"partOf\":\"https://" + host + "/users/fedilogue/followers\",\"totalItems\":1,\"type\":\"OrderedCollectionPage\"},\"id\":\"https://" + host + "/users/fedilogue/followers\",\"totalItems\":1,\"type\":\"OrderedCollection\"}"
|
||||
//wtf := "{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://p.farhan.codes/schemas/litepub-0.1.jsonld\",{\"@language\":\"und\"}],\"first\":{\"id\":\"https://p.farhan.codes/users/fedilogue/followers?page=1\",\"next\":\"https://p.farhan.codes/users/fedilogue/followers?page=2\",\"orderedItems\":[\"https://mastodon.host/users/federationbot\"],\"partOf\":\"https://p.farhan.codes/users/fedilogue/followers\",\"totalItems\":1,\"type\":\"OrderedCollectionPage\"},\"id\":\"https://p.farhan.codes/users/fedilogue/followers\",\"totalItems\":1,\"type\":\"OrderedCollection\"}"
|
||||
|
||||
w.Header().Set("Content-Type", "application/activity+json; charset=utf-8")
|
||||
fmt.Fprintf(w, staticjson)
|
||||
|
Loading…
x
Reference in New Issue
Block a user