Migrate core infrastructure to VoidLibrary

This commit is contained in:
faumaray committed 2026-06-22 15:53:23 +03:00
1 parent 53801f2b53
commit 2bdb63766d
65 files changed
+16109 -12011

No files matched your search

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