Remove Arc around Dbs
This commit is contained in:
parent
6c0af083d5
commit
e8c029c9d0
|
@ -1,21 +1,19 @@
|
|||
use sled::{Db, Tree};
|
||||
use sled::Tree;
|
||||
use std::path::Path;
|
||||
|
||||
const DB_DIR: &str = "db";
|
||||
|
||||
const DB_NAME_ADS: &str = "ads";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Dbs {
|
||||
pub db: Db,
|
||||
pub ads: Tree,
|
||||
}
|
||||
|
||||
pub fn load_dbs(path: &Path) -> Dbs {
|
||||
//std::fs::create_dir_all(path.join(DB_DIR)).expect("Cannot create db dir");
|
||||
let db = sled::open(path.join(DB_DIR)).expect("Cannot open db");
|
||||
|
||||
Dbs {
|
||||
ads: db.open_tree(DB_NAME_ADS).unwrap(),
|
||||
db,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ pub async fn start_server(
|
|||
) {
|
||||
let templates = Arc::new(templates);
|
||||
let config = Arc::new(config);
|
||||
let dbs = Arc::new(dbs);
|
||||
|
||||
let mut app = tide::new();
|
||||
app.at("/static")
|
||||
|
@ -57,7 +56,7 @@ pub async fn start_server(
|
|||
async fn serve_index<'a>(
|
||||
req: tide::Request<()>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
errors: &[ErrorTemplate<'a>],
|
||||
new_ad_form_refill: Option<NewAdQuery>,
|
||||
) -> tide::Result<tide::Response> {
|
||||
|
@ -97,7 +96,7 @@ async fn serve_index<'a>(
|
|||
async fn serve_admin<'a>(
|
||||
req: tide::Request<()>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
errors: &[ErrorTemplate<'a>],
|
||||
) -> tide::Result<tide::Response> {
|
||||
let selected_ad = req.param("ad").ok();
|
||||
|
@ -154,7 +153,7 @@ async fn serve_admin_login<'a>(
|
|||
async fn handle_post_index(
|
||||
mut req: tide::Request<()>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
) -> tide::Result<tide::Response> {
|
||||
match req.body_form::<Query>().await? {
|
||||
Query::NewAdQuery(query) => handle_new_ad(req, templates.clone(), dbs.clone(), query).await,
|
||||
|
@ -165,7 +164,7 @@ async fn handle_post_index(
|
|||
async fn handle_new_ad(
|
||||
req: tide::Request<()>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
query: NewAdQuery,
|
||||
) -> tide::Result<tide::Response> {
|
||||
let mut hasher = Sha512Trunc256::new();
|
||||
|
@ -215,7 +214,7 @@ async fn handle_new_ad(
|
|||
async fn handle_rm_ad(
|
||||
req: tide::Request<()>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
query: RmAdQuery,
|
||||
) -> tide::Result<tide::Response> {
|
||||
let mut hasher = Sha512Trunc256::new();
|
||||
|
@ -265,7 +264,7 @@ async fn handle_admin(
|
|||
req: tide::Request<()>,
|
||||
config: Arc<config::Config>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
) -> tide::Result<tide::Response> {
|
||||
if let Some(psw) = req.cookie("admin") {
|
||||
if config.admin_passwords.contains(&String::from(psw.value())) {
|
||||
|
@ -289,7 +288,7 @@ async fn handle_post_admin(
|
|||
mut req: tide::Request<()>,
|
||||
config: Arc<config::Config>,
|
||||
templates: Arc<Templates<'static>>,
|
||||
dbs: Arc<db::Dbs>,
|
||||
dbs: db::Dbs,
|
||||
) -> tide::Result<tide::Response> {
|
||||
if let Some(psw) = req.cookie("admin") {
|
||||
if config.admin_passwords.contains(&String::from(psw.value())) {
|
||||
|
|
Loading…
Reference in New Issue