refactor: remove container selection, extract helpers, add logging and tests
All checks were successful
CI / build (push) Successful in 51s

- Remove container picker UI, keyboard, settings, and ContainerOptions
  entirely — yt-dlp handles container format automatically
- Remove Container field from DownloadJob struct and related references
- Extract buildFormatList helper to deduplicate format list building
  between handleURLInput and handleBackStep
- Break runDownload into trackDownloadProgress + handleDownloadCompletion
- Add HTTP timeout (30s) to downloadFile helper
- Log applyQuota and AddHistory errors instead of discarding
- Log nil stepState warnings in all handler entry points
- Include job.StderrLog in download failure messages
- Add tests for buildFormatList, findFormatByID, determineMediaType,
  and buildFormatString
- Update README with search, DRM fallback, and quota feature docs
- Remove unused strings import from keyboard.go
This commit is contained in:
2026-06-25 23:41:26 +03:30
parent dfe946a41b
commit 37e7f918d0
10 changed files with 266 additions and 296 deletions

View File

@@ -280,7 +280,7 @@ func (h *Handler) routePrefixedCallback(ctx context.Context, chatID int64, msgID
case strings.HasPrefix(data, "lang_"):
h.handleLanguageSelection(ctx, chatID, msgID, userID, data[5:])
case strings.HasPrefix(data, "container_"):
h.handleContainerSelection(ctx, chatID, msgID, userID, data[10:])
// container selection was removed — yt-dlp handles it
case strings.HasPrefix(data, "pl_page_"):
h.handlePlaylistPage(ctx, chatID, msgID, userID, data[8:])
case strings.HasPrefix(data, "pl_entry_"):
@@ -295,8 +295,6 @@ func (h *Handler) routePrefixedCallback(ctx context.Context, chatID int64, msgID
}
case data == "back_quality":
h.handleSettingsSelection(ctx, chatID, msgID, userID, "quality")
case data == "back_container":
h.handleSettingsSelection(ctx, chatID, msgID, userID, "container")
case data == "back_settings":
h.backToSettings(ctx, chatID, msgID, userID)
case strings.HasPrefix(data, "settings_set_"):
@@ -573,6 +571,7 @@ func (h *Handler) historyCallback(ctx context.Context, chatID int64, msgID int,
func (h *Handler) applyQuota(userID int64, fileSize int64) {
q, err := h.Repo.GetOrCreateQuotas(userID)
if err != nil {
slog.Error("get quotas for apply", "user_id", userID, "error", err)
return
}
q = h.resetQuotasIfNeeded(q)
@@ -583,7 +582,9 @@ func (h *Handler) applyQuota(userID int64, fileSize int64) {
q.DailyUsedMB += sizeMB
q.WeeklyUsedMB += sizeMB
q.MonthlyUsedMB += sizeMB
_ = h.Repo.UpdateQuotas(userID, q)
if err := h.Repo.UpdateQuotas(userID, q); err != nil {
slog.Error("update quotas", "user_id", userID, "error", err)
}
}
// resetQuotasIfNeeded resets quota counters if the period has changed.