Files
faumaray 7975f2b38e update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:44:42 +03:00

46 lines
1.1 KiB
C++

#pragma once
#include <TrackTypes.hpp>
#include <Types.hpp>
#include <Void/ShortUrl/ShortUrl.hpp>
#include <chrono>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_set>
#include <vector>
namespace Echoion::Core
{
// Thin Core adapter around the universal Void ShortUrl service. It owns no
// provider and performs no HTTP itself: the getter returns a pinned service
// instance for each operation, making calls safe across plugin hot reloads.
class UrlShortener
{
public:
using ProviderGetter = std::function<
std::shared_ptr<Void::ShortUrl::IShortener>()>;
void setProvider(ProviderGetter provider);
void setSources(const std::vector<std::string>& sources);
[[nodiscard]] Api::Result<std::string>
shortenUrl(std::string_view originalUrl,
Api::TrackSource source) const;
private:
[[nodiscard]] bool sourceAllowed(Api::TrackSource source) const;
mutable std::mutex mutex_;
ProviderGetter provider_;
std::unordered_set<Api::TrackSource> sources_ = {
Api::TrackSource::YouTube};
};
} // namespace Echoion::Core