go fmt'ed
This commit is contained in:
parent
b2974b7501
commit
85e0735fa3
2
db.go
2
db.go
@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
"log"
|
||||
)
|
||||
|
||||
func getDbPool() *pgxpool.Pool {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -8,7 +9,6 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sync"
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
)
|
||||
|
||||
// Current instances
|
||||
|
18
headers.go
18
headers.go
@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
type ObjectType struct {
|
||||
Id string `json:"id"`
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
// Parsing Unmarshal JSON type
|
||||
@ -52,14 +52,14 @@ type AccountType struct {
|
||||
|
||||
// Instance's new min_id value
|
||||
type RunningInstance struct {
|
||||
Software string `json:"software"`
|
||||
Version string `json:"version"`
|
||||
Status int `json:"status"`
|
||||
LastRun string `json:"lastrun"`
|
||||
CaptureType string `json:"capturetype"`
|
||||
client http.Client
|
||||
client_id string
|
||||
client_secret string
|
||||
Software string `json:"software"`
|
||||
Version string `json:"version"`
|
||||
Status int `json:"status"`
|
||||
LastRun string `json:"lastrun"`
|
||||
CaptureType string `json:"capturetype"`
|
||||
client http.Client
|
||||
client_id string
|
||||
client_secret string
|
||||
}
|
||||
|
||||
type NodeInfoSoftware struct {
|
||||
|
@ -14,13 +14,13 @@ import (
|
||||
var p *bluemonday.Policy
|
||||
var spaceReg *regexp.Regexp
|
||||
|
||||
func GetRunner(endpoint string) (RunningInstance) {
|
||||
func GetRunner(endpoint string) RunningInstance {
|
||||
ri_mutex.Lock()
|
||||
o, exists := runninginstances[endpoint]
|
||||
if exists == false {
|
||||
o := RunningInstance{}
|
||||
|
||||
tr := &http.Transport {MaxIdleConns: 10, IdleConnTimeout: 7200 * time.Second}
|
||||
tr := &http.Transport{MaxIdleConns: 10, IdleConnTimeout: 7200 * time.Second}
|
||||
|
||||
o.client = http.Client{Transport: tr}
|
||||
o.Status = KEEPALIVE
|
||||
@ -31,15 +31,13 @@ func GetRunner(endpoint string) (RunningInstance) {
|
||||
return o
|
||||
}
|
||||
|
||||
|
||||
func UpdateRunner(endpoint string, o RunningInstance) {
|
||||
ri_mutex.Lock()
|
||||
runninginstances[endpoint] = o
|
||||
ri_mutex.Unlock()
|
||||
}
|
||||
|
||||
|
||||
func GetNodeInfo(endpoint string, o RunningInstance) (RunningInstance) {
|
||||
func GetNodeInfo(endpoint string, o RunningInstance) RunningInstance {
|
||||
/* Checking order
|
||||
* Mastodon/Pleroma
|
||||
* Um..nothing else yet
|
||||
|
12
oauth.go
12
oauth.go
@ -26,7 +26,7 @@ func (e *authError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func register_client(endpoint string, o *RunningInstance) (error) {
|
||||
func register_client(endpoint string, o *RunningInstance) error {
|
||||
requestBodymap, _ := json.Marshal(map[string]string{
|
||||
"client_name": "Tusky", // Hard-coded in for now...
|
||||
"scopes": "read write follow push",
|
||||
@ -91,7 +91,7 @@ func register_client(endpoint string, o *RunningInstance) (error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func get_client(endpoint string, o *RunningInstance) (error) {
|
||||
func get_client(endpoint string, o *RunningInstance) error {
|
||||
var err error
|
||||
client_file := "clients/" + endpoint
|
||||
_, err = os.Stat(client_file)
|
||||
@ -100,7 +100,7 @@ func get_client(endpoint string, o *RunningInstance) (error) {
|
||||
if err != nil {
|
||||
log.Print("Unable to open " + client_file + ", creating new client")
|
||||
return err
|
||||
// return register_client(endpoint, o)
|
||||
// return register_client(endpoint, o)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@ -111,15 +111,15 @@ func get_client(endpoint string, o *RunningInstance) (error) {
|
||||
if err != nil {
|
||||
log.Print("Unable to read client_id line of " + client_file + ", building new client")
|
||||
return err
|
||||
// return register_client(endpoint, o)
|
||||
// return register_client(endpoint, o)
|
||||
}
|
||||
client_secret_bin, _, err := rd.ReadLine()
|
||||
o.client_secret = string(client_secret_bin)
|
||||
if err != nil {
|
||||
log.Print("Unable to read client_secret line of " + client_file + ", building new client")
|
||||
return err
|
||||
// return register_client(endpoint, o)
|
||||
// return o
|
||||
// return register_client(endpoint, o)
|
||||
// return o
|
||||
}
|
||||
|
||||
return nil
|
||||
|
89
retrieve.go
89
retrieve.go
@ -2,68 +2,67 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"time"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"html"
|
||||
"errors"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ImageType struct {
|
||||
// Type string `json:"type"`
|
||||
Url string `json:"url"`
|
||||
// Type string `json:"type"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type PublicKeyType struct {
|
||||
PublicKeyPem string `json:"publicKeyPem"`
|
||||
PublicKeyPem string `json:"publicKeyPem"`
|
||||
}
|
||||
|
||||
type UserJson struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Inbox string `json:"inbox"`
|
||||
Outbox string `json:"outbox"`
|
||||
Followers string `json:"followers"`
|
||||
Following string `json:"following"`
|
||||
Url string `json:"url"`
|
||||
PreferredUsername string `json:"preferredUsername"`
|
||||
Name string `json:"name"`
|
||||
Summary string `json:"summary"`
|
||||
Icon ImageType `json:"icon"`
|
||||
Image ImageType `json:"image"`
|
||||
PublicKey PublicKeyType `json:"publicKey"`
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Inbox string `json:"inbox"`
|
||||
Outbox string `json:"outbox"`
|
||||
Followers string `json:"followers"`
|
||||
Following string `json:"following"`
|
||||
Url string `json:"url"`
|
||||
PreferredUsername string `json:"preferredUsername"`
|
||||
Name string `json:"name"`
|
||||
Summary string `json:"summary"`
|
||||
Icon ImageType `json:"icon"`
|
||||
Image ImageType `json:"image"`
|
||||
PublicKey PublicKeyType `json:"publicKey"`
|
||||
|
||||
instance string
|
||||
instance string
|
||||
}
|
||||
|
||||
type PostJson struct {
|
||||
ID string `json:"id"`
|
||||
InReplyTo string `json:"inReplyTo"`
|
||||
ID string `json:"id"`
|
||||
InReplyTo string `json:"inReplyTo"`
|
||||
|
||||
normalized string
|
||||
posthash []byte
|
||||
receivedAt time.Time `json:"created_at"`
|
||||
|
||||
Content string `json:"content"`
|
||||
Conversation string `json:"conversation"`
|
||||
Published time.Time `json:"published"`
|
||||
Source string `json:"source"`
|
||||
Summary string `json:"summary"`
|
||||
// Ignoring tag for now
|
||||
To []string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
|
||||
Content string `json:"content"`
|
||||
Conversation string `json:"conversation"`
|
||||
Published time.Time `json:"published"`
|
||||
Source string `json:"source"`
|
||||
Summary string `json:"summary"`
|
||||
// Ignoring tag for now
|
||||
To []string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
Actor string `json:"actor"`
|
||||
AttributedTo string `json:"attributedTo"`
|
||||
|
||||
Actor string `json:"actor"`
|
||||
AttributedTo string `json:"attributedTo"`
|
||||
|
||||
instance string
|
||||
instance string
|
||||
}
|
||||
|
||||
func GetHTTPSession(endpoint string) (RunningInstance) {
|
||||
func GetHTTPSession(endpoint string) RunningInstance {
|
||||
ri_mutex.Lock()
|
||||
o, exist := runninginstances[endpoint]
|
||||
ri_mutex.Unlock()
|
||||
@ -83,7 +82,7 @@ func GetHTTPSession(endpoint string) (RunningInstance) {
|
||||
func check_post(uri string) (PostJson, error) {
|
||||
var postjson PostJson
|
||||
for _, banned := range settings.Banned {
|
||||
if strings.Index(uri, "https://" + banned + "/") == 0 {
|
||||
if strings.Index(uri, "https://"+banned+"/") == 0 {
|
||||
return postjson, errors.New("Banned instance")
|
||||
}
|
||||
}
|
||||
@ -98,7 +97,7 @@ func check_post(uri string) (PostJson, error) {
|
||||
if endslash == -1 {
|
||||
return postjson, errors.New("Invalid URI " + uri)
|
||||
}
|
||||
postjson.instance = uri[8:endslash+8]
|
||||
postjson.instance = uri[8 : endslash+8]
|
||||
|
||||
o := GetHTTPSession(postjson.instance)
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
@ -141,11 +140,11 @@ func check_post(uri string) (PostJson, error) {
|
||||
|
||||
_, err = pool.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)
|
||||
if err != nil {
|
||||
// log.Print("INSERT posts error of " + uri + ": ", err)
|
||||
// log.Print("INSERT posts error of " + uri + ": ", err)
|
||||
return postjson, err
|
||||
}
|
||||
|
||||
for _, to := range postjson.To{
|
||||
for _, to := range postjson.To {
|
||||
if to != "https://www.w3.org/ns/activitystreams#Public" && to != "" {
|
||||
go check_user(to)
|
||||
}
|
||||
@ -157,7 +156,7 @@ func check_post(uri string) (PostJson, error) {
|
||||
func check_user(uri string) (UserJson, error) {
|
||||
var userjson UserJson
|
||||
for _, banned := range settings.Banned {
|
||||
if strings.Index(uri, "https://" + banned + "/") == 0 {
|
||||
if strings.Index(uri, "https://"+banned+"/") == 0 {
|
||||
return userjson, errors.New("Banned instance")
|
||||
}
|
||||
}
|
||||
@ -171,7 +170,7 @@ func check_user(uri string) (UserJson, error) {
|
||||
if endslash == -1 {
|
||||
return userjson, errors.New("Invalid user: " + uri)
|
||||
}
|
||||
userjson.instance = uri[8:endslash+8]
|
||||
userjson.instance = uri[8 : endslash+8]
|
||||
|
||||
o := GetHTTPSession(userjson.instance)
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
@ -191,7 +190,7 @@ func check_user(uri string) (UserJson, error) {
|
||||
|
||||
_, err = pool.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)
|
||||
if err != nil {
|
||||
// log.Print("INSERT accounts error: ", err)
|
||||
// log.Print("INSERT accounts error: ", err)
|
||||
return userjson, err
|
||||
}
|
||||
|
||||
|
16
stream.go
16
stream.go
@ -48,7 +48,7 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
||||
|
||||
resp, err := http_client.Do(req)
|
||||
if err != nil {
|
||||
log.Print("Unable to stream " + api_timeline + ": ", err)
|
||||
log.Print("Unable to stream "+api_timeline+": ", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
@ -70,8 +70,6 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch strings.TrimSpace(token[0]) {
|
||||
case "event":
|
||||
name = strings.TrimSpace(token[1])
|
||||
@ -117,10 +115,10 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
||||
}
|
||||
}
|
||||
|
||||
// ri_mutex.Lock()
|
||||
// m = runninginstances[endpoint]
|
||||
// m.LastRun = time.Now().Format(time.RFC3339)
|
||||
// m.Status = STREAM_ENDED
|
||||
// runninginstances[endpoint] = m
|
||||
// ri_mutex.Unlock()
|
||||
// ri_mutex.Lock()
|
||||
// m = runninginstances[endpoint]
|
||||
// m.LastRun = time.Now().Format(time.RFC3339)
|
||||
// m.Status = STREAM_ENDED
|
||||
// runninginstances[endpoint] = m
|
||||
// ri_mutex.Unlock()
|
||||
}
|
||||
|
14
web.go
14
web.go
@ -1,21 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
// "crypto/sha1"
|
||||
// "crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
// "html"
|
||||
// "html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
// "time"
|
||||
// "time"
|
||||
)
|
||||
|
||||
// CreateObject - Used by post web receiver
|
||||
type CreateObject struct {
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Actor string `json:"actor"`
|
||||
Cc []string `json:"cc"`
|
||||
Content string `json:"content"`
|
||||
@ -25,8 +25,8 @@ type CreateObject struct {
|
||||
|
||||
// RelayBase - The base object used by web receiver
|
||||
type RelayBase struct {
|
||||
Actor string `json:"actor"`
|
||||
Cc []string `json:"cc"`
|
||||
Actor string `json:"actor"`
|
||||
Cc []string `json:"cc"`
|
||||
Object json.RawMessage `json:"Object"`
|
||||
ID string `json:"id"`
|
||||
Published string `json:"published"`
|
||||
@ -119,7 +119,7 @@ func inboxHandler() http.HandlerFunc {
|
||||
|
||||
go check_post(createobject.ID)
|
||||
slashend := strings.Index(createobject.ID[8:], "/")
|
||||
newinstance := createobject.ID[8:8+slashend]
|
||||
newinstance := createobject.ID[8 : 8+slashend]
|
||||
log.Print("The at sign is: ", newinstance)
|
||||
|
||||
// Only done if we are crawling
|
||||
|
Loading…
x
Reference in New Issue
Block a user