Commit Graph
37 Commits
Author SHA1 Message Date
Mak5er d4595a7e13 feat(guest-mode): add Telegram Bot API 9.0 guest mode support and media download flow
- Add guest_message router and handler for guest mentions in chats where bot is not a member
- Support link detection from direct messages, replies, quotes, and text_link entities
- Integrate with inline media senders for supported platforms and deep-linking for audio/albums
- Add guest rate-limiting and ban enforcement in antiflood and ban middlewares
- Update chat tracker to track guest users without saving non-member group data
- Bypass private chat guard for guest messages
- Add /start settings, /start stats, and /start dl_<token> deep-link handlers
- Add comprehensive test suite in tests/test_guest_mode.py
2026-09-14 14:35:09 +03:00
Mak5er 635e50b407 feat(settings): add media quality & file options, ZIP multi-photo archives, and categorized /settings UI
- Add video_quality, as_document, audio_format, and file_button to user settings schema and Alembic migrations.
- Categorize /settings into Media & Quality, Appearance & Buttons, and Chat & Clean-up with dynamic back navigation.
- Implement strict document delivery with disable_content_type_detection=True to prevent Telegram video player fallback when as_document is ON.
- Add multi-photo ZIP archive packaging for photo carousels in as_document mode.
- Differentiate DB media file cache entries between video and document types (url#document vs url#video) to eliminate cache collisions.
- Hide redundant Download File inline button when as_document setting is active.
- Remove obsolete referral system (/ref command and links).
2026-07-22 13:18:09 +03:00
Mak5er 40662635b7 feat: add Spotify audio downloads and rich metadata
Add Spotify track resolution through YouTube audio sources with oEmbed fallback, caching, routing, analytics, and user-facing support. Normalize MP3 filenames, ID3 tags, JPEG cover art, Telegram thumbnails, and duplicate artist metadata across Spotify, YouTube Music, and SoundCloud. Extend regression coverage for provider parsing, delivery, metadata, covers, cache behavior, and link dispatch.
2026-07-10 12:22:17 +03:00
Mak5er bbb5af1643 fix(downloads): harden media download flows 2026-07-05 22:19:51 +03:00
Mak5er e3d8bb287e fix: remove private IP blocking from CUSTOM_API_URL (it's a local Telegram API server) 2026-06-18 18:54:51 +03:00
Mak5er 0a0ab1466f perf: tune connection pool for Neon serverless (5+10, 300s recycle, FIFO) 2026-06-18 18:28:44 +03:00
Mak5er 46403d791d security: add private IP blocking to CUSTOM_API_URL validator, warn on DANGER_ACCEPT_INSECURE 2026-06-18 18:24:36 +03:00
Mak5er 62050a0f2c perf: comprehensive production audit and hardening (Phase 1-4)
43 files changed, 828 insertions, 408 deletions. Key changes:

== Phase 1 - Critical fixes ==
- Fix shared mutable state in ResilientDownloader (class-level _inflight_downloads)
- Add threading.Lock to request dedup (race condition on concurrent claims)
- Fix ban_middleware fail-closed: DB error -> fallback to 'active' instead of 'restricted'
- Fix COUNT(*) anti-pattern: 5 methods fetched entire user table into memory
- Remove 6 duplicated function definitions in user_messages.py (silent shadowing)
- Extract metadata from Cobalt responses (Instagram no longer discards descriptions)
- Add SSRF validation for COBALT_API_URL (private IP blocking, scheme enforcement)
- Docker: healthcheck, resource limits, restart: on-failure:5
- Fix migration crash-loop (try/except guardrails + dialect detection bug)

== Phase 2 - Performance hardening ==
- Exponential backoff+jitter in cobalt_client and retry_async_operation (removed 9 fixed delays)
- Add asyncio.wait_for timeouts to Instagram/Pinterest downloads
- TikTok preflight size check before download
- SQLAlchemy pool event listeners (perf metrics on checkout/overflow)
- DownloadedFile TTL cleanup (date_added index + daily cron cleanup)
- Per-request UUID request_id in ChatTrackerMiddleware for end-to-end tracing
- private_chat_guard caching (60s TTL, reduces Telegram API calls)
- Antiflood O(k) eviction instead of O(n) full scan
- TikTok: Semaphore(3)+sliding-window rate limiter instead of global asyncio.Lock

== Phase 3 - CI hardening ==
- CI: lint job (ruff + mypy), docker smoke tests migrations, --cov-fail-under=80
- Upgrade dependency-audit Python 3.12 -> 3.14
- Fix 7 '# type: ignore' decorators with ParamSpec
- Migration 000005: ix_analytics_events_user_id + ix_downloaded_files_date_added
- Race-condition tests for dedup, queue shutdown, per-user slots

== Phase 4 - Architecture ==
- .dockerignore (exclude .git, tests, __pycache__, .env from Docker image)
- Consolidate 3 FakeYoutubeDL/DummyYDL classes into conftest.py
- Extract _download_youtube_media() from 70-line closure
- BasePlatformMediaService ABC in services/platforms/__init__.py
- Remove empty profiling/ directory

Tests: 349 passed, 0 failed (4 skipped: PostgreSQL-dependent)
2026-06-16 01:01:06 +03:00
Mak5er 468ba2031b Improve bot onboarding and adaptive downloads 2026-05-27 17:33:59 +03:00
Mak5er c4fd448f37 fix: dedupe repeated media link requests 2026-04-09 02:08:46 +03:00
Mak5er 57012b387e perf: harden update backpressure and antiflood 2026-04-09 01:31:47 +03:00
Mak5er bbe6737d85 refactor: normalize config names to upper snake case
- switch runtime imports to ADMIN_ID/CUSTOM_API_URL and drop lowercase module aliases
- keep backward-compatible env fallback for existing deployments
- update docs/tests and remove the completed config naming finding from the review backlog
2026-04-06 23:50:41 +03:00
Mak5er 784aee9747 fix: harden inline delivery and bot runtime safeguards
- secure admin callbacks and inline token ownership checks
- stabilize private chat handoff and fail-soft user settings reads
- improve inline album previews with captions, photo file_ids, and API-safe payloads
- fix download manager dedup, resume validation, and size-limit propagation
- add regression coverage for admin, db, runtime, inline, and download flows
2026-04-06 23:07:26 +03:00
mak5er a14785b5fa refactor: extract cobalt client and integrate instagram flow 2026-02-16 23:12:38 +02:00
mak5er 943d14ccea chore: refresh bot copy and keyboard flow 2026-02-16 00:39:27 +02:00
mak5er 0f9485f577 Refactor configuration to use environment variable for COBALT_API_URL; clean up TikTok handler by removing redundant reaction call 2026-01-21 12:36:34 +02:00
mak5er 34895f627f Update README and configuration for Cobalt API integration; enhance Instagram handler for media fetching and processing 2026-01-18 11:58:52 +02:00
mak5er e8c526f464 Remove Instagram RapidAPI keys from configuration and update Instagram handler to use Cobalt API for media fetching. 2026-01-17 22:00:47 +02:00
mak5er 449db311f2 Refactor user stats command to include error handling and logging
- Added try-except block in the stats command to handle exceptions and log errors.
- Updated logging to capture exceptions when generating stats.

Refactor YouTube download handler for improved error handling and type safety

- Introduced safe_int function to handle integer conversions safely.
- Updated download_video and inline_youtube_query functions to use safe_int for view and like counts.
- Removed custom OAuth verifier function and related code.

Simplify video info keyboard function

- Removed unused full_quality_callback parameter from return_video_info_keyboard function.

Update requirements for PostgreSQL support

- Added psycopg2-binary and asyncpg to requirements.txt for PostgreSQL database support.
- Added pytest-asyncio for async testing.

Update Alembic configuration for environment-based database URL

- Changed sqlalchemy.url in alembic.ini to use environment variable DATABASE_URL.

Refactor database connection to support PostgreSQL

- Updated db.py to use BigInteger for primary keys and adapt to PostgreSQL.
- Implemented asyncpg for asynchronous database operations.
- Added sequence adjustments for PostgreSQL after migrations.

Add migration script from SQLite to PostgreSQL

- Created migrate_sqlite_to_postgres.py to facilitate data migration from SQLite to PostgreSQL.

Implement a resilient downloader service

- Added download_manager.py with a ResilientDownloader class for robust file downloading.
- Supports multipart downloads, retries, and resuming interrupted downloads.

Refactor tests to accommodate new database and downloader structure

- Updated test_db.py to use DATABASE_URL for database connection in tests.
- Refactored Instagram handler tests to use the new InstagramService for downloading videos.
2025-12-15 23:58:44 +02:00
Mak5er e4fe9776dd Update .gitignore and refactor database path handling in config and db modules 2025-11-02 22:48:45 +02:00
Mak5er 67f591207f Add user settings management and logging enhancements 2025-11-02 21:38:51 +02:00
Mak5er a85d34f58f Refactor database configuration and add SQLite initialization 2025-09-10 22:25:45 +03:00
Mak5er 3c13ce22c6 Remove SubscriptionMiddleware and CHANNEL_USERNAME from configuration 2025-07-13 01:37:02 +03:00
Mak5er c583010514 Add subscription middleware to enforce channel subscription for bot usage 2025-04-10 21:05:49 +03:00
Mak5er 5b3124731c Refactor Instagram and TikTok handlers for improved error handling and logging; update API URLs and message responses 2025-02-22 12:39:20 +02:00
Mak5er 08072085a7 Updated Instagram API keys and host configuration 2025-02-20 22:16:44 +02:00
Mak5er f5127d25b3 Updated Instagram downloading
Added inline mode support for Instagram reels
2025-02-09 19:28:43 +02:00
Mak5er cc2b592915 Updated TikTok downloading
Added inline mode support for TikTok videos
2025-02-09 14:22:38 +02:00
Mak5er ac7d07fae2 updated config 2024-10-09 20:00:34 +03:00
Mak5er 398870db39 added pytube oauth 2024-08-08 23:10:18 +03:00
Mak5er ab208d764f add google analytic 2024-07-11 20:56:40 +03:00
Mak5er 207de460ca created custom tg bot API 2024-06-28 13:32:09 +03:00
Mak5er 19679ff5fe updated bot commands list 2024-06-24 10:29:11 +03:00
Mak5er c4818c7790 add admin, optimized code and add music time 2024-06-23 23:22:39 +03:00
Mak5er ae94a3b5ad add database with users 2024-06-22 20:06:13 +03:00
Mak5er b16bd64919 add instagram posts and reels downloading 2024-06-22 15:16:23 +03:00
Mak5er dee77218f4 created tik-tok downloader 2024-06-21 17:00:54 +03:00