combluotion/app.go

91 lines
1.7 KiB
Go
Raw Normal View History

2024-10-28 13:48:22 -05:00
package combluotion
2024-09-12 16:40:31 -05:00
import (
"errors"
"fmt"
2024-09-14 16:53:53 -05:00
"time"
2024-09-12 16:40:31 -05:00
2024-10-28 13:48:22 -05:00
"codeberg.org/danjones000/combluotion/config"
_ "codeberg.org/danjones000/combluotion/imports"
"codeberg.org/danjones000/combluotion/store"
2024-09-12 16:40:31 -05:00
vocab "github.com/go-ap/activitypub"
"github.com/go-ap/client"
boxap "github.com/go-ap/fedbox/activitypub"
)
2024-09-14 16:53:53 -05:00
func init() {
client.UserAgent = config.UserAgent
}
2024-09-12 16:40:31 -05:00
type App struct {
conf config.Config
self vocab.Service
user vocab.Person
version string
2024-09-14 11:27:28 -05:00
storage store.Store
2024-09-12 16:40:31 -05:00
client client.C
}
2024-09-14 11:27:28 -05:00
func NewApp(ver string, conf config.Config, db store.Store) (*App, error) {
if conf.BaseURL() == "" {
2024-09-14 17:34:47 -05:00
return nil, errors.New("missing BaseURL")
2024-09-12 16:40:31 -05:00
}
app := App{
version: ver,
2024-09-13 17:45:06 -05:00
conf: conf,
2025-01-27 11:41:32 -06:00
storage: db,
2024-09-12 16:40:31 -05:00
}
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL())
2024-09-14 16:53:53 -05:00
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()
2024-09-12 16:40:31 -05:00
app.self = self
app.client = *client.New()
return &app, nil
}
func (l *App) Config() config.Config {
return l.conf
}
2024-09-13 17:45:06 -05:00
func (l *App) Environment() config.Env {
return l.conf.Env()
2024-09-13 17:45:06 -05:00
}
2024-09-14 11:27:28 -05:00
func (l *App) Storage() store.Store {
2024-09-12 16:40:31 -05:00
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
}
2024-09-13 17:45:06 -05:00
func (l *App) Name() string {
if l.conf.Name() == "" {
2024-09-13 17:45:06 -05:00
return "Lenore"
}
return l.conf.Name()
2024-09-13 17:45:06 -05:00
}
2024-09-12 16:40:31 -05:00
func (l *App) String() string {
2024-09-13 17:45:06 -05:00
return fmt.Sprintf("%s (%s)", l.Name(), l.version)
2024-09-12 16:40:31 -05:00
}