mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(markdown) remove id check & extraction
This commit is contained in:
2 files changed
+1
-18
No files matched your search
@@ -2,12 +2,6 @@ use thiserror::Error;
|
|||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("missing front-matter field: id")]
|
|
||||||
MissingID,
|
|
||||||
|
|
||||||
#[error("invalid file id: {}", msg)]
|
|
||||||
InvalidID { msg: String },
|
|
||||||
|
|
||||||
#[error("invalid front-matter: {}", msg)]
|
#[error("invalid front-matter: {}", msg)]
|
||||||
InvalidFrontMatter { msg: String },
|
InvalidFrontMatter { msg: String },
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,17 @@ mod utils;
|
|||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::utils::front_matter::{parse_front_matter, split_md_front_matter};
|
use crate::utils::front_matter::{parse_front_matter, split_md_front_matter};
|
||||||
|
|
||||||
use base64::{Engine, engine::general_purpose};
|
use base64::{engine::general_purpose, Engine};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize)]
|
#[derive(Default, Debug, Serialize)]
|
||||||
pub struct MdFile {
|
pub struct MdFile {
|
||||||
pub file_id: Uuid,
|
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub meta: Value,
|
pub meta: Value,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
@@ -36,13 +33,6 @@ impl MdFile {
|
|||||||
Err(e) => return Err(Error::InvalidFrontMatter { msg: e.to_string() }),
|
Err(e) => return Err(Error::InvalidFrontMatter { msg: e.to_string() }),
|
||||||
};
|
};
|
||||||
let hash = calculate_hash_base64(&raw_file_bytes);
|
let hash = calculate_hash_base64(&raw_file_bytes);
|
||||||
let file_id = match front_matter["id"].as_str() {
|
|
||||||
Some(id) => match Uuid::from_str(id) {
|
|
||||||
Ok(id) => id,
|
|
||||||
Err(e) => return Err(Error::InvalidID { msg: e.to_string() }),
|
|
||||||
},
|
|
||||||
None => return Err(Error::MissingID),
|
|
||||||
};
|
|
||||||
let file_name = Path::new(file_path)
|
let file_name = Path::new(file_path)
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -51,7 +41,6 @@ impl MdFile {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
Ok(MdFile {
|
Ok(MdFile {
|
||||||
file_id,
|
|
||||||
filename: file_name,
|
filename: file_name,
|
||||||
meta: front_matter,
|
meta: front_matter,
|
||||||
content,
|
content,
|
||||||
|
|||||||
Reference in new issue
Block a user