server and web app

This commit is contained in:
2026-05-31 23:08:53 -04:00
parent 438b3b29a2
commit b3364447a1
24 changed files with 2318 additions and 153 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/go-chi/chi/v5/middleware"
"github.com/tim/cairnquire/apps/server/internal/auth"
"github.com/tim/cairnquire/apps/server/internal/collaboration"
"github.com/tim/cairnquire/apps/server/internal/config"
"github.com/tim/cairnquire/apps/server/internal/docs"
"github.com/tim/cairnquire/apps/server/internal/realtime"
@@ -24,30 +25,32 @@ import (
var assets embed.FS
type Dependencies struct {
Config config.Config
Logger *slog.Logger
Documents *docs.Service
Repository *docs.Repository
ContentStore *store.ContentStore
Hub *realtime.Hub
SyncService *sync.Service
SyncRepo *sync.Repository
Auth *auth.Service
Config config.Config
Logger *slog.Logger
Documents *docs.Service
Repository *docs.Repository
ContentStore *store.ContentStore
Hub *realtime.Hub
SyncService *sync.Service
SyncRepo *sync.Repository
Auth *auth.Service
Collaboration *collaboration.Service
}
type Server struct {
config config.Config
logger *slog.Logger
documents *docs.Service
repository *docs.Repository
contentStore *store.ContentStore
hub *realtime.Hub
syncService *sync.Service
syncRepo *sync.Repository
auth *auth.Service
authLimiter *rateLimiter
templates *template.Template
webEnabled bool
config config.Config
logger *slog.Logger
documents *docs.Service
repository *docs.Repository
contentStore *store.ContentStore
hub *realtime.Hub
syncService *sync.Service
syncRepo *sync.Repository
auth *auth.Service
collaboration *collaboration.Service
authLimiter *rateLimiter
templates *template.Template
webEnabled bool
}
func New(deps Dependencies) (http.Handler, error) {
@@ -64,17 +67,18 @@ func New(deps Dependencies) (http.Handler, error) {
}
server := &Server{
config: deps.Config,
logger: deps.Logger,
documents: deps.Documents,
repository: deps.Repository,
contentStore: deps.ContentStore,
hub: deps.Hub,
syncService: deps.SyncService,
syncRepo: deps.SyncRepo,
auth: deps.Auth,
authLimiter: newRateLimiter(5, time.Minute),
templates: templates,
config: deps.Config,
logger: deps.Logger,
documents: deps.Documents,
repository: deps.Repository,
contentStore: deps.ContentStore,
hub: deps.Hub,
syncService: deps.SyncService,
syncRepo: deps.SyncRepo,
auth: deps.Auth,
collaboration: deps.Collaboration,
authLimiter: newRateLimiter(5, time.Minute),
templates: templates,
}
if _, err := os.Stat(deps.Config.Web.DistDir); err == nil {
@@ -129,6 +133,20 @@ func New(deps Dependencies) (http.Handler, error) {
router.Post("/api/uploads", server.handleUpload)
router.Get("/attachments/{hash}", server.handleAttachment)
// Collaboration endpoints
router.Get("/api/comments", server.handleListComments)
router.Post("/api/comments", server.handleCreateComment)
router.Post("/api/comments/{id}/resolve", server.handleResolveComment)
router.Get("/api/notifications", server.handleListNotifications)
router.Post("/api/notifications/{id}/read", server.handleMarkNotificationRead)
router.Post("/api/notifications/read-all", server.handleMarkAllNotificationsRead)
router.Get("/api/notifications/bell", server.handleNotificationBell)
router.Post("/api/watch/document", server.handleWatchDocument)
router.Post("/api/watch/folder", server.handleWatchFolder)
router.Delete("/api/watch/document", server.handleUnwatchDocument)
router.Delete("/api/watch/folder", server.handleUnwatchFolder)
router.Get("/api/watch/status", server.handleIsWatching)
// Sync protocol endpoints
router.Post("/api/sync/init", server.handleSyncInit)
router.Post("/api/sync/delta", server.handleSyncDelta)