#pragma once #include "NetworkClient.hpp" #include #include #include #include #include #include #include namespace Echoion::Core { // URL shortener service for faumaray.ru class UrlShortener { public: explicit UrlShortener(std::shared_ptr networkClient); ~UrlShortener(); // Shorten a YouTube URL via faumaray.ru // Returns shortened URL in format: https://faumaray.ru/xxxxx [[nodiscard]] Api::Result shortenYouTubeUrl(std::string_view videoId); // Shorten any URL via faumaray.ru [[nodiscard]] Api::Result shortenUrl(std::string_view originalUrl); // Get cached shortened URL if available [[nodiscard]] std::optional getCachedUrl(std::string_view originalUrl) const; // Clear the URL cache void clearCache(); // Set cache TTL (default: 24 hours) void setCacheTtl(std::chrono::hours ttl); private: struct CacheEntry { std::string shortenedUrl; std::chrono::system_clock::time_point timestamp; }; std::shared_ptr networkClient_; mutable std::mutex cacheMutex_; std::unordered_map cache_; std::chrono::hours cacheTtl_{24}; // Clean expired entries from cache void cleanExpiredCache(); }; } // namespace Echoion::Core