mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-10 14:55:41 +01:00
Syndicate is working! Instagra & Pixelfed demonstrated with the new post attached. Lots of TODOs, but functional enough :)
44 lines
800 B
Go
44 lines
800 B
Go
package poster
|
|
|
|
import (
|
|
"github.com/by-jp/www.byjp.me/tools/syndicate/shared"
|
|
)
|
|
|
|
type poster struct {
|
|
services map[string]shared.Service
|
|
done map[shared.SyndicationID]string
|
|
}
|
|
|
|
func New(services map[string]shared.Service) *poster {
|
|
return &poster{
|
|
services: services,
|
|
done: make(map[shared.SyndicationID]string),
|
|
}
|
|
}
|
|
|
|
func (p *poster) Connect(sname string) error {
|
|
return p.services[sname].Connect(false)
|
|
}
|
|
|
|
func (p *poster) Post(sid shared.SyndicationID, post shared.Post) error {
|
|
if _, ok := p.done[sid]; ok {
|
|
return nil
|
|
}
|
|
|
|
url, err := p.services[sid.Source].Post(post)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
p.done[sid] = url
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *poster) PostedURL(sid shared.SyndicationID) string {
|
|
if url, ok := p.done[sid]; ok {
|
|
return url
|
|
} else {
|
|
return ""
|
|
}
|
|
}
|