mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-22 00:38:30 +02:00
remove mail functionality for now
removing mail functionality
This commit is contained in:
@@ -25,7 +25,7 @@ pub enum ApiError {
|
|||||||
impl From<AppError> for ApiError {
|
impl From<AppError> for ApiError {
|
||||||
fn from(err: AppError) -> Self {
|
fn from(err: AppError) -> Self {
|
||||||
match err {
|
match err {
|
||||||
AppError::Database(_) | AppError::OpenAI(_) | AppError::Email(_) => {
|
AppError::Database(_) | AppError::OpenAI(_) => {
|
||||||
tracing::error!("Internal error: {:?}", err);
|
tracing::error!("Internal error: {:?}", err);
|
||||||
ApiError::InternalError("Internal server error".to_string())
|
ApiError::InternalError("Internal server error".to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,8 @@ axum_typed_multipart = "0.12.1"
|
|||||||
chrono = { version = "0.4.39", features = ["serde"] }
|
chrono = { version = "0.4.39", features = ["serde"] }
|
||||||
chrono-tz = "0.10.1"
|
chrono-tz = "0.10.1"
|
||||||
config = "0.15.4"
|
config = "0.15.4"
|
||||||
lettre = { version = "0.11.11", features = [] }
|
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
minijinja = { version = "2.5.0", features = ["loader", "multi_template"] }
|
|
||||||
minijinja-autoreload = "2.5.0"
|
|
||||||
reqwest = {version = "0.12.12", features = ["charset", "json"]}
|
reqwest = {version = "0.12.12", features = ["charset", "json"]}
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
tempfile = "3.12.0"
|
tempfile = "3.12.0"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use async_openai::error::OpenAIError;
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::task::JoinError;
|
use tokio::task::JoinError;
|
||||||
|
|
||||||
use crate::{storage::types::file_info::FileError, utils::mailer::EmailError};
|
use crate::storage::types::file_info::FileError;
|
||||||
|
|
||||||
// Core internal errors
|
// Core internal errors
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@@ -13,8 +13,6 @@ pub enum AppError {
|
|||||||
OpenAI(#[from] OpenAIError),
|
OpenAI(#[from] OpenAIError),
|
||||||
#[error("File error: {0}")]
|
#[error("File error: {0}")]
|
||||||
File(#[from] FileError),
|
File(#[from] FileError),
|
||||||
#[error("Email error: {0}")]
|
|
||||||
Email(#[from] EmailError),
|
|
||||||
#[error("Not found: {0}")]
|
#[error("Not found: {0}")]
|
||||||
NotFound(String),
|
NotFound(String),
|
||||||
#[error("Validation error: {0}")]
|
#[error("Validation error: {0}")]
|
||||||
@@ -29,8 +27,6 @@ pub enum AppError {
|
|||||||
GraphMapper(String),
|
GraphMapper(String),
|
||||||
#[error("IoError: {0}")]
|
#[error("IoError: {0}")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[error("Minijina error: {0}")]
|
|
||||||
MiniJinja(#[from] minijinja::Error),
|
|
||||||
#[error("Reqwest error: {0}")]
|
#[error("Reqwest error: {0}")]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
#[error("Tiktoken error: {0}")]
|
#[error("Tiktoken error: {0}")]
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ use config::{Config, ConfigError, File};
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AppConfig {
|
pub struct AppConfig {
|
||||||
pub smtp_username: String,
|
|
||||||
pub smtp_password: String,
|
|
||||||
pub smtp_relayer: String,
|
|
||||||
pub surrealdb_address: String,
|
pub surrealdb_address: String,
|
||||||
pub surrealdb_username: String,
|
pub surrealdb_username: String,
|
||||||
pub surrealdb_password: String,
|
pub surrealdb_password: String,
|
||||||
@@ -18,9 +15,6 @@ pub fn get_config() -> Result<AppConfig, ConfigError> {
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
Ok(AppConfig {
|
Ok(AppConfig {
|
||||||
smtp_username: config.get_string("SMTP_USERNAME")?,
|
|
||||||
smtp_password: config.get_string("SMTP_PASSWORD")?,
|
|
||||||
smtp_relayer: config.get_string("SMTP_RELAYER")?,
|
|
||||||
surrealdb_address: config.get_string("SURREALDB_ADDRESS")?,
|
surrealdb_address: config.get_string("SURREALDB_ADDRESS")?,
|
||||||
surrealdb_username: config.get_string("SURREALDB_USERNAME")?,
|
surrealdb_username: config.get_string("SURREALDB_USERNAME")?,
|
||||||
surrealdb_password: config.get_string("SURREALDB_PASSWORD")?,
|
surrealdb_password: config.get_string("SURREALDB_PASSWORD")?,
|
||||||
|
|||||||
@@ -1,81 +1 @@
|
|||||||
use lettre::address::AddressError;
|
|
||||||
use lettre::message::MultiPart;
|
|
||||||
use lettre::{transport::smtp::authentication::Credentials, SmtpTransport};
|
|
||||||
use lettre::{Message, Transport};
|
|
||||||
use minijinja::context;
|
|
||||||
use minijinja_autoreload::AutoReloader;
|
|
||||||
use thiserror::Error;
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
pub struct Mailer {
|
|
||||||
pub mailer: SmtpTransport,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum EmailError {
|
|
||||||
#[error("Email construction error: {0}")]
|
|
||||||
EmailParsingError(#[from] AddressError),
|
|
||||||
|
|
||||||
#[error("Email sending error: {0}")]
|
|
||||||
SendingError(#[from] lettre::transport::smtp::Error),
|
|
||||||
|
|
||||||
#[error("Body constructing error: {0}")]
|
|
||||||
BodyError(#[from] lettre::error::Error),
|
|
||||||
|
|
||||||
#[error("Templating error: {0}")]
|
|
||||||
TemplatingError(#[from] minijinja::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mailer {
|
|
||||||
pub fn new(
|
|
||||||
username: &str,
|
|
||||||
relayer: &str,
|
|
||||||
password: &str,
|
|
||||||
) -> Result<Self, lettre::transport::smtp::Error> {
|
|
||||||
let creds = Credentials::new(username.to_owned(), password.to_owned());
|
|
||||||
|
|
||||||
let mailer = SmtpTransport::relay(&relayer)?.credentials(creds).build();
|
|
||||||
|
|
||||||
Ok(Mailer { mailer })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send_email_verification(
|
|
||||||
&self,
|
|
||||||
email_to: &str,
|
|
||||||
verification_code: &str,
|
|
||||||
templates: &AutoReloader,
|
|
||||||
) -> Result<(), EmailError> {
|
|
||||||
let name = email_to
|
|
||||||
.split('@')
|
|
||||||
.next()
|
|
||||||
.unwrap_or("User")
|
|
||||||
.chars()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(i, c)| if i == 0 { c.to_ascii_uppercase() } else { c })
|
|
||||||
.collect::<String>();
|
|
||||||
|
|
||||||
let context = context! {
|
|
||||||
name => name,
|
|
||||||
verification_code => verification_code
|
|
||||||
};
|
|
||||||
|
|
||||||
let env = templates.acquire_env()?;
|
|
||||||
let html = env
|
|
||||||
.get_template("email/email_verification.html")?
|
|
||||||
.render(&context)?;
|
|
||||||
let plain = env
|
|
||||||
.get_template("email/email_verification.txt")?
|
|
||||||
.render(&context)?;
|
|
||||||
|
|
||||||
let email = Message::builder()
|
|
||||||
.from("Admin <minne@starks.cloud>".parse()?)
|
|
||||||
.reply_to("Admin <minne@starks.cloud>".parse()?)
|
|
||||||
.to(format!("{} <{}>", name, email_to).parse()?)
|
|
||||||
.subject("Verify Your Email Address")
|
|
||||||
.multipart(MultiPart::alternative_plain_html(plain, html))?;
|
|
||||||
|
|
||||||
info!("Sending email to: {}", email_to);
|
|
||||||
self.mailer.send(&email)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use axum_session::SessionStore;
|
|||||||
use axum_session_surreal::SessionSurrealPool;
|
use axum_session_surreal::SessionSurrealPool;
|
||||||
use common::storage::db::SurrealDbClient;
|
use common::storage::db::SurrealDbClient;
|
||||||
use common::utils::config::AppConfig;
|
use common::utils::config::AppConfig;
|
||||||
use common::utils::mailer::Mailer;
|
|
||||||
use minijinja::{path_loader, Environment};
|
use minijinja::{path_loader, Environment};
|
||||||
use minijinja_autoreload::AutoReloader;
|
use minijinja_autoreload::AutoReloader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -14,7 +13,6 @@ pub struct HtmlState {
|
|||||||
pub db: Arc<SurrealDbClient>,
|
pub db: Arc<SurrealDbClient>,
|
||||||
pub openai_client: Arc<async_openai::Client<async_openai::config::OpenAIConfig>>,
|
pub openai_client: Arc<async_openai::Client<async_openai::config::OpenAIConfig>>,
|
||||||
pub templates: Arc<AutoReloader>,
|
pub templates: Arc<AutoReloader>,
|
||||||
pub mailer: Arc<Mailer>,
|
|
||||||
pub session_store: Arc<SessionStore<SessionSurrealPool<Any>>>,
|
pub session_store: Arc<SessionStore<SessionSurrealPool<Any>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +50,6 @@ impl HtmlState {
|
|||||||
db: surreal_db_client.clone(),
|
db: surreal_db_client.clone(),
|
||||||
templates: Arc::new(reloader),
|
templates: Arc::new(reloader),
|
||||||
openai_client: openai_client.clone(),
|
openai_client: openai_client.clone(),
|
||||||
mailer: Arc::new(Mailer::new(
|
|
||||||
&config.smtp_username,
|
|
||||||
&config.smtp_relayer,
|
|
||||||
&config.smtp_password,
|
|
||||||
)?),
|
|
||||||
session_store,
|
session_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user