diff options
Diffstat (limited to 'import/src/plugins/misc.rs')
| -rw-r--r-- | import/src/plugins/misc.rs | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/import/src/plugins/misc.rs b/import/src/plugins/misc.rs index 4717753..6f2c18e 100644 --- a/import/src/plugins/misc.rs +++ b/import/src/plugins/misc.rs @@ -3,16 +3,27 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::plugins::{ImportContext, ImportPlugin}; +use crate::plugins::{ImportContext, ImportPlugin, PluginInfo}; use anyhow::{Result, bail}; use jellycache::{HashKey, cache_store}; use jellycommon::{Asset, NodeID, NodeKind, PictureSlot, Visibility}; use jellyremuxer::matroska::{AttachedFile, Segment}; use log::info; -use std::{fs::File, io::Read, path::Path}; +use std::{ + fs::{File, read_to_string}, + io::Read, + path::Path, +}; pub struct ImageFiles; impl ImportPlugin for ImageFiles { + fn info(&self) -> PluginInfo { + PluginInfo { + name: "image-files", + handle_file: true, + ..Default::default() + } + } fn file(&self, ct: &ImportContext, parent: NodeID, path: &Path) -> Result<()> { let filename = path.file_name().unwrap().to_string_lossy(); let slot = match filename.as_ref() { @@ -42,6 +53,13 @@ pub fn is_cover(a: &&AttachedFile) -> bool { } pub struct ImageAttachments; impl ImportPlugin for ImageAttachments { + fn info(&self) -> PluginInfo { + PluginInfo { + name: "image-attachments", + handle_media: true, + ..Default::default() + } + } fn media(&self, ct: &ImportContext, node: NodeID, _path: &Path, seg: &Segment) -> Result<()> { let Some(cover) = seg .attachments @@ -63,7 +81,14 @@ impl ImportPlugin for ImageAttachments { pub struct General; impl ImportPlugin for General { - fn import_instruction(&self, ct: &ImportContext, node: NodeID, line: &str) -> Result<()> { + fn info(&self) -> PluginInfo { + PluginInfo { + name: "general", + handle_instruction: true, + ..Default::default() + } + } + fn instruction(&self, ct: &ImportContext, node: NodeID, line: &str) -> Result<()> { if line == "hidden" { ct.db.update_node_init(node, |node| { node.visibility = node.visibility.min(Visibility::Hidden); @@ -98,3 +123,32 @@ impl ImportPlugin for General { Ok(()) } } + +pub struct Children; +impl ImportPlugin for Children { + fn info(&self) -> PluginInfo { + PluginInfo { + name: "children", + handle_file: true, + ..Default::default() + } + } + fn file(&self, ct: &ImportContext, parent: NodeID, path: &Path) -> Result<()> { + let filename = path.file_name().unwrap().to_string_lossy(); + if filename.as_ref() == "children" { + info!("import children at {path:?}"); + for line in read_to_string(path)?.lines() { + let line = line.trim(); + if line.starts_with("#") || line.is_empty() { + continue; + } + ct.db.update_node_init(NodeID::from_slug(line), |n| { + n.slug = line.to_owned(); + n.parents.insert(parent); + Ok(()) + })?; + } + } + Ok(()) + } +} |