sonda/cmd/sondad/scan.go
tgiachi 46463846b3 feat(library): named media libraries managed through the API
- feat(storage): libraries table (name, path); audio_files points at a library
  by id instead of repeating the root path; migration 0005 for both drivers
  turns every existing root into a library and keeps file ids, tracks and the
  missing flag
- feat(library): Libraries service validates names and paths: absolute, an
  existing directory, never the filesystem root, never inside or around
  another library (checked on real paths, so symlinks cannot hide an overlap)
- feat(api): admin-only GET/POST /libraries, PATCH/DELETE /libraries/{id} and
  POST /libraries/{id}/scan; deleting a library drops its index entries and
  keeps tracks and listening history
- feat(library): the scanner and the scan manager work on libraries; scanning
  with no libraries answers 409 no_libraries
- feat(streaming): the library directory comes from the database instead of
  a configured list of roots
- breaking(config): library.roots is removed; an old config fails with a hint
  to use POST /api/v1/libraries
- test: CRUD and duplicates on both databases, path change keeps files,
  upgrade of a database written before libraries existed
2026-11-11 13:30:25 +01:00

38 lines
1.2 KiB
Go

package main
import (
"context"
"go.uber.org/zap"
"codeberg.org/squidd/sonda/internal/library"
)
// scanControl lets the HTTP layer start scans that live as long as the
// application, not as long as a single request.
type scanControl struct {
ctx context.Context
m *library.Manager
}
func (c scanControl) Start() error { return c.m.Start(c.ctx) }
func (c scanControl) StartLibrary(id int64) error { return c.m.StartLibrary(c.ctx, id) }
func (c scanControl) Status() library.Status { return c.m.Status() }
// logScanResults writes one log line per finished scan. File paths are left
// out on purpose: audio paths are private.
func logScanResults(logger *zap.Logger, m *library.Manager) {
m.OnFinish(func(s library.Summary, err error) {
fields := []zap.Field{
zap.Int("found", s.Found), zap.Int("added", s.Added), zap.Int("updated", s.Updated),
zap.Int("unchanged", s.Unchanged), zap.Int("renamed", s.Renamed),
zap.Int("restored", s.Restored), zap.Int("missing", s.Missing),
zap.Int("failed", s.Failed), zap.Int("skipped", s.Skipped),
}
if err != nil {
logger.Warn("library scan finished with errors", append(fields, zap.Error(err))...)
return
}
logger.Info("library scan finished", fields...)
})
}