[Mig] storage to SQLite pool

[Clean] split message handler dispatch
This commit is contained in:
Alex Emmet 2026-07-08 23:40:46 +02:00
commit 3be1d9f308
18 changed files with 1949 additions and 1700 deletions

View file

@ -5,9 +5,9 @@ use iota_util::file_util::{has_file, load_file, used_dir_space};
use json::{JsonValue, object};
use rand::Rng;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
// --- UserProfile ---
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UserProfile {
pub user_id: i64,
pub username: String,
@ -43,26 +43,6 @@ impl UserProfile {
}
}
pub fn to_json(&self) -> JsonValue {
let mut trusted_apps_obj = json::JsonValue::new_object();
for (k, v) in &self.trusted_apps {
trusted_apps_obj[k] = v.clone().into();
}
let mut obj = object! {
"uuid" => self.user_id,
"username" => self.username.clone(),
"public_key" => self.public_key.clone(),
"private_key_hash" => self.private_key_hash.clone(),
"created_at" => self.created_at,
"reset_token" => self.reset_token.clone(),
"trusted_apps" => trusted_apps_obj,
};
if let Some(d) = &self.display_name {
obj["display_name"] = d.clone().into();
}
obj
}
pub fn frontend(&self) -> JsonValue {
let mut obj = object! {
"uuid" => self.user_id,
@ -78,10 +58,11 @@ impl UserProfile {
if has_file("", &format!("{}.tu", self.username.clone())) {
obj["tu"] = load_file("", &format!("{}.tu", self.username.clone())).into();
}
obj
}
pub async fn from_json(j: &JsonValue) -> Option<Self> {
/// Legacy JSON import - used when migrating from users.json to SQLite.
pub fn from_json(j: &JsonValue) -> Option<Self> {
let user_id = j["uuid"].as_i64()?;
let username = j["username"].as_str()?.to_string();
let public_key = j["public_key"].as_str()?.to_string();
@ -99,7 +80,7 @@ impl UserProfile {
}
}
let up = UserProfile {
Some(UserProfile {
user_id,
username,
display_name,
@ -108,22 +89,15 @@ impl UserProfile {
created_at,
reset_token,
trusted_apps,
};
})
}
// TODO: Migrate to Omikron / Wss
/* if j.has_key("migrate")
|| j.has_key("migrating")
|| j.has_key("changing")
|| j.has_key("move")
|| j.has_key("moving")
{
if auth_connector::migrate_user(&mut up).await {
log_message(format!("[INFO] Migration triggered for {}", up.username));
user_manager::set_unique(true);
}
} */
pub fn from_yaml(s: &str) -> Result<Self, serde_yaml::Error> {
serde_yaml::from_str(s)
}
Some(up)
pub fn to_yaml(&self) -> Result<String, serde_yaml::Error> {
serde_yaml::to_string(self)
}
#[allow(dead_code)]