formatting and linting
This commit is contained in:
parent
8d56747f1c
commit
726ac7e0bd
13
config.go
13
config.go
@ -1,12 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"muzzammil.xyz/jsonc"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"muzzammil.xyz/jsonc"
|
||||
)
|
||||
|
||||
// Database - Database configuration used by config.go
|
||||
type Database struct {
|
||||
Host string `"json:host"`
|
||||
Port int `"json:port"`
|
||||
@ -15,6 +16,7 @@ type Database struct {
|
||||
Workers int `"json:workers"`
|
||||
}
|
||||
|
||||
// MassFollower - Mass follower configuration used by config.go
|
||||
type MassFollower struct {
|
||||
Acct string `"json:acct"`
|
||||
Name string `"json:name"`
|
||||
@ -23,6 +25,7 @@ type MassFollower struct {
|
||||
FollowLimit int `"json:followlimit"`
|
||||
}
|
||||
|
||||
// ExtAccount - External account configuration used by config.go
|
||||
type ExtAccount struct {
|
||||
Username string `"json:username"`
|
||||
Password string `"json:password"`
|
||||
@ -30,6 +33,7 @@ type ExtAccount struct {
|
||||
Followlimit int `"json:followlimit"`
|
||||
}
|
||||
|
||||
// Proxy - Configuration file proxy settings
|
||||
type Proxy struct {
|
||||
Host string `"json:host"`
|
||||
Port int `"json:port"`
|
||||
@ -37,6 +41,7 @@ type Proxy struct {
|
||||
Password string `"json:password"`
|
||||
}
|
||||
|
||||
// Settings - Configuration file structure
|
||||
type Settings struct {
|
||||
Autostart []string `"json:autostart"`
|
||||
Crawl bool `"json:crawl"`
|
||||
@ -50,7 +55,7 @@ type Settings struct {
|
||||
|
||||
var settings Settings
|
||||
|
||||
func StringExists(needle string, haystack []string) (bool) {
|
||||
func stringexists(needle string, haystack []string) bool {
|
||||
for _, check := range haystack {
|
||||
if check == needle {
|
||||
return true
|
||||
@ -61,7 +66,7 @@ func StringExists(needle string, haystack []string) (bool) {
|
||||
|
||||
func getSettings() {
|
||||
c, err := ioutil.ReadFile("config.jsonc")
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
log.Fatal("Unable to open config.jsonc, exiting: ", err)
|
||||
}
|
||||
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON
|
||||
|
5
ctl.go
5
ctl.go
@ -4,9 +4,9 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"log"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -90,7 +90,6 @@ func handleClient(commandClient net.Conn, reportPostChan chan ReportPost) {
|
||||
fmt.Println("Something else")
|
||||
}
|
||||
|
||||
|
||||
responseback.Type = "status"
|
||||
responseback.RunningInstances = runninginstances
|
||||
|
||||
|
10
db.go
10
db.go
@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
"context"
|
||||
"log"
|
||||
"fmt"
|
||||
"github.com/jackc/pgx/pgxpool"
|
||||
"log"
|
||||
)
|
||||
|
||||
func postHandler(reportPostChan chan ReportPost, pool *pgxpool.Pool) {
|
||||
@ -57,10 +57,10 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
|
||||
}
|
||||
}
|
||||
|
||||
func get_db_pool() (*pgxpool.Pool) {
|
||||
func getDbPool() *pgxpool.Pool {
|
||||
// Setup Database
|
||||
db_uri := fmt.Sprintf("postgres://%s:%s@%s:%d/fedilogue", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port)
|
||||
pool, err := pgxpool.Connect(context.Background(), db_uri)
|
||||
dbURI := fmt.Sprintf("postgres://%s:%s@%s:%d/fedilogue", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port)
|
||||
pool, err := pgxpool.Connect(context.Background(), dbURI)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to connect to database:", err)
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"io"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
12
fedilogue.go
12
fedilogue.go
@ -1,13 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "net/http/pprof"
|
||||
"net/http"
|
||||
"sync"
|
||||
"regexp"
|
||||
"log"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Current instances
|
||||
@ -27,7 +27,7 @@ func main() {
|
||||
getSettings()
|
||||
go startpprof()
|
||||
|
||||
pool := get_db_pool()
|
||||
pool := getDbPool()
|
||||
|
||||
for i := 0; i < settings.Database.Workers; i++ {
|
||||
go postHandler(reportPostChan, pool)
|
||||
|
@ -90,4 +90,3 @@ type Userinfo struct {
|
||||
ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
|
||||
Discoverable string `"json:discoverable"`
|
||||
}
|
||||
|
||||
|
10
instance.go
10
instance.go
@ -1,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"encoding/json"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"regexp"
|
||||
"time"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var p *bluemonday.Policy
|
||||
|
10
oauth.go
10
oauth.go
@ -1,13 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"bytes"
|
||||
"bufio"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
14
poll.go
14
poll.go
@ -1,15 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"html"
|
||||
"time"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type ImageData struct {
|
||||
@ -37,7 +37,6 @@ type UserInfo struct {
|
||||
Summary string `"json:summary"`
|
||||
Url string `"json:Url"`
|
||||
|
||||
|
||||
// ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
|
||||
// Discoverable bool `"json:discoverable"`
|
||||
}
|
||||
@ -75,7 +74,6 @@ func fetch_user_info(http_client http.Client, uri string) (UserInfo, error) {
|
||||
return userinfo, nil
|
||||
}
|
||||
|
||||
|
||||
func fetch_post(http_client http.Client, uri string) (PostInfo, error) {
|
||||
var postinfo PostInfo
|
||||
|
||||
@ -118,7 +116,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
|
||||
for _, extaccount := range settings.Externalaccounts {
|
||||
if extaccount.Endpoint == endpoint {
|
||||
use_auth = true
|
||||
client_id, client_secret, err = get_client(endpoint, &http_client);
|
||||
client_id, client_secret, err = get_client(endpoint, &http_client)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to register client: ", err)
|
||||
}
|
||||
@ -303,7 +301,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
|
||||
}
|
||||
|
||||
// Only done if we are crawling
|
||||
if settings.Crawl == true && StringExists(endpoint, settings.Banned) == false {
|
||||
if settings.Crawl == true && stringexists(endpoint, settings.Banned) == false {
|
||||
// Skip over this if its the same as the endpoint
|
||||
if newinstance == endpoint {
|
||||
continue
|
||||
|
17
stream.go
17
stream.go
@ -1,15 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"crypto/sha1"
|
||||
"strings"
|
||||
"bufio"
|
||||
"time"
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
@ -32,7 +32,7 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
// use_auth = true
|
||||
get_client(endpoint, &http_client)
|
||||
|
||||
client_id, client_secret, err = get_client(endpoint, &http_client);
|
||||
client_id, client_secret, err = get_client(endpoint, &http_client)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to register client: ", err)
|
||||
}
|
||||
@ -46,7 +46,6 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
// last_refresh := time.Now().Unix()
|
||||
_ = time.Now().Unix()
|
||||
|
||||
|
||||
req.Header.Add("Authorization", oauthData.Access_token)
|
||||
|
||||
}
|
||||
@ -168,7 +167,7 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
|
||||
// Reporting post
|
||||
reportPostChan <- newpost
|
||||
|
||||
if settings.Crawl == true && StringExists(endpoint, settings.Banned) == false {
|
||||
if settings.Crawl == true && stringexists(endpoint, settings.Banned) == false {
|
||||
ri_mutex.Lock()
|
||||
o, exists := runninginstances[newinstance]
|
||||
if exists == false || o.Status == KEEPALIVE {
|
||||
|
41
web.go
41
web.go
@ -1,18 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"html"
|
||||
"time"
|
||||
"strings"
|
||||
"crypto/sha1"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CreateObject - Used by post web receiver
|
||||
type CreateObject struct {
|
||||
Actor string `json:"actor"`
|
||||
Cc []string `json:"cc"`
|
||||
@ -21,12 +22,13 @@ type CreateObject struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// CreateObject - Used by post web receiver
|
||||
type FindType struct {
|
||||
Actor string `json:"actor"`
|
||||
Cc []string `json:"cc"`
|
||||
//Object interface{} `json:"Object"`
|
||||
Object json.RawMessage `json:"Object"`
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Published string `json:"published"`
|
||||
To []string `json:"to"`
|
||||
Type string `json:"type"`
|
||||
@ -98,7 +100,6 @@ func webfinger(w http.ResponseWriter, r *http.Request) {
|
||||
func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
fmt.Println("PATH --> ", r.URL.Path)
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
@ -122,19 +123,19 @@ func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
newpost.Uri = findtype.Id
|
||||
newpost.Uri = findtype.ID
|
||||
|
||||
start_slashes := strings.Index(createobject.Actor, "//") + 2
|
||||
end_slashes := strings.Index(createobject.Actor[start_slashes:], "/")
|
||||
newinstance := createobject.Actor[start_slashes:start_slashes+end_slashes]
|
||||
startSlashes := strings.Index(createobject.Actor, "//") + 2
|
||||
endSlashes := strings.Index(createobject.Actor[startSlashes:], "/")
|
||||
newinstance := createobject.Actor[startSlashes : startSlashes+endSlashes]
|
||||
|
||||
// For now we are just verifying the user
|
||||
ri_mutex.Lock()
|
||||
o, exist := runninginstances[newinstance]
|
||||
if exist == false {
|
||||
o := RunningInstance{}
|
||||
new_client := http.Client{}
|
||||
o.client = new_client
|
||||
newClient := http.Client{}
|
||||
o.client = newClient
|
||||
o.Status = KEEPALIVE
|
||||
runninginstances[newinstance] = o
|
||||
}
|
||||
@ -176,7 +177,7 @@ func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func users_fedilogue_followers(w http.ResponseWriter, r *http.Request) {
|
||||
func usersFedilogueFollowers(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("PATH --> ", r.URL.Path)
|
||||
host := r.Host
|
||||
contextlist := map[string]string{"@language": "und"}
|
||||
@ -192,7 +193,7 @@ func users_fedilogue_followers(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, staticjson)
|
||||
}
|
||||
|
||||
func users_fedilogue_following(w http.ResponseWriter, r *http.Request) {
|
||||
func usersFedilogueFollowing(w http.ResponseWriter, r *http.Request) {
|
||||
host := r.Host
|
||||
fmt.Println("PATH --> ", r.URL.Path)
|
||||
staticjson := "{\"@context\": [\"https://www.w3.org/ns/activitystreams\", \"https://" + host + "/schemas/litepub-0.1.jsonld\", {\"@language\": \"und\"}], \"first\": {\"id\": \"https://" + host + "/users/fedilogue/following?page=1\", \"orderedItems\": [], \"partOf\": \"https://" + host + "/users/fedilogue/following\", \"totalItems\": 0, \"type\": \"OrderedCollectionPage\"}, \"id\": \"https://" + host + "/users/fedilogue/following\", \"totalItems\": 0, \"type\": \"OrderedCollection\"}"
|
||||
@ -200,7 +201,7 @@ func users_fedilogue_following(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, staticjson)
|
||||
}
|
||||
|
||||
func users_fedilogue(w http.ResponseWriter, r *http.Request) {
|
||||
func usersFedilogue(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("PATH --> ", r.URL.Path)
|
||||
host := r.Host
|
||||
|
||||
@ -263,9 +264,9 @@ func webmain(reportPostChan chan ReportPost) {
|
||||
http.HandleFunc("/.well-known/webfinger", webfinger)
|
||||
http.HandleFunc("/.well-known/host-meta", hostmeta)
|
||||
http.HandleFunc("/inbox", inboxHandler(reportPostChan))
|
||||
http.HandleFunc("/users/fedilogue", users_fedilogue)
|
||||
http.HandleFunc("/users/fedilogue/followers", users_fedilogue_followers)
|
||||
http.HandleFunc("/users/fedilogue/following", users_fedilogue_following)
|
||||
http.HandleFunc("/users/fedilogue", usersFedilogue)
|
||||
http.HandleFunc("/users/fedilogue/followers", usersFedilogueFollowers)
|
||||
http.HandleFunc("/users/fedilogue/following", usersFedilogueFollowing)
|
||||
http.HandleFunc("/", errorHandler)
|
||||
log.Print("Starting HTTP inbox on port 8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
|
Loading…
x
Reference in New Issue
Block a user