Files
Media-download-telegram-bot/internal/db/models.go
T
MichilisandClaude Fable 5.2 3b361c17a1 Phase 1: core bot
Link in, card, download, send, in private chats and groups.

- cmd/core with an embedded download worker
- Telegram front end on telego v1.13.0 (Bot API 10.4): link card with
  thumbnail and format buttons, one live status message, /dl /audio /thumb
  /info /queue /cancel, group support with requester-only buttons
- Database backed queue: paid and free lanes, leases with heartbeats, one
  automatic retry, cancel, queue position and wait estimate
- yt-dlp and ffprobe behind a Runner interface with classified, redacted
  errors mapped to friendly messages
- SQLite via modernc with goose migrations, portable schema
- Local file storage behind a Storage interface
- go-i18n with an English catalog, no literal text in handlers
- Free tier limits enforced before queueing and again on the real file
- Bot token and webhook secret are stripped from all log output
- Tests: URL parsing, job lifecycle, worker, yt-dlp wrapper, and end to end
  flows against a fake Bot API server; opt-in test with the real yt-dlp

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 07:33:32 +00:00

133 lines
3.0 KiB
Go

package db
// Request statuses.
const (
RequestReady = "ready" // card shown, waiting for a format choice
RequestChosen = "chosen" // a format was picked and a job exists
RequestCancelled = "cancelled" // the requester dismissed the card
)
// Job statuses.
const (
JobQueued = "queued"
JobRunning = "running"
JobDelivering = "delivering" // file is stored, the core is sending it
JobDone = "done"
JobFailed = "failed"
JobCancelled = "cancelled"
)
// Delivery statuses.
const (
DeliveryPending = "pending"
DeliverySending = "sending"
DeliverySent = "sent"
DeliveryFailed = "failed"
DeliveryCancelled = "cancelled"
)
// Queue lanes.
const (
LanePaid = "paid"
LaneFree = "free"
)
// Job kinds.
const (
KindDownload = "download"
)
// User is a Telegram user known to the bot.
type User struct {
ID int64
Username string
FirstName string
Lang string // detected from Telegram
LangOverride string // chosen with /language
Banned bool
CreatedAt int64
LastSeenAt int64
}
// Request is one link sent by a user.
type Request struct {
ID string
UserID int64
ChatID int64
ChatType string
SourceMessageID int64
CardMessageID int64
CardIsPhoto bool
URL string
Status string
Info string // JSON, see service.CardInfo
Lang string
CreatedAt int64
UpdatedAt int64
}
// Job is one unit of work for a worker.
type Job struct {
ID string
Kind string
URL string
Extractor string
VideoID string
Profile string
CacheKey string
Status string
Lane string
Priority int
RequiredTags string
MaxSize int64
MaxDuration int64 // seconds
Attempts int
MaxAttempts int
WorkerID string
LeaseExpiresAt int64
CancelRequested bool
Stage string
ProgressBytes int64
TotalBytes int64
ErrorCode string
ErrorDetail string
StorageKey string
FileExt string
FileSize int64
Duration int64 // seconds
Width int
Height int
Title string
Uploader string
CreatedAt int64
QueuedAt int64
StartedAt int64
FinishedAt int64
}
// Active reports whether the job still needs a worker or the core.
func (j *Job) Active() bool {
return j.Status == JobQueued || j.Status == JobRunning || j.Status == JobDelivering
}
// Delivery is one requester waiting for a job.
type Delivery struct {
ID string
JobID string
RequestID string
UserID int64
ChatID int64
ChatType string
ReplyToMessageID int64
StatusMessageID int64
StatusIsPhoto bool
Lang string
Status string
Attempts int
ErrorCode string
TgFileID string
TgMessageID int64
CreatedAt int64
UpdatedAt int64
}