Phase 2: command screens

- /help: a short introduction with the user's default format, how to be
  asked every time and the limits on one line, plus buttons Commands,
  Account, Groups, Open app and Upgrade that switch the same message to
  a section. Group commands are hidden in private chats; "Add me to a
  group" takes their place.
- /quality: Ask every time, Best that fits my limit, Best, 1080p, 720p,
  480p and Audio only, with the active one checked. Free users see which
  qualities may go over their limit.
- /history: pages of five compact buttons (site, title, format, when),
  a view per download with Send again, Thumbnail, Remove from history,
  and Clear history with a confirmation. Thumbnails are grouped under
  their video. Migration 00007 stores extractor, title, uploader and
  profile on deliveries and adds a hidden flag.
- docs/SCREENS.md shows every screen in en, es and nl, generated by the
  language test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:46:13 +00:00
co-authored by Claude Opus 5.5
parent 6843053582
commit 123cede7f3
21 changed files with 3758 additions and 183 deletions
+72 -6
View File
@@ -8,14 +8,14 @@ import (
const deliveryCols = `id, job_id, request_id, user_id, chat_id, chat_type, reply_to_message_id,
status_message_id, status_is_photo, lang, status, attempts, error_code, tg_file_id,
tg_message_id, created_at, updated_at, source, wallet_id, charge_sats, quota_day, released,
max_size, max_duration`
max_size, max_duration, extractor, title, uploader, profile, hidden`
func scanDelivery(sc interface{ Scan(...any) error }) (*Delivery, error) {
var d Delivery
err := sc.Scan(&d.ID, &d.JobID, &d.RequestID, &d.UserID, &d.ChatID, &d.ChatType, &d.ReplyToMessageID,
&d.StatusMessageID, &d.StatusIsPhoto, &d.Lang, &d.Status, &d.Attempts, &d.ErrorCode, &d.TgFileID,
&d.TgMessageID, &d.CreatedAt, &d.UpdatedAt, &d.Source, &d.WalletID, &d.ChargeSats, &d.QuotaDay, &d.Released,
&d.MaxSize, &d.MaxDuration)
&d.MaxSize, &d.MaxDuration, &d.Extractor, &d.Title, &d.Uploader, &d.Profile, &d.Hidden)
if err != nil {
return nil, notFound(err)
}
@@ -48,11 +48,11 @@ func (s *Store) InsertDelivery(ctx context.Context, d *Delivery) error {
d.Source = "free"
}
_, err := s.exec(ctx, `INSERT INTO deliveries (`+deliveryCols+`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
d.ID, d.JobID, d.RequestID, d.UserID, d.ChatID, d.ChatType, d.ReplyToMessageID,
d.StatusMessageID, d.StatusIsPhoto, d.Lang, d.Status, d.Attempts, d.ErrorCode, d.TgFileID,
d.TgMessageID, d.CreatedAt, d.UpdatedAt, d.Source, d.WalletID, d.ChargeSats, d.QuotaDay, d.Released,
d.MaxSize, d.MaxDuration)
d.MaxSize, d.MaxDuration, d.Extractor, d.Title, d.Uploader, d.Profile, d.Hidden)
return err
}
@@ -102,8 +102,14 @@ func (s *Store) TransitionDelivery(ctx context.Context, id, from, to, errorCode
// MarkDeliverySent records the Telegram file and message of a delivery.
func (s *Store) MarkDeliverySent(ctx context.Context, id, fileID string, messageID int64) error {
// What history shows is copied from the job now, when it is final.
_, err := s.exec(ctx, `UPDATE deliveries SET status = 'sent', tg_file_id = ?, tg_message_id = ?,
error_code = '', updated_at = ? WHERE id = ?`, fileID, messageID, NowMilli(), id)
error_code = '', updated_at = ?,
extractor = COALESCE((SELECT j.extractor FROM jobs j WHERE j.id = deliveries.job_id), ''),
title = COALESCE((SELECT j.title FROM jobs j WHERE j.id = deliveries.job_id), ''),
uploader = COALESCE((SELECT j.uploader FROM jobs j WHERE j.id = deliveries.job_id), ''),
profile = COALESCE((SELECT j.profile FROM jobs j WHERE j.id = deliveries.job_id), '')
WHERE id = ?`, fileID, messageID, NowMilli(), id)
return err
}
@@ -169,7 +175,67 @@ func (s *Store) CountDeliveriesForRequest(ctx context.Context, requestID string)
// History lists a user's delivered files, newest first.
func (s *Store) History(ctx context.Context, userID int64, limit int) ([]*Delivery, error) {
return scanDeliveries(s.rows(ctx, `SELECT `+deliveryCols+` FROM deliveries
WHERE user_id = ? AND status = 'sent' ORDER BY updated_at DESC, id DESC LIMIT ?`, userID, limit))
WHERE `+historyWhere+` ORDER BY created_at DESC, id DESC LIMIT ?`, userID, limit))
}
// historyWhere selects the downloads history lists for a user: sent, not
// removed from history, and not thumbnails, which are offered under their
// video instead of as downloads of their own.
const historyWhere = `user_id = ? AND status = 'sent' AND hidden = FALSE AND profile <> 'thumb'`
// HistoryRow is one past download as /history lists it.
type HistoryRow struct {
DeliveryID string
RequestID string
Extractor string
Title string
Uploader string
Profile string
URL string
Size int64
CreatedAt int64
}
// HistoryPage returns one page of a user's history, newest first, and how
// many downloads the history holds in all.
func (s *Store) HistoryPage(ctx context.Context, userID int64, offset, limit int) ([]HistoryRow, int, error) {
var total int
if err := s.row(ctx, `SELECT COUNT(*) FROM deliveries WHERE `+historyWhere, userID).Scan(&total); err != nil {
return nil, 0, err
}
rows, err := s.rows(ctx, `SELECT d.id, d.request_id, d.extractor, d.title, d.uploader, d.profile,
COALESCE(j.url, ''), COALESCE(j.file_size, 0), d.created_at
FROM deliveries d LEFT JOIN jobs j ON j.id = d.job_id
WHERE d.user_id = ? AND d.status = 'sent' AND d.hidden = FALSE AND d.profile <> 'thumb'
ORDER BY d.created_at DESC, d.id DESC LIMIT ? OFFSET ?`, userID, limit, offset)
if err != nil {
return nil, 0, err
}
defer rows.Close()
var out []HistoryRow
for rows.Next() {
var r HistoryRow
if err := rows.Scan(&r.DeliveryID, &r.RequestID, &r.Extractor, &r.Title, &r.Uploader, &r.Profile,
&r.URL, &r.Size, &r.CreatedAt); err != nil {
return nil, 0, err
}
out = append(out, r)
}
return out, total, rows.Err()
}
// HideFromHistory removes one download from a user's history. It reports
// whether the download was there.
func (s *Store) HideFromHistory(ctx context.Context, userID int64, deliveryID string) (bool, error) {
n, err := s.exec(ctx, `UPDATE deliveries SET hidden = TRUE WHERE id = ? AND user_id = ? AND hidden = FALSE`,
deliveryID, userID)
return n == 1, err
}
// ClearHistory removes every download from a user's history and returns
// how many there were.
func (s *Store) ClearHistory(ctx context.Context, userID int64) (int64, error) {
return s.exec(ctx, `UPDATE deliveries SET hidden = TRUE WHERE user_id = ? AND status = 'sent' AND hidden = FALSE`, userID)
}
// RecentDelivery is a file a user got lately, with the link it came from.