mirror of
https://codeberg.org/selfsigned-ash/antifed
synced 2026-09-18 10:38:14 +02:00
Merge branch 'main' of https://codeberg.org/selfsigned-ash/antifed
This commit is contained in:
@@ -12,3 +12,4 @@ diesel = { version = "2.3.2", features = ["postgres", "uuid", "chrono", "r2d2"]
|
||||
chrono = "0.4.42"
|
||||
log = "0.4.28"
|
||||
fern = "0.7.1"
|
||||
lettre = "0.11"
|
||||
|
||||
@@ -8,3 +8,18 @@ CREATE TABLE IF NOT EXISTS actions
|
||||
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS timed_emails
|
||||
(
|
||||
id UUID PRIMARY KEY NOT NULL UNIQUE DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
recipient TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
body TEXT NOT NULL,
|
||||
interval INT NOT NULL,
|
||||
heartbeat TIMESTAMP NOT NULL,
|
||||
expires TIMESTAMP NOT NULL,
|
||||
fired BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
)
|
||||
|
||||
+19
-2
@@ -12,8 +12,10 @@ mod sh;
|
||||
use crate::api::action;
|
||||
use auth::CORS;
|
||||
use chrono::Local;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use diesel::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use lettre::SmtpTransport;
|
||||
use lettre::transport::smtp::authentication::Credentials;
|
||||
use models::AppState;
|
||||
use rocket::State;
|
||||
use std::env;
|
||||
@@ -63,7 +65,22 @@ fn rocket() -> _ {
|
||||
.build(manager)
|
||||
.expect("Failed to create pool");
|
||||
|
||||
let app_data = AppState::new(pool);
|
||||
let smtp_server = env::var("SMTP_SERVER").expect("SMTP_SERVER must be set");
|
||||
let smtp_port = env::var("SMTP_PORT")
|
||||
.expect("SMTP_PORT must be set")
|
||||
.parse::<u16>()
|
||||
.expect("SMTP_PORT must be a number");
|
||||
let smtp_username = env::var("SMTP_USERNAME").expect("SMTP_USERNAME must be set");
|
||||
let smtp_password = env::var("SMTP_PASSWORD").expect("SMTP_PASSWORD must be set");
|
||||
|
||||
let creds = Credentials::new(smtp_username, smtp_password);
|
||||
let mailer = SmtpTransport::relay(smtp_server.as_str())
|
||||
.unwrap()
|
||||
.port(smtp_port)
|
||||
.credentials(creds)
|
||||
.build();
|
||||
|
||||
let app_data = AppState::new(pool, mailer);
|
||||
rocket::build()
|
||||
.manage(app_data)
|
||||
.attach(CORS {})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use diesel::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use lettre::SmtpTransport;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub const DEFAULT_QUERY_LIMIT: i64 = 100;
|
||||
|
||||
@@ -7,10 +9,14 @@ pub mod action;
|
||||
|
||||
pub struct AppState {
|
||||
pub db: Pool<ConnectionManager<PgConnection>>,
|
||||
pub mailer: Arc<Mutex<SmtpTransport>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(pool: Pool<ConnectionManager<PgConnection>>) -> Self {
|
||||
Self { db: pool }
|
||||
pub fn new(pool: Pool<ConnectionManager<PgConnection>>, mailer: SmtpTransport) -> Self {
|
||||
Self {
|
||||
db: pool,
|
||||
mailer: Arc::new(Mutex::new(mailer)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user