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>
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
-- +goose Up
|
||||
-- One schema for SQLite and Postgres. Rules that keep it portable:
|
||||
-- identifiers are application generated TEXT, timestamps are unix
|
||||
-- milliseconds in BIGINT, flags are BOOLEAN, no engine specific types.
|
||||
|
||||
CREATE TABLE users (
|
||||
id BIGINT PRIMARY KEY,
|
||||
username TEXT NOT NULL DEFAULT '',
|
||||
first_name TEXT NOT NULL DEFAULT '',
|
||||
lang TEXT NOT NULL DEFAULT '',
|
||||
lang_override TEXT NOT NULL DEFAULT '',
|
||||
banned BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at BIGINT NOT NULL,
|
||||
last_seen_at BIGINT NOT NULL
|
||||
);
|
||||
|
||||
-- A request is one link a user sent, shown as a card with format buttons.
|
||||
CREATE TABLE requests (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
chat_id BIGINT NOT NULL,
|
||||
chat_type TEXT NOT NULL DEFAULT 'private',
|
||||
source_message_id BIGINT NOT NULL DEFAULT 0,
|
||||
card_message_id BIGINT NOT NULL DEFAULT 0,
|
||||
card_is_photo BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
url TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
info TEXT NOT NULL DEFAULT '',
|
||||
lang TEXT NOT NULL DEFAULT 'en',
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL
|
||||
);
|
||||
CREATE INDEX requests_user_idx ON requests (user_id, created_at);
|
||||
|
||||
-- A job is one unit of work for a worker.
|
||||
CREATE TABLE jobs (
|
||||
id TEXT PRIMARY KEY,
|
||||
kind TEXT NOT NULL DEFAULT 'download',
|
||||
url TEXT NOT NULL,
|
||||
extractor TEXT NOT NULL DEFAULT '',
|
||||
video_id TEXT NOT NULL DEFAULT '',
|
||||
profile TEXT NOT NULL,
|
||||
cache_key TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL,
|
||||
lane TEXT NOT NULL DEFAULT 'free',
|
||||
priority INTEGER NOT NULL DEFAULT 0,
|
||||
required_tags TEXT NOT NULL DEFAULT '',
|
||||
max_size BIGINT NOT NULL DEFAULT 0,
|
||||
max_duration BIGINT NOT NULL DEFAULT 0,
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
max_attempts INTEGER NOT NULL DEFAULT 2,
|
||||
worker_id TEXT NOT NULL DEFAULT '',
|
||||
lease_expires_at BIGINT NOT NULL DEFAULT 0,
|
||||
cancel_requested BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
stage TEXT NOT NULL DEFAULT '',
|
||||
progress_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
total_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
error_code TEXT NOT NULL DEFAULT '',
|
||||
error_detail TEXT NOT NULL DEFAULT '',
|
||||
storage_key TEXT NOT NULL DEFAULT '',
|
||||
file_ext TEXT NOT NULL DEFAULT '',
|
||||
file_size BIGINT NOT NULL DEFAULT 0,
|
||||
duration BIGINT NOT NULL DEFAULT 0,
|
||||
width INTEGER NOT NULL DEFAULT 0,
|
||||
height INTEGER NOT NULL DEFAULT 0,
|
||||
title TEXT NOT NULL DEFAULT '',
|
||||
uploader TEXT NOT NULL DEFAULT '',
|
||||
created_at BIGINT NOT NULL,
|
||||
queued_at BIGINT NOT NULL,
|
||||
started_at BIGINT NOT NULL DEFAULT 0,
|
||||
finished_at BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
CREATE INDEX jobs_queue_idx ON jobs (status, lane, priority, queued_at);
|
||||
CREATE INDEX jobs_lease_idx ON jobs (status, lease_expires_at);
|
||||
|
||||
-- A delivery is one requester waiting for the result of a job.
|
||||
CREATE TABLE deliveries (
|
||||
id TEXT PRIMARY KEY,
|
||||
job_id TEXT NOT NULL REFERENCES jobs (id),
|
||||
request_id TEXT NOT NULL DEFAULT '',
|
||||
user_id BIGINT NOT NULL,
|
||||
chat_id BIGINT NOT NULL,
|
||||
chat_type TEXT NOT NULL DEFAULT 'private',
|
||||
reply_to_message_id BIGINT NOT NULL DEFAULT 0,
|
||||
status_message_id BIGINT NOT NULL DEFAULT 0,
|
||||
status_is_photo BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
lang TEXT NOT NULL DEFAULT 'en',
|
||||
status TEXT NOT NULL,
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
error_code TEXT NOT NULL DEFAULT '',
|
||||
tg_file_id TEXT NOT NULL DEFAULT '',
|
||||
tg_message_id BIGINT NOT NULL DEFAULT 0,
|
||||
created_at BIGINT NOT NULL,
|
||||
updated_at BIGINT NOT NULL
|
||||
);
|
||||
CREATE INDEX deliveries_job_idx ON deliveries (job_id);
|
||||
CREATE INDEX deliveries_user_idx ON deliveries (user_id, status);
|
||||
CREATE INDEX deliveries_status_idx ON deliveries (status, updated_at);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE deliveries;
|
||||
DROP TABLE jobs;
|
||||
DROP TABLE requests;
|
||||
DROP TABLE users;
|
||||
Reference in New Issue
Block a user