2026-02-27 23:39:08 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
"lmika.dev/lmika/weiro/config"
|
|
|
|
|
"lmika.dev/lmika/weiro/providers/db"
|
|
|
|
|
"lmika.dev/lmika/weiro/services/auth"
|
|
|
|
|
"lmika.dev/lmika/weiro/services/posts"
|
|
|
|
|
"lmika.dev/lmika/weiro/services/publisher"
|
|
|
|
|
"lmika.dev/lmika/weiro/services/sites"
|
2026-03-02 09:48:41 +00:00
|
|
|
"lmika.dev/lmika/weiro/services/uploads"
|
2026-02-27 23:39:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Services struct {
|
|
|
|
|
DB *db.Provider
|
|
|
|
|
Auth *auth.Service
|
|
|
|
|
Publisher *publisher.Publisher
|
|
|
|
|
PublisherQueue *publisher.Queue
|
|
|
|
|
Posts *posts.Service
|
|
|
|
|
Sites *sites.Service
|
2026-03-02 09:48:41 +00:00
|
|
|
Uploads *uploads.Service
|
2026-02-27 23:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New(cfg config.Config) (*Services, error) {
|
|
|
|
|
dbp, err := db.New(filepath.Join(cfg.DataDir, "weiro.db"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
authSvc := auth.New(dbp)
|
|
|
|
|
publisherSvc := publisher.New(dbp)
|
|
|
|
|
publisherQueue := publisher.NewQueue(publisherSvc)
|
|
|
|
|
postService := posts.New(dbp, publisherQueue)
|
|
|
|
|
siteService := sites.New(dbp)
|
2026-03-02 09:48:41 +00:00
|
|
|
uploadService := uploads.New(dbp, filepath.Join(cfg.ScratchDir, "uploads", "pending"))
|
2026-02-27 23:39:08 +00:00
|
|
|
|
|
|
|
|
return &Services{
|
|
|
|
|
DB: dbp,
|
|
|
|
|
Auth: authSvc,
|
|
|
|
|
Publisher: publisherSvc,
|
|
|
|
|
PublisherQueue: publisherQueue,
|
|
|
|
|
Posts: postService,
|
|
|
|
|
Sites: siteService,
|
2026-03-02 09:48:41 +00:00
|
|
|
Uploads: uploadService,
|
2026-02-27 23:39:08 +00:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Services) Close() error {
|
|
|
|
|
return s.DB.Close()
|
|
|
|
|
}
|