fix: resolve back step, audio labels, progress parsing, file size pre-check, and stale job cleanup
All checks were successful
CI / build (push) Successful in 36s
All checks were successful
CI / build (push) Successful in 36s
- Fix handleBackStep to redirect to download prompt when step state is nil (previously silent no-op after container selection cleared the state) - Improve formatLabel for audio-only entries without bitrate: use ID + extension instead of generic 'audio', fixing duplicate entries in format list - Add yt-dlp --progress-template for reliable JSON progress parsing across all sites (fixes 0.0% progress on sites like xnxx.com where [download] lines are absent); keep regex parser as fallback for older yt-dlp versions - Add file size pre-check in handleContainerSelection before download starts (previously checked only after download completed, wasting bandwidth) - Clear stale active jobs and step state on /start for a clean slate
This commit is contained in:
@@ -346,6 +346,14 @@ func (h *Handler) handleContainerSelection(ctx context.Context, chatID int64, ms
|
||||
format = ss.MainFormat
|
||||
}
|
||||
|
||||
fileSize := format.Filesize
|
||||
|
||||
if fileSize > 0 && fileSize > h.maxFileSize {
|
||||
h.editText(ctx, chatID, msgID,
|
||||
fmt.Sprintf("File too large (%s). Max: %s", formatBytes(fileSize), formatBytes(h.maxFileSize)), nil)
|
||||
return
|
||||
}
|
||||
|
||||
job := &domain.DownloadJob{
|
||||
ID: h.generateJobID(),
|
||||
UserID: userID,
|
||||
@@ -359,9 +367,10 @@ func (h *Handler) handleContainerSelection(ctx context.Context, chatID int64, ms
|
||||
Language: ss.Language,
|
||||
Status: domain.StatusDownloading,
|
||||
Title: ss.MediaInfo.Title,
|
||||
FileSize: format.Filesize,
|
||||
FileSize: fileSize,
|
||||
}
|
||||
|
||||
h.editText(ctx, chatID, msgID, "Processing...", nil)
|
||||
h.setActiveJob(userID, job)
|
||||
h.clearStepState(chatID)
|
||||
|
||||
@@ -526,6 +535,7 @@ func (h *Handler) handleBackStep(ctx context.Context, chatID int64, msgID int, c
|
||||
defer h.answerCb(ctx, cbID)
|
||||
ss := h.getUserStepState(chatID)
|
||||
if ss == nil {
|
||||
h.handleDownloadPrompt(ctx, chatID, msgID, cbID, userID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -442,9 +442,11 @@ func (h *Handler) generateJobID() string {
|
||||
return uuid.NewString()[:8]
|
||||
}
|
||||
|
||||
// handleStart shows the main menu.
|
||||
// handleStart shows the main menu and cleans up any stale state.
|
||||
func (h *Handler) handleStart(ctx context.Context, msg *models.Message, userID int64) {
|
||||
slog.Info("start", "user_id", userID, "chat_id", msg.Chat.ID)
|
||||
h.clearActiveJob(userID)
|
||||
h.clearStepState(msg.Chat.ID)
|
||||
h.sendWithKB(ctx, msg.Chat.ID, "Main Menu:", mainKeyboard())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user