89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package combluotion
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"codeberg.org/danjones000/combluotion/config"
|
|
_ "codeberg.org/danjones000/combluotion/imports"
|
|
"codeberg.org/danjones000/combluotion/store"
|
|
vocab "github.com/go-ap/activitypub"
|
|
"github.com/go-ap/client"
|
|
boxap "github.com/go-ap/fedbox/activitypub"
|
|
)
|
|
|
|
func init() {
|
|
client.UserAgent = config.UserAgent
|
|
}
|
|
|
|
type App struct {
|
|
conf config.Config
|
|
self vocab.Service
|
|
user vocab.Person
|
|
version string
|
|
storage store.Store
|
|
client client.C
|
|
}
|
|
|
|
func NewApp(ver string, conf config.Config, db store.Store) (*App, error) {
|
|
if conf.BaseURL() == "" {
|
|
return nil, errors.New("missing BaseURL")
|
|
}
|
|
app := App{
|
|
version: ver,
|
|
conf: conf,
|
|
}
|
|
|
|
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL())
|
|
self := boxap.Self(selfIRI)
|
|
self.Name = vocab.DefaultNaturalLanguageValue(app.Name())
|
|
self.AttributedTo = vocab.IRI(config.DevUrl)
|
|
self.Summary = vocab.DefaultNaturalLanguageValue("ActivityPub-powered reader")
|
|
self.Published = time.Now()
|
|
self.Updated = time.Now()
|
|
|
|
app.self = self
|
|
app.client = *client.New()
|
|
|
|
return &app, nil
|
|
}
|
|
|
|
func (l *App) Config() config.Config {
|
|
return l.conf
|
|
}
|
|
|
|
func (l *App) Environment() config.Env {
|
|
return l.conf.Env()
|
|
}
|
|
|
|
func (l *App) Storage() store.Store {
|
|
return l.storage
|
|
}
|
|
|
|
func (l *App) Service() vocab.Service {
|
|
return l.self
|
|
}
|
|
|
|
func (l *App) ServiceIRI() vocab.IRI {
|
|
return l.self.ID
|
|
}
|
|
|
|
func (l *App) User() vocab.Actor {
|
|
return l.user
|
|
}
|
|
|
|
func (l *App) Version() string {
|
|
return l.version
|
|
}
|
|
|
|
func (l *App) Name() string {
|
|
if l.conf.Name() == "" {
|
|
return "Lenore"
|
|
}
|
|
return l.conf.Name()
|
|
}
|
|
|
|
func (l *App) String() string {
|
|
return fmt.Sprintf("%s (%s)", l.Name(), l.version)
|
|
}
|