ref, feat(scheduler) global project refactor, add scheduler

This commit is contained in:
lumither committed 2024-10-29 18:37:14 -07:00
1 parent 3baf011be9
commit 3dab27323a
47 files changed
+796 -1037

No files matched your search

+50 -9
View File
@@ -1,14 +1,55 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
mod utils;
use std::error::Error;
use std::fs;
use std::path::Path;
use std::str::FromStr;
use base64::{engine::general_purpose, Engine};
use serde::Serialize;
use serde_json::Value;
use sha2::{Digest, Sha256};
use uuid::Uuid;
use crate::utils::front_matter::{parse_front_matter, split_md_front_matter};
#[derive(Default, Debug, Serialize)]
pub struct MdFile {
file_id: Uuid,
file_name: String,
meta: Value,
content: String,
hash: String,
}
#[cfg(test)]
mod tests {
use super::*;
impl MdFile {
pub async fn from_file(file_path: &str) -> Result<MdFile, Box<dyn Error>> {
let raw_file = fs::read_to_string(file_path)?;
let raw_file_bytes = raw_file.as_bytes().to_vec();
let (front_matter_str, content) = split_md_front_matter(raw_file);
let front_matter = parse_front_matter(&front_matter_str)?;
let hash = calculate_hash_base64(&raw_file_bytes);
let file_id = Uuid::from_str(front_matter["id"].to_string().as_str())?;
let file_name = Path::new(file_path)
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
Ok(MdFile {
file_id,
file_name,
meta: front_matter,
content,
hash,
})
}
}
fn calculate_hash_base64(bytes: &Vec<u8>) -> String {
let mut hasher = Sha256::new();
hasher.update(bytes);
let hash = hasher.finalize().to_vec();
general_purpose::STANDARD.encode(hash)
}