mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
d5cf5fb4b2
Adopt the cropflre/nowen-video tech stack and rebuild the project from
scratch:
- Backend: Go 1.25 + Gin + GORM + SQLite (WAL) + JWT + WebSocket hub.
Layered packages config / database / model / repository / service /
middleware / handler. Default admin (admin/admin123) seeded on first
run; /api routes for auth, libraries, media, stream and admin
panels. WebSocket scan-progress events at /api/ws.
- Frontend: React 18 + Vite 5 + Tailwind 3.4 + Zustand + axios +
react-router 6 + lucide-react + framer-motion + hls.js. Pages for
Login / Home / Library / Search / MediaDetail / Player / Admin
(Library, Users, Settings tabs).
- Distribution: multi-arch Dockerfile (frontend -> backend -> Alpine
runtime), docker-compose.yml, GitHub Actions for CI and GHCR
publish, Makefile, env-prefixed config (MEDIASTATION_*).
- Docs: README, CONTRIBUTING, .env.example, config.example.yaml.
Backend builds, vets and tests pass. Frontend builds via tsc -b && vite
build (250 kB JS / 16 kB CSS, gzipped 84 / 4 kB).
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Package service contains the business logic of MediaStationGo. Handlers
|
|
// deserialize the HTTP request, call into a Service method, then serialize
|
|
// the response. Services own all cross-cutting policy (auth, scanning,
|
|
// transcoding, etc.) and never deal with HTTP types directly.
|
|
package service
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/config"
|
|
"github.com/ShukeBta/MediaStationGo/internal/repository"
|
|
)
|
|
|
|
// Container holds every service initialized at startup. Handlers receive a
|
|
// pointer to it and pick the relevant fields.
|
|
type Container struct {
|
|
Cfg *config.Config
|
|
Log *zap.Logger
|
|
Repo *repository.Container
|
|
WSHub *Hub
|
|
Auth *AuthService
|
|
Media *MediaService
|
|
Scan *ScannerService
|
|
Stream *StreamService
|
|
}
|
|
|
|
// New builds the service container.
|
|
func New(cfg *config.Config, log *zap.Logger, repos *repository.Container) *Container {
|
|
hub := NewHub(log)
|
|
go hub.Run()
|
|
return &Container{
|
|
Cfg: cfg,
|
|
Log: log,
|
|
Repo: repos,
|
|
WSHub: hub,
|
|
Auth: NewAuthService(cfg, log, repos),
|
|
Media: NewMediaService(cfg, log, repos),
|
|
Scan: NewScannerService(cfg, log, repos, hub),
|
|
Stream: NewStreamService(cfg, log, repos),
|
|
}
|
|
}
|
|
|
|
// Close releases any resources held by services (e.g. the websocket hub).
|
|
func (c *Container) Close() {
|
|
if c.WSHub != nil {
|
|
c.WSHub.Stop()
|
|
}
|
|
}
|