#![doc = include_str!("../README.md")]
pub use app_router::router;
pub use config::CONFIG;
pub use controller::db_utils::{clear_invalid, get_one, ivec_to_u32, set_one, u8_slice_to_u32};
pub use controller::{feed::cron_feed, tantivy::Tan};
pub use error::AppError;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
mod app_router;
mod config;
mod controller;
mod error;
use data_encoding::HEXLOWER;
use once_cell::sync::Lazy;
use ring::digest::{Context, Digest, SHA256};
use sled::Db;
use std::{
env,
fs::File,
io::{BufReader, Read},
};
use tracing::info;
const GIT_COMMIT: &str = env!("GIT_COMMIT");
static CURRENT_SHA256: Lazy<String> = Lazy::new(|| {
fn sha256_digest<R: Read>(mut reader: R) -> Digest {
let mut context = Context::new(&SHA256);
let mut buffer = [0; 1024];
loop {
let count = reader.read(&mut buffer).unwrap();
if count == 0 {
break;
}
context.update(&buffer[..count]);
}
context.finish()
}
let file = env::current_exe().unwrap();
let input = File::open(file).unwrap();
let reader = BufReader::new(input);
let digest = sha256_digest(reader);
HEXLOWER.encode(digest.as_ref())
});
pub static DB: Lazy<Db> = Lazy::new(|| {
info!("sha256: {}", *CURRENT_SHA256);
info!(VERSION);
info!(GIT_COMMIT);
let db_url = &CONFIG.db;
let config = sled::Config::default().path(db_url);
let db = config.open().unwrap();
info!(%db_url);
db
});