Добавил реализацию

This commit is contained in:
av
2026-06-28 12:20:10 +03:00
parent 4f2fb5998a
commit d8ef7063f4
12 changed files with 731 additions and 39 deletions
+21 -3
View File
@@ -26,6 +26,12 @@ type QBittorrent interface {
Add(ctx context.Context, ar qbt.AddRequest) error
}
// Namer выводит человекочитаемое отображаемое имя торрента из контекста.
// Пустой результат → имя в qBittorrent не задаём. nil → шаг пропускается.
type Namer interface {
DeriveName(ctx context.Context, contextText, hint string) string
}
// Config — параметры добавления в qBittorrent.
type Config struct {
Category string
@@ -36,13 +42,15 @@ type Config struct {
type Service struct {
store Store
qbt QBittorrent
namer Namer
cfg Config
log *slog.Logger
}
// New собирает сервис приёма.
func New(st Store, qb QBittorrent, cfg Config, log *slog.Logger) *Service {
return &Service{store: st, qbt: qb, cfg: cfg, log: log}
// New собирает сервис приёма. namer опционален (nil → отображаемое имя не
// выводится; qBittorrent оставит своё).
func New(st Store, qb QBittorrent, namer Namer, cfg Config, log *slog.Logger) *Service {
return &Service{store: st, qbt: qb, namer: namer, cfg: cfg, log: log}
}
// Request — входной запрос приёма.
@@ -82,6 +90,15 @@ func (s *Service) Ingest(ctx context.Context, req Request) (Result, error) {
}, nil
}
// Отображаемое имя для списка qBit — best-effort: не валит приём.
// Выводится синхронно (param rename действует только при добавлении) и
// ДО CreateDownload, чтобы возможный медленный вызов LLM не расширял окно
// «строка в БД есть, в qBittorrent ещё нет». Имя от строки БД не зависит.
var rename string
if s.namer != nil {
rename = s.namer.DeriveName(ctx, req.Context, info.DisplayName)
}
d := &store.Download{
SourceType: store.SourceMagnet,
SourceRef: source,
@@ -99,6 +116,7 @@ func (s *Service) Ingest(ctx context.Context, req Request) (Result, error) {
URLs: []string{source},
Category: s.cfg.Category,
SavePath: s.cfg.SavePath,
Rename: rename,
})
if addErr != nil {
s.log.Warn("ingest: qbittorrent add failed, marking download failed",