Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-25 23:44:42 +03:00
1 parent 9f06af6c80
commit 7975f2b38e
19 files changed
+2020 -747

No files matched your search

+9 -1
View File
@@ -4,6 +4,7 @@
#include <Types.hpp>
#include <filesystem>
#include <string>
#include <string_view>
namespace Echoion::Core
{
@@ -22,6 +23,12 @@ namespace Echoion::Core
[[nodiscard]] static Api::Result<Api::AppConfig>
loadFromFile(const std::filesystem::path& path);
// Parse, migrate, and normalize a complete JSON configuration. This
// is shared by file loading and live configuration updates so
// legacy fields have identical behavior through both entry points.
[[nodiscard]] static Api::Result<Api::AppConfig>
loadFromJson(std::string_view json);
// Save configuration to JSON file
[[nodiscard]] static Api::Result<void>
saveToFile(const std::filesystem::path& path,
@@ -34,7 +41,8 @@ namespace Echoion::Core
[[nodiscard]] static Api::AppConfig createDefaultConfig();
// Clamp/normalize values that carry hard limits after loading
// (e.g. the yt-dlp concurrency cap). Applied by loadFromFile.
// (e.g. the yt-dlp concurrency cap). Applied by all load/update
// paths.
static void normalize(Api::AppConfig& config);
};
+6 -2
View File
@@ -136,6 +136,8 @@ namespace Echoion::Core
void setAudioDataCallback(
const MusicManager::AudioDataCallback& callback);
Api::Result<void> reloadConfig() override;
[[nodiscard]] Api::Result<std::string>
managePluginsJson(const std::string& requestJson) override;
// Internal implementations using full types
Api::Result<void> playTrack(const Api::TrackInfo& track);
@@ -168,6 +170,7 @@ namespace Echoion::Core
void updateWhisperList();
void setupRpcHandlers();
void setupEventBusSubscriptions() noexcept;
void applyUrlShorteningConfig();
// Fetch an online client's avatar bytes (TS local cache, then the
// myTeamSpeak URL, then a legacy file-transfer download) and
@@ -256,8 +259,9 @@ namespace Echoion::Core
std::shared_ptr<RpcServer> rpcServer_;
#ifdef ECHOION_WITH_WEB
// Browser web interface: serves the static dashboard and same-origin
// RPC bridge. Bot control still terminates at the RPC server.
// Browser web interface: serves the static dashboard and
// same-origin RPC bridge. Bot control still terminates at the RPC
// server.
std::shared_ptr<Web::HttpServer> webServer_;
#endif
+83 -34
View File
@@ -1,14 +1,20 @@
#pragma once
#include <ExtensionPlugin.hpp>
#include <NetworkTypes.hpp>
#include <Void/Plugin/Manager.hpp>
#include <Void/Service/PluginService.hpp>
#include <Void/Service/Registry.hpp>
#include <Void/ShortUrl/ShortUrl.hpp>
#include <filesystem>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
namespace Echoion::Core
@@ -19,41 +25,84 @@ namespace Echoion::Core
class PluginHost final : public std::enable_shared_from_this<PluginHost>
{
public:
PluginHost(CommandManager& commands, std::shared_ptr<MusicManager> music,
std::function<bool(uint64_t)> isAdmin,
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink = {});
~PluginHost();
public:
void loadDirectory(const std::filesystem::path& directory);
void setChangeCallback(std::function<void()> callback);
void dispatch(const Api::PluginEvent& event) const;
[[nodiscard]] Api::Result<std::string> call(
std::string_view plugin, std::string_view method,
std::string params, uint64_t clientId) const;
[[nodiscard]] std::vector<Api::ExtensionWebAsset> webAssets() const;
[[nodiscard]] std::vector<std::string> names() const;
struct State {
std::string name;
std::string json;
std::uint32_t version{};
};
[[nodiscard]] std::vector<State> snapshotStates() const;
void restoreStates(const std::vector<State>& states);
struct Configuration {
std::filesystem::path configDirectory;
std::filesystem::path stateDirectory;
std::string publicUrl;
std::optional<Void::Net::ProxyConfig> proxy;
std::string shortenerProvider = "url-shortener-internal";
};
private:
void publish(std::string_view name);
void unpublish(std::string_view name);
void notifyChanged() const;
PluginHost(CommandManager& commands,
std::shared_ptr<MusicManager>
music,
std::function<bool(uint64_t)>
isAdmin,
std::function<void(std::shared_ptr<ITrackSource>)>
mediaSink,
Configuration configuration);
~PluginHost();
CommandManager& commands_;
std::shared_ptr<MusicManager> music_;
std::function<bool(uint64_t)> isAdmin_;
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink_;
Void::Plugin::PluginManager plugins_;
Void::Plugin::ReloadCallbackId reloadCallback_{};
mutable std::mutex mutex_;
std::vector<std::shared_ptr<class PluginTrackSource>> sources_;
std::function<void()> changeCallback_;
void loadDirectory(const std::filesystem::path& directory);
void loadManagedDirectory(const std::filesystem::path& directory);
[[nodiscard]] Api::Result<std::string>
manage(const std::string& requestJson);
void setChangeCallback(std::function<void()> callback);
void dispatch(const Api::PluginEvent& event) const;
[[nodiscard]] Api::Result<std::string>
call(std::string_view plugin, std::string_view method,
std::string params, uint64_t clientId) const;
[[nodiscard]] std::vector<Api::ExtensionWebAsset> webAssets() const;
[[nodiscard]] std::vector<std::string> names() const;
[[nodiscard]] bool reconfigure(Configuration configuration);
[[nodiscard]] std::shared_ptr<Void::ShortUrl::IShortener>
shortener() const;
[[nodiscard]] Void::ShortUrl::ResolveResult
resolveShortLink(std::string_view key) const;
struct State {
std::string name;
std::string json;
std::uint32_t version{};
};
[[nodiscard]] std::vector<State> snapshotStates() const;
void restoreStates(const std::vector<State>& states);
private:
void publish(std::string_view name);
void unpublish(std::string_view name);
void notifyChanged() const;
[[nodiscard]] std::string
pluginConfiguration(std::string_view name) const;
[[nodiscard]] bool bindShortenerServices();
CommandManager& commands_;
std::shared_ptr<MusicManager> music_;
std::function<bool(uint64_t)> isAdmin_;
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink_;
Void::Plugin::PluginManager plugins_;
Void::Service::ServiceRegistry shortenerRegistry_;
Void::Service::ServiceRegistry internalShortenerRegistry_;
std::unique_ptr<
Void::Service::PluginServiceBinding<Void::ShortUrl::IShortener>>
shortenerBinding_;
std::unique_ptr<
Void::Service::PluginServiceBinding<Void::ShortUrl::IShortener>>
internalShortenerBinding_;
Void::Plugin::ReloadCallbackId reloadCallback_{};
mutable std::mutex reconfigureMutex_;
mutable std::mutex mutex_;
Configuration configuration_;
std::vector<std::shared_ptr<class PluginTrackSource>> sources_;
std::function<void()> changeCallback_;
struct ManagedPlugin {
std::string version;
std::filesystem::path path;
};
std::filesystem::path managedDirectory_;
std::unordered_map<std::string, ManagedPlugin> managed_;
std::unordered_map<std::string, std::filesystem::path> loadedPaths_;
};
}
} // namespace Echoion::Core
+1 -1
View File
@@ -97,7 +97,7 @@ namespace Echoion::Core::Dto
int source = 0;
std::optional<std::string> thumbnailUrl;
std::optional<std::string> url; // originalUrl (play-by-url)
// Shortened faumaray.ru link when available; the web UI prefers
// Provider-generated shortened link when available; the web UI prefers
// it for "open original link" (falls back to url).
std::optional<std::string> shortenedUrl;
};
+23 -36
View File
@@ -1,58 +1,45 @@
#pragma once
#include "NetworkClient.hpp"
#include <NetworkTypes.hpp>
#include <TrackTypes.hpp>
#include <Types.hpp>
#include <Void/ShortUrl/ShortUrl.hpp>
#include <chrono>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <unordered_map>
#include <string_view>
#include <unordered_set>
#include <vector>
namespace Echoion::Core
{
// URL shortener service for faumaray.ru
// 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:
explicit UrlShortener(std::shared_ptr<NetworkClient> networkClient);
~UrlShortener();
using ProviderGetter = std::function<
std::shared_ptr<Void::ShortUrl::IShortener>()>;
void setProvider(ProviderGetter provider);
void setSources(const std::vector<std::string>& sources);
// 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);
shortenUrl(std::string_view originalUrl,
Api::TrackSource source) const;
private:
struct CacheEntry {
std::string shortenedUrl;
std::chrono::system_clock::time_point timestamp;
};
[[nodiscard]] bool sourceAllowed(Api::TrackSource source) const;
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();
mutable std::mutex mutex_;
ProviderGetter provider_;
std::unordered_set<Api::TrackSource> sources_ = {
Api::TrackSource::YouTube};
};
} // namespace Echoion::Core
+10 -5
View File
@@ -102,8 +102,7 @@ namespace Echoion::Core
nullptr,
std::function<void()> onComplete = nullptr);
// Extract video ID from various YouTube URL formats (handles
// redirects for short URLs)
// Extract a video ID from known YouTube URL formats or a bare ID.
[[nodiscard]] std::optional<std::string>
extractVideoId(std::string_view url);
[[nodiscard]] static std::optional<std::string>
@@ -153,6 +152,14 @@ namespace Echoion::Core
// Enable/disable URL shortening for track links
void setUrlShorteningEnabled(bool enabled);
void setUrlShortenerProvider(UrlShortener::ProviderGetter provider);
void setUrlShorteningSources(
const std::vector<std::string>& sources);
void setUrlShorteningTimeout(std::chrono::milliseconds timeout);
// Apply the provider-neutral policy to resolved tracks from any
// source. Operations are best-effort and timeout-bounded.
void populateShortenedUrls(std::vector<Api::TrackInfo>& tracks);
void populateShortenedUrl(Api::TrackInfo& track);
// Gate yt-dlp's periodic background self-update
// (features.enableAutoUpdateCheck). Set before initialize().
@@ -208,9 +215,7 @@ namespace Echoion::Core
mutable std::mutex configMutex_;
size_t maxConcurrentResolutions_ = 4;
bool urlShorteningEnabled_ = true;
std::chrono::milliseconds urlShorteningTimeout_{3000};
// Populate shortened URLs for tracks
void populateShortenedUrls(std::vector<Api::TrackInfo>& tracks);
void populateShortenedUrl(Api::TrackInfo& track);
};
} // namespace Echoion::Core
+1 -1
View File
@@ -94,7 +94,7 @@ namespace Echoion::Core
return escapeMarkdown(text);
}
// The best public link for a track: the shortened faumaray link when
// The best public link for a track: the provider-generated short link when
// available, otherwise the original source URL (e.g. the YouTube or
// Yandex Music page). Used so every list — search, queue, history,
// favorites, stats — links to the real track, never the CDN/stream URL.