diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-30 15:47:16 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-30 15:47:16 +0100 |
commit | 32a05b5ec244d4d8143993b082f8d3f86a0a4ecd (patch) | |
tree | 4cc75a81ef77a424822c2f74e4c9008be0a0205f | |
parent | e588d058ec3d13501edd0b4a3ac86604934c78c5 (diff) | |
download | jellything-32a05b5ec244d4d8143993b082f8d3f86a0a4ecd.tar jellything-32a05b5ec244d4d8143993b082f8d3f86a0a4ecd.tar.bz2 jellything-32a05b5ec244d4d8143993b082f8d3f86a0a4ecd.tar.zst |
external ids
-rw-r--r-- | base/src/database.rs | 96 | ||||
-rw-r--r-- | base/src/permission.rs | 24 | ||||
-rw-r--r-- | common/src/lib.rs | 3 | ||||
-rw-r--r-- | import/src/lib.rs | 8 | ||||
-rw-r--r-- | server/src/routes/mod.rs | 5 | ||||
-rw-r--r-- | tool/src/lib.rs | 3 |
6 files changed, 82 insertions, 57 deletions
diff --git a/base/src/database.rs b/base/src/database.rs index bec630a..cd8b2bc 100644 --- a/base/src/database.rs +++ b/base/src/database.rs @@ -31,6 +31,8 @@ const T_INVITE: TableDefinition<&str, ()> = TableDefinition::new("invite"); const T_NODE: TableDefinition<[u8; 32], Ser<Node>> = TableDefinition::new("node"); const T_NODE_CHILDREN: TableDefinition<([u8; 32], [u8; 32]), ()> = TableDefinition::new("node_children"); +const T_NODE_EXTERNAL_ID: TableDefinition<(&str, &str), [u8; 32]> = + TableDefinition::new("node_external_id"); const T_IMPORT_FILE_MTIME: TableDefinition<&[u8], u64> = TableDefinition::new("import_file_mtime"); #[derive(Clone)] @@ -65,9 +67,11 @@ impl Database { info!("ready"); Ok(r) } + pub fn get_node_slug(&self, slug: &str) -> Result<Option<Arc<Node>>> { self.get_node(NodeID::from_slug(slug)) } + pub fn get_node(&self, id: NodeID) -> Result<Option<Arc<Node>>> { let txn = self.inner.begin_read()?; let t_node = txn.open_table(T_NODE)?; @@ -77,6 +81,7 @@ impl Database { Ok(None) } } + pub fn get_node_children(&self, id: NodeID) -> Result<Vec<NodeID>> { let txn = self.inner.begin_read()?; let t_node_children = txn.open_table(T_NODE_CHILDREN)?; @@ -85,16 +90,20 @@ impl Database { .map(|r| r.map(|r| NodeID(r.0.value().1))) .collect::<Result<Vec<_>, StorageError>>()?) } + pub fn clear_nodes(&self) -> Result<()> { let txn = self.inner.begin_write()?; let mut t_node = txn.open_table(T_NODE)?; let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; + let mut t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; t_node.retain(|_, _| false)?; t_node_children.retain(|_, _| false)?; - drop((t_node, t_node_children)); + t_node_external_id.retain(|_, _| false)?; + drop((t_node, t_node_children, t_node_external_id)); txn.commit()?; Ok(()) } + pub fn get_node_udata(&self, id: NodeID, username: &str) -> Result<Option<NodeUserData>> { let txn = self.inner.begin_read()?; let t_node = txn.open_table(T_USER_NODE)?; @@ -104,6 +113,52 @@ impl Database { Ok(None) } } + + pub fn update_node_init( + &self, + id: NodeID, + update: impl FnOnce(&mut Node) -> Result<()>, + ) -> Result<()> { + let txn = self.inner.begin_write()?; + let mut t_nodes = txn.open_table(T_NODE)?; + let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; + let mut t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; + let mut node = t_nodes.get(id.0)?.map(|v| v.value().0).unwrap_or_default(); + update(&mut node)?; + for parent in &node.parents { + t_node_children.insert((parent.0, id.0), ())?; + } + for (pl, eid) in &node.external_ids { + t_node_external_id.insert((pl.as_str(), eid.as_str()), id.0)?; + } + t_nodes.insert(&id.0, Ser(node))?; + drop((t_nodes, t_node_children, t_node_external_id)); + txn.commit()?; + Ok(()) + } + + pub fn update_node_udata( + &self, + node: NodeID, + username: &str, + update: impl FnOnce(&mut NodeUserData) -> Result<()>, + ) -> Result<()> { + let txn = self.inner.begin_write()?; + let mut user_nodes = txn.open_table(T_USER_NODE)?; + + let mut udata = user_nodes + .get((username, node.0))? + .map(|x| x.value().0) + .unwrap_or_default(); + + update(&mut udata)?; + + user_nodes.insert((username, node.0), Ser(udata))?; + drop(user_nodes); + txn.commit()?; + Ok(()) + } + pub fn get_user(&self, username: &str) -> Result<Option<User>> { let txn = self.inner.begin_read()?; let t_user = txn.open_table(T_USER)?; @@ -132,27 +187,6 @@ impl Database { Ok(()) } - pub fn update_node_udata( - &self, - node: NodeID, - username: &str, - update: impl FnOnce(&mut NodeUserData) -> Result<()>, - ) -> Result<()> { - let txn = self.inner.begin_write()?; - let mut user_nodes = txn.open_table(T_USER_NODE)?; - - let mut udata = user_nodes - .get((username, node.0))? - .map(|x| x.value().0) - .unwrap_or_default(); - - update(&mut udata)?; - - user_nodes.insert((username, node.0), Ser(udata))?; - drop(user_nodes); - txn.commit()?; - Ok(()) - } pub fn delete_user(&self, username: &str) -> Result<bool> { let txn = self.inner.begin_write()?; let mut table = txn.open_table(T_USER)?; @@ -290,24 +324,6 @@ impl Database { txn.commit().unwrap(); Ok(()) } - pub fn update_node_init( - &self, - id: NodeID, - update: impl FnOnce(&mut Node) -> Result<()>, - ) -> Result<()> { - let txn = self.inner.begin_write()?; - let mut t_nodes = txn.open_table(T_NODE)?; - let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; - let mut node = t_nodes.get(id.0)?.map(|v| v.value().0).unwrap_or_default(); - update(&mut node)?; - for parent in &node.parents { - t_node_children.insert((parent.0, id.0), ())?; - } - t_nodes.insert(&id.0, Ser(node))?; - drop((t_nodes, t_node_children)); - txn.commit()?; - Ok(()) - } pub fn get_import_file_mtime(&self, path: &Path) -> Result<Option<u64>> { let bytes = path.as_os_str().as_encoded_bytes(); let txn = self.inner.begin_read()?; diff --git a/base/src/permission.rs b/base/src/permission.rs index cec3833..55d0870 100644 --- a/base/src/permission.rs +++ b/base/src/permission.rs @@ -50,16 +50,16 @@ impl NodePermissionExt for Option<Node> { }) } } -fn check_node_permission(perms: &PermissionSet, node: &Node) -> bool { - if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(node.id.clone().unwrap())) { - v - } else { - // TODO - // for com in node.parents.clone().into_iter() { - // if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(com.to_owned())) { - // return v; - // } - // } - true - } +fn check_node_permission(_perms: &PermissionSet, _node: &Node) -> bool { + // if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(node.id.clone().unwrap())) { + // v + // } else { + // TODO + // for com in node.parents.clone().into_iter() { + // if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(com.to_owned())) { + // return v; + // } + // } + true + // } } diff --git a/common/src/lib.rs b/common/src/lib.rs index 05d1573..503febd 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -31,7 +31,6 @@ pub struct Node { pub backdrop: Option<Asset>, pub title: Option<String>, pub subtitle: Option<String>, - pub id: Option<String>, pub tagline: Option<String>, pub description: Option<String>, pub release_date: Option<i64>, // in unix millis @@ -40,7 +39,7 @@ pub struct Node { pub ratings: BTreeMap<Rating, f64>, pub federated: Option<String>, pub people: BTreeMap<PeopleGroup, Vec<Appearance>>, - pub external_ids: ObjectIds, + pub external_ids: BTreeMap<String, String>, } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Encode, Decode)] diff --git a/import/src/lib.rs b/import/src/lib.rs index 10bd0ec..a22551e 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -72,6 +72,7 @@ fn import(db: &Database, incremental: bool) -> Result<()> { trakt: SECRETS.api.trakt.as_ref().map(|key| Trakt::new(key)), tmdb: SECRETS.api.tmdb.as_ref().map(|key| Tmdb::new(key)), }; + drop((apis.tmdb, apis.trakt)); while !queue_prev.is_empty() { queue_next = queue_prev @@ -160,6 +161,7 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { "channel.info.json" => { let data = serde_json::from_reader::<_, YVideo>(BufReader::new(File::open(path)?))?; db.update_node_init(parent, |node| { + node.kind = Some(NodeKind::Channel); node.slug = parent_slug.to_string(); node.title = Some( data.title @@ -167,6 +169,11 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { .unwrap_or(&data.title) .to_owned(), ); + node.external_ids + .insert("youtube".to_string(), data.channel_id); + if let Some(uid) = data.uploader_id { + node.external_ids.insert("youtube".to_string(), uid); + } node.description = Some(data.description); if let Some(followers) = data.channel_follower_count { node.ratings @@ -244,6 +251,7 @@ fn import_media_file(db: &Database, path: &Path, parent: NodeID) -> Result<()> { node.release_date = Some(infojson::parse_upload_date(date).context("parsing upload date")?); } + node.external_ids.insert("youtube".to_string(), infojson.id); node.ratings.insert( Rating::YoutubeViews, infojson.view_count.unwrap_or_default() as f64, diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs index 93a5c88..600d544 100644 --- a/server/src/routes/mod.rs +++ b/server/src/routes/mod.rs @@ -29,7 +29,10 @@ use ui::{ settings::{r_account_settings, r_account_settings_post}, }, admin::{ - log::r_admin_log, r_admin_dashboard, r_admin_delete_cache, r_admin_import, r_admin_invite, r_admin_remove_invite, r_admin_transcode_posters, user::{r_admin_remove_user, r_admin_user, r_admin_user_permission, r_admin_users} + log::r_admin_log, + r_admin_dashboard, r_admin_delete_cache, r_admin_import, r_admin_invite, + r_admin_remove_invite, r_admin_transcode_posters, + user::{r_admin_remove_user, r_admin_user, r_admin_user_permission, r_admin_users}, }, assets::{r_asset, r_item_backdrop, r_item_poster, r_node_thumbnail, r_person_asset}, browser::r_all_items_filter, diff --git a/tool/src/lib.rs b/tool/src/lib.rs index 71c7346..0ee7b8f 100644 --- a/tool/src/lib.rs +++ b/tool/src/lib.rs @@ -1,4 +1,3 @@ - pub mod add; pub mod cli; -pub mod migrate;
\ No newline at end of file +pub mod migrate; |