diff --git a/Cargo.lock b/Cargo.lock index 7ff6990..0ada5af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -566,7 +566,6 @@ dependencies = [ "serde", "serde_json", "snafu", - "tantivy", "timeago", "tokio", "tracing", diff --git a/Cargo.toml b/Cargo.toml index fe8d29d..f0abf28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,6 @@ rustls-pemfile = "2.2.0" blake3 = "1.8.5" uuid = { version = "1.23.1", features = ["v4", "serde"] } fjall = { version = "3.1.4", features = ["lz4", "metrics", "bytes_1"] } -tantivy = { version = "0.26.0", features = ["zstd-compression"] } tracing-log = "0.2.0" tokio-util = "0.7.18" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index a2966a7..63508ef 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -48,6 +48,7 @@ async-imap = { git = "https://github.com/rustmailer/async-imap.git", branch = "m "runtime-tokio", "compress", ] } +tantivy = { version = "0.26.0", features = ["zstd-compression"] } webpki-roots.workspace = true rustls.workspace = true rustls-pki-types.workspace = true @@ -65,6 +66,5 @@ mail-send.workspace = true blake3.workspace = true uuid.workspace = true fjall.workspace = true -tantivy.workspace = true tracing-log.workspace = true tokio-util.workspace = true diff --git a/crates/core/src/store/tantivy/mod.rs b/crates/core/src/store/tantivy/mod.rs index 665f7de..d500bfe 100644 --- a/crates/core/src/store/tantivy/mod.rs +++ b/crates/core/src/store/tantivy/mod.rs @@ -16,7 +16,12 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use tantivy::IndexWriter; +use tantivy::{schema::Facet, IndexWriter}; + +use crate::{ + error::{code::ErrorCode, BichonResult}, + raise_error, +}; pub mod attachment; pub mod envelope; @@ -66,3 +71,9 @@ pub fn fatal_commit(writer: &mut IndexWriter) { } } } + +pub fn validate_facet(tag: &str) -> BichonResult<()> { + Facet::from_text(tag) + .map(|_| ()) + .map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InvalidParameter)) +} diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index a2105ff..e70e32e 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -19,7 +19,6 @@ poem-openapi = { version = "5.1.16", features = [ ] } rust-embed = "8.11.0" email_address.workspace = true -tantivy.workspace = true serde.workspace = true serde_json.workspace = true governor.workspace = true diff --git a/crates/server/src/rest/api/attachment.rs b/crates/server/src/rest/api/attachment.rs index 0efbcb6..2459977 100644 --- a/crates/server/src/rest/api/attachment.rs +++ b/crates/server/src/rest/api/attachment.rs @@ -29,12 +29,12 @@ use bichon_core::message::tags::TagsRequest; use bichon_core::raise_error; use bichon_core::store::tantivy::attachment::ATTACHMENT_MANAGER; use bichon_core::store::tantivy::model::AttachmentModel; +use bichon_core::store::tantivy::validate_facet; use bichon_core::users::permissions::Permission; use poem_openapi::param::Path; use poem_openapi::payload::Json; use poem_openapi::OpenApi; use std::collections::HashSet; -use tantivy::schema::Facet; pub struct AttachmentApi; @@ -133,8 +133,7 @@ impl AttachmentApi { ) -> ApiResult<()> { let req = req.0; for tag in &req.tags { - Facet::from_text(tag) - .map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InvalidParameter))?; + validate_facet(tag)?; } for account_id in req.updates.keys() { diff --git a/crates/server/src/rest/api/message.rs b/crates/server/src/rest/api/message.rs index dca5158..3df383a 100644 --- a/crates/server/src/rest/api/message.rs +++ b/crates/server/src/rest/api/message.rs @@ -38,6 +38,7 @@ use bichon_core::raise_error; use bichon_core::store::envelope::Envelope; use bichon_core::store::storage::get_reader; use bichon_core::store::tantivy::envelope::ENVELOPE_MANAGER; +use bichon_core::store::tantivy::validate_facet; use bichon_core::users::permissions::Permission; use poem::Body; use poem_openapi::param::{Path, Query}; @@ -45,7 +46,6 @@ use poem_openapi::payload::{Attachment, AttachmentType, Json}; use poem_openapi::OpenApi; use std::collections::HashMap; use std::collections::HashSet; -use tantivy::schema::Facet; pub struct MessageApi; @@ -350,8 +350,7 @@ impl MessageApi { ) -> ApiResult<()> { let req = req.0; for tag in &req.tags { - Facet::from_text(tag) - .map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InvalidParameter))?; + validate_facet(tag)?; } for account_id in req.updates.keys() {