Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-15 19:49:57 +03:00
1 parent 01362d2e51
commit 39aff68d8d
29 files changed
+2061 -1818

No files matched your search

+4 -95
View File
@@ -359,28 +359,14 @@ namespace Echoion::Api
"Database migration 8 applied: track_thumbnail columns added");
}
// Migration 9: custom emojis for the web UI (admin-managed image
// emotes, referenced by :name: shortcodes in watch chat/reactions).
// Migration 9 belonged to a retired embedded browser feature. Preserve
// its version slot so existing databases and later migrations remain
// compatible, but new Echoion databases no longer create its tables.
if (currentVersion < 9) {
const char* migration9 = R"(
CREATE TABLE IF NOT EXISTS custom_emojis (
name TEXT PRIMARY KEY,
mime TEXT NOT NULL,
data TEXT NOT NULL, -- base64-encoded image bytes
added_by TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
)";
if (auto r = impl_->voidDb.exec(migration9); !r) {
return fail(ErrorCode::DatabaseError, r.error().message());
}
[[maybe_unused]] auto ins = impl_->voidDb.exec(
"INSERT INTO schema_migrations (version) VALUES (9)");
Void::Log::info("Database", "{}",
"Database migration 9 applied: custom_emojis table added");
Void::Log::info("Database", "{}", "Database migration 9 retired");
}
// Migration 10: cached TeamSpeak avatars for the web UI, keyed by uid,
@@ -1451,83 +1437,6 @@ namespace Echoion::Api
return {};
}
Result<std::vector<Database::CustomEmoji>> Database::getCustomEmojis()
{
std::shared_lock<std::shared_mutex> lock(mutex_);
auto stmtRes = impl_->voidDb.prepare(
"SELECT name, mime, data, added_by FROM custom_emojis "
"ORDER BY name;");
if (!stmtRes) {
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
}
auto& stmt = *stmtRes;
std::vector<CustomEmoji> out;
while (stmt.step().value_or(false)) {
out.push_back(CustomEmoji{.name = stmt.column_text(0),
.mime = stmt.column_text(1),
.dataBase64 = stmt.column_text(2),
.addedBy = stmt.column_text(3)});
}
return out;
}
Result<std::optional<Database::CustomEmoji>>
Database::getCustomEmoji(const std::string& name)
{
std::shared_lock<std::shared_mutex> lock(mutex_);
auto stmtRes = impl_->voidDb.prepare(
"SELECT name, mime, data, added_by FROM custom_emojis "
"WHERE name = ?;");
if (!stmtRes) {
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
}
auto& stmt = *stmtRes;
stmt.bind(1, name);
if (stmt.step().value_or(false)) {
return std::optional<CustomEmoji>{
CustomEmoji{.name = stmt.column_text(0),
.mime = stmt.column_text(1),
.dataBase64 = stmt.column_text(2),
.addedBy = stmt.column_text(3)}};
}
return std::optional<CustomEmoji>{};
}
Result<void> Database::addCustomEmoji(const std::string& name,
const std::string& mime,
const std::string& dataBase64,
const std::string& addedBy)
{
std::unique_lock<std::shared_mutex> lock(mutex_);
auto stmtRes = impl_->voidDb.prepare(R"(
INSERT OR REPLACE INTO custom_emojis (name, mime, data, added_by)
VALUES (?, ?, ?, ?);
)");
if (!stmtRes) {
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
}
auto& stmt = *stmtRes;
stmt.bind(1, name).bind(2, mime).bind(3, dataBase64).bind(4, addedBy);
if (auto stepRes = stmt.step(); !stepRes) {
return fail(ErrorCode::DatabaseError, stepRes.error().message());
}
return {};
}
Result<void> Database::removeCustomEmoji(const std::string& name)
{
std::unique_lock<std::shared_mutex> lock(mutex_);
auto stmtRes =
impl_->voidDb.prepare("DELETE FROM custom_emojis WHERE name = ?;");
if (!stmtRes) {
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
}
auto& stmt = *stmtRes;
stmt.bind(1, name);
[[maybe_unused]] auto stepRes = stmt.step();
return {};
}
Result<std::optional<Database::CachedAvatar>>
Database::getCachedAvatar(const std::string& uid)
{