diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eab603e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +fediverse-archive diff --git a/fediverse-archive b/fediverse-archive deleted file mode 100755 index 86fdf09..0000000 Binary files a/fediverse-archive and /dev/null differ diff --git a/fetcher.go b/fetcher.go index aa3718f..f909977 100644 --- a/fetcher.go +++ b/fetcher.go @@ -1,23 +1,87 @@ package main import ( + "fmt" "github.com/rs/zerolog/log" + "net/http" + "time" + //"github.com/bitly/go-simplejson" ) -// https://mastodon.social/api/v1/timelines/public?limit=40&local=true +const mastodonIndexUrl = "https://instances.social/list.json?q%5Busers%5D=&q%5Bsearch%5D=&strict=false" -func findPleromaInstances() { - //var url = "https://distsn.org/cgi-bin/distsn-pleroma-instances-api.cgi?shuffle" +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 } -func fetchPleromaToots(url string) { - //https://%s/api/statuses/public_and_external_timeline.json?count=100 +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") - }