88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/rs/zerolog/log"
|
|
"net/http"
|
|
"time"
|
|
//"github.com/bitly/go-simplejson"
|
|
)
|
|
|
|
const mastodonIndexUrl = "https://instances.social/list.json?q%5Busers%5D=&q%5Bsearch%5D=&strict=false"
|
|
|
|
const pleromaIndexUrl = "https://distsn.org/cgi-bin/distsn-pleroma-instances-api.cgi"
|
|
|
|
type InstanceLocator struct {
|
|
pleromaIndexLastRefresh *time.Time
|
|
mastodonIndexLastRefresh *time.Time
|
|
instances map[string]Instance
|
|
}
|
|
|
|
type ServerImplementation int
|
|
|
|
const (
|
|
Mastodon ServerImplementation = iota + 1
|
|
Pleorama
|
|
)
|
|
|
|
type Instance struct {
|
|
hostName string
|
|
impl ServerImplementation
|
|
errorCount uint
|
|
lastFetch *time.Time
|
|
highestId int
|
|
skip bool
|
|
}
|
|
|
|
func NewInstance(hostname string) *Instance {
|
|
i := new(Instance)
|
|
i.hostName = hostname
|
|
i.detectNodeType()
|
|
return i
|
|
}
|
|
|
|
func (i *Instance) detectNodeType() {
|
|
if i.impl == 0 {
|
|
return
|
|
}
|
|
}
|
|
|
|
func (i *Instance) fetchNodeInfo() {
|
|
url := fmt.Sprintf("https://%s/.well-known/nodeinfo")
|
|
var c = &http.Client{
|
|
Timeout: time.Second * 10,
|
|
}
|
|
response, err := c.Get(url)
|
|
if err != nil {
|
|
log.Debug().Msg("unable to fetch nodeinfo, node is down?")
|
|
i.skip = true
|
|
}
|
|
|
|
log.Debug().Msg(fmt.Sprintf("%#v", response))
|
|
}
|
|
|
|
func (i *Instance) fetchRecentToots() ([]byte, error) {
|
|
if i.impl == Mastodon {
|
|
return i.fetchRecentTootsJsonFromMastodon()
|
|
} else if i.impl == Pleorama {
|
|
return i.fetchRecentTootsJsonFromPleorama()
|
|
} else {
|
|
panic("nope")
|
|
}
|
|
}
|
|
|
|
func (i *Instance) fetchRecentTootsJsonFromPleorama() ([]byte, error) {
|
|
//url := fmt.Sprintf("https://%s/api/statuses/public_and_external_timeline.json?count=100", i.hostName)
|
|
return nil, nil
|
|
}
|
|
|
|
func (i *Instance) fetchRecentTootsJsonFromMastodon() ([]byte, error) {
|
|
//url := fmt.Sprintf("https://%s/api/v1/timelines/public?limit=40&local=true", i.hostName)
|
|
return nil, nil
|
|
}
|
|
|
|
func fetchLatestToots(lastId int) {
|
|
log.Debug().Msg("This message appears only when log level set to Debug")
|
|
log.Info().Msg("This message appears when log level set to Debug or Info")
|
|
}
|