add account localization and switchable rooms
Centralize control and OBS copy in a shared TOML catalog, persist the selected locale per account, and broadcast language changes to component streams. Allow account owners to atomically switch their Bilibili room and restart the shared listener without changing component URLs.
This commit is contained in:
@@ -15,6 +15,7 @@ use uuid::Uuid;
|
||||
use crate::{
|
||||
components::{ComponentInstance, ComponentRegistry},
|
||||
db::{ComponentRecord, Db, DbError},
|
||||
i18n,
|
||||
realtime::InMemoryComponentStore,
|
||||
song_request::{SONG_REQUEST_KIND, SONG_REQUEST_NAME, SongRequestSettings},
|
||||
};
|
||||
@@ -300,6 +301,44 @@ impl TenantRepository {
|
||||
Ok(row.get(0))
|
||||
}
|
||||
|
||||
pub async fn account_language(&self, owner_id: Uuid) -> Result<String, RepositoryError> {
|
||||
let mut client = self.db.get().await?;
|
||||
let transaction = client.transaction().await?;
|
||||
Db::set_tenant(&transaction, owner_id).await?;
|
||||
let language = transaction
|
||||
.query_opt(
|
||||
"SELECT language FROM account_preferences WHERE user_id=$1",
|
||||
&[&owner_id],
|
||||
)
|
||||
.await?
|
||||
.map(|row| row.get(0))
|
||||
.unwrap_or_else(|| i18n::default_language().to_owned());
|
||||
transaction.commit().await?;
|
||||
Ok(language)
|
||||
}
|
||||
|
||||
pub async fn set_account_language(
|
||||
&self,
|
||||
owner_id: Uuid,
|
||||
language: &str,
|
||||
) -> Result<String, RepositoryError> {
|
||||
if !i18n::is_supported(language) {
|
||||
return Err(RepositoryError::Invalid("language is not supported".into()));
|
||||
}
|
||||
let mut client = self.db.get().await?;
|
||||
let transaction = client.transaction().await?;
|
||||
Db::set_tenant(&transaction, owner_id).await?;
|
||||
transaction
|
||||
.execute(
|
||||
"INSERT INTO account_preferences(user_id,language) VALUES($1,$2) \
|
||||
ON CONFLICT(user_id) DO UPDATE SET language=EXCLUDED.language,updated_at=now()",
|
||||
&[&owner_id, &language],
|
||||
)
|
||||
.await?;
|
||||
transaction.commit().await?;
|
||||
Ok(language.to_owned())
|
||||
}
|
||||
|
||||
pub async fn token_summary(
|
||||
&self,
|
||||
owner_id: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user