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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"github.com/jackc/pgx/pgxpool"
|
"github.com/jackc/pgx/pgxpool"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDbPool() *pgxpool.Pool {
|
func getDbPool() *pgxpool.Pool {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jackc/pgx/pgxpool"
|
||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -8,7 +9,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"github.com/jackc/pgx/pgxpool"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Current instances
|
// Current instances
|
||||||
|
@ -14,13 +14,13 @@ import (
|
|||||||
var p *bluemonday.Policy
|
var p *bluemonday.Policy
|
||||||
var spaceReg *regexp.Regexp
|
var spaceReg *regexp.Regexp
|
||||||
|
|
||||||
func GetRunner(endpoint string) (RunningInstance) {
|
func GetRunner(endpoint string) RunningInstance {
|
||||||
ri_mutex.Lock()
|
ri_mutex.Lock()
|
||||||
o, exists := runninginstances[endpoint]
|
o, exists := runninginstances[endpoint]
|
||||||
if exists == false {
|
if exists == false {
|
||||||
o := RunningInstance{}
|
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.client = http.Client{Transport: tr}
|
||||||
o.Status = KEEPALIVE
|
o.Status = KEEPALIVE
|
||||||
@ -31,15 +31,13 @@ func GetRunner(endpoint string) (RunningInstance) {
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func UpdateRunner(endpoint string, o RunningInstance) {
|
func UpdateRunner(endpoint string, o RunningInstance) {
|
||||||
ri_mutex.Lock()
|
ri_mutex.Lock()
|
||||||
runninginstances[endpoint] = o
|
runninginstances[endpoint] = o
|
||||||
ri_mutex.Unlock()
|
ri_mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNodeInfo(endpoint string, o RunningInstance) RunningInstance {
|
||||||
func GetNodeInfo(endpoint string, o RunningInstance) (RunningInstance) {
|
|
||||||
/* Checking order
|
/* Checking order
|
||||||
* Mastodon/Pleroma
|
* Mastodon/Pleroma
|
||||||
* Um..nothing else yet
|
* Um..nothing else yet
|
||||||
|
12
oauth.go
12
oauth.go
@ -26,7 +26,7 @@ func (e *authError) Error() string {
|
|||||||
return e.msg
|
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{
|
requestBodymap, _ := json.Marshal(map[string]string{
|
||||||
"client_name": "Tusky", // Hard-coded in for now...
|
"client_name": "Tusky", // Hard-coded in for now...
|
||||||
"scopes": "read write follow push",
|
"scopes": "read write follow push",
|
||||||
@ -91,7 +91,7 @@ func register_client(endpoint string, o *RunningInstance) (error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_client(endpoint string, o *RunningInstance) (error) {
|
func get_client(endpoint string, o *RunningInstance) error {
|
||||||
var err error
|
var err error
|
||||||
client_file := "clients/" + endpoint
|
client_file := "clients/" + endpoint
|
||||||
_, err = os.Stat(client_file)
|
_, err = os.Stat(client_file)
|
||||||
@ -100,7 +100,7 @@ func get_client(endpoint string, o *RunningInstance) (error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Unable to open " + client_file + ", creating new client")
|
log.Print("Unable to open " + client_file + ", creating new client")
|
||||||
return err
|
return err
|
||||||
// return register_client(endpoint, o)
|
// return register_client(endpoint, o)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
@ -111,15 +111,15 @@ func get_client(endpoint string, o *RunningInstance) (error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Unable to read client_id line of " + client_file + ", building new client")
|
log.Print("Unable to read client_id line of " + client_file + ", building new client")
|
||||||
return err
|
return err
|
||||||
// return register_client(endpoint, o)
|
// return register_client(endpoint, o)
|
||||||
}
|
}
|
||||||
client_secret_bin, _, err := rd.ReadLine()
|
client_secret_bin, _, err := rd.ReadLine()
|
||||||
o.client_secret = string(client_secret_bin)
|
o.client_secret = string(client_secret_bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Unable to read client_secret line of " + client_file + ", building new client")
|
log.Print("Unable to read client_secret line of " + client_file + ", building new client")
|
||||||
return err
|
return err
|
||||||
// return register_client(endpoint, o)
|
// return register_client(endpoint, o)
|
||||||
// return o
|
// return o
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
33
retrieve.go
33
retrieve.go
@ -2,18 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
"log"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"html"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"html"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImageType struct {
|
type ImageType struct {
|
||||||
// Type string `json:"type"`
|
// Type string `json:"type"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,13 +47,12 @@ type PostJson struct {
|
|||||||
posthash []byte
|
posthash []byte
|
||||||
receivedAt time.Time `json:"created_at"`
|
receivedAt time.Time `json:"created_at"`
|
||||||
|
|
||||||
|
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Conversation string `json:"conversation"`
|
Conversation string `json:"conversation"`
|
||||||
Published time.Time `json:"published"`
|
Published time.Time `json:"published"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
// Ignoring tag for now
|
// Ignoring tag for now
|
||||||
To []string `json:"to"`
|
To []string `json:"to"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ type PostJson struct {
|
|||||||
instance string
|
instance string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHTTPSession(endpoint string) (RunningInstance) {
|
func GetHTTPSession(endpoint string) RunningInstance {
|
||||||
ri_mutex.Lock()
|
ri_mutex.Lock()
|
||||||
o, exist := runninginstances[endpoint]
|
o, exist := runninginstances[endpoint]
|
||||||
ri_mutex.Unlock()
|
ri_mutex.Unlock()
|
||||||
@ -83,7 +82,7 @@ func GetHTTPSession(endpoint string) (RunningInstance) {
|
|||||||
func check_post(uri string) (PostJson, error) {
|
func check_post(uri string) (PostJson, error) {
|
||||||
var postjson PostJson
|
var postjson PostJson
|
||||||
for _, banned := range settings.Banned {
|
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")
|
return postjson, errors.New("Banned instance")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +97,7 @@ func check_post(uri string) (PostJson, error) {
|
|||||||
if endslash == -1 {
|
if endslash == -1 {
|
||||||
return postjson, errors.New("Invalid URI " + uri)
|
return postjson, errors.New("Invalid URI " + uri)
|
||||||
}
|
}
|
||||||
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)
|
||||||
@ -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)
|
_, 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 {
|
if err != nil {
|
||||||
// log.Print("INSERT posts error of " + uri + ": ", err)
|
// log.Print("INSERT posts error of " + uri + ": ", err)
|
||||||
return postjson, err
|
return postjson, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, to := range postjson.To{
|
for _, to := range postjson.To {
|
||||||
if to != "https://www.w3.org/ns/activitystreams#Public" && to != "" {
|
if to != "https://www.w3.org/ns/activitystreams#Public" && to != "" {
|
||||||
go check_user(to)
|
go check_user(to)
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ func check_post(uri string) (PostJson, error) {
|
|||||||
func check_user(uri string) (UserJson, error) {
|
func check_user(uri string) (UserJson, error) {
|
||||||
var userjson UserJson
|
var userjson UserJson
|
||||||
for _, banned := range settings.Banned {
|
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")
|
return userjson, errors.New("Banned instance")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +170,7 @@ func check_user(uri string) (UserJson, error) {
|
|||||||
if endslash == -1 {
|
if endslash == -1 {
|
||||||
return userjson, errors.New("Invalid user: " + uri)
|
return userjson, errors.New("Invalid user: " + uri)
|
||||||
}
|
}
|
||||||
userjson.instance = uri[8:endslash+8]
|
userjson.instance = uri[8 : endslash+8]
|
||||||
|
|
||||||
o := GetHTTPSession(userjson.instance)
|
o := GetHTTPSession(userjson.instance)
|
||||||
req, _ := http.NewRequest("GET", uri, nil)
|
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)
|
_, 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 {
|
if err != nil {
|
||||||
// log.Print("INSERT accounts error: ", err)
|
// log.Print("INSERT accounts error: ", err)
|
||||||
return userjson, 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)
|
resp, err := http_client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Unable to stream " + api_timeline + ": ", err)
|
log.Print("Unable to stream "+api_timeline+": ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@ -70,8 +70,6 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch strings.TrimSpace(token[0]) {
|
switch strings.TrimSpace(token[0]) {
|
||||||
case "event":
|
case "event":
|
||||||
name = strings.TrimSpace(token[1])
|
name = strings.TrimSpace(token[1])
|
||||||
@ -117,10 +115,10 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ri_mutex.Lock()
|
// ri_mutex.Lock()
|
||||||
// m = runninginstances[endpoint]
|
// m = runninginstances[endpoint]
|
||||||
// m.LastRun = time.Now().Format(time.RFC3339)
|
// m.LastRun = time.Now().Format(time.RFC3339)
|
||||||
// m.Status = STREAM_ENDED
|
// m.Status = STREAM_ENDED
|
||||||
// runninginstances[endpoint] = m
|
// runninginstances[endpoint] = m
|
||||||
// ri_mutex.Unlock()
|
// ri_mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
8
web.go
8
web.go
@ -1,16 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "crypto/sha1"
|
// "crypto/sha1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
// "html"
|
// "html"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
// "time"
|
// "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateObject - Used by post web receiver
|
// CreateObject - Used by post web receiver
|
||||||
@ -119,7 +119,7 @@ func inboxHandler() http.HandlerFunc {
|
|||||||
|
|
||||||
go check_post(createobject.ID)
|
go check_post(createobject.ID)
|
||||||
slashend := strings.Index(createobject.ID[8:], "/")
|
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)
|
log.Print("The at sign is: ", newinstance)
|
||||||
|
|
||||||
// Only done if we are crawling
|
// Only done if we are crawling
|
||||||
|
Loading…
x
Reference in New Issue
Block a user