feat: core data models - MaterialType, DocumentBlock, ReadingPosition, ReadingEvent, NoteAnchor, SearchResult, DocumentError
This commit is contained in:
parent
5f34b871ba
commit
8042a9d92e
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zx_document_core"
|
name = "zx_document_core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum NoteAnchor {
|
||||||
|
Material {
|
||||||
|
material_id: String,
|
||||||
|
},
|
||||||
|
MarkdownBlock {
|
||||||
|
material_id: String,
|
||||||
|
block_id: String,
|
||||||
|
},
|
||||||
|
TextLine {
|
||||||
|
material_id: String,
|
||||||
|
line_number: u32,
|
||||||
|
},
|
||||||
|
PdfPage {
|
||||||
|
material_id: String,
|
||||||
|
page_number: u32,
|
||||||
|
},
|
||||||
|
Image {
|
||||||
|
material_id: String,
|
||||||
|
},
|
||||||
|
EpubChapter {
|
||||||
|
material_id: String,
|
||||||
|
chapter_id: String,
|
||||||
|
},
|
||||||
|
KnowledgeItem {
|
||||||
|
knowledge_item_id: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum DocumentBlock {
|
||||||
|
Heading {
|
||||||
|
id: String,
|
||||||
|
level: u8,
|
||||||
|
text: String,
|
||||||
|
},
|
||||||
|
Paragraph {
|
||||||
|
id: String,
|
||||||
|
text: String,
|
||||||
|
},
|
||||||
|
List {
|
||||||
|
id: String,
|
||||||
|
ordered: bool,
|
||||||
|
items: Vec<String>,
|
||||||
|
},
|
||||||
|
CodeBlock {
|
||||||
|
id: String,
|
||||||
|
language: Option<String>,
|
||||||
|
code: String,
|
||||||
|
},
|
||||||
|
Quote {
|
||||||
|
id: String,
|
||||||
|
text: String,
|
||||||
|
},
|
||||||
|
Table {
|
||||||
|
id: String,
|
||||||
|
headers: Vec<String>,
|
||||||
|
rows: Vec<Vec<String>>,
|
||||||
|
},
|
||||||
|
Image {
|
||||||
|
id: String,
|
||||||
|
src: String,
|
||||||
|
alt: Option<String>,
|
||||||
|
},
|
||||||
|
HorizontalRule {
|
||||||
|
id: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::material_type::{MaterialType, PreviewMode};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct DocumentInfo {
|
||||||
|
pub material_id: String,
|
||||||
|
pub title: String,
|
||||||
|
pub material_type: MaterialType,
|
||||||
|
pub preview_mode: PreviewMode,
|
||||||
|
pub file_size: u64,
|
||||||
|
pub page_count: Option<u32>,
|
||||||
|
pub word_count: Option<u32>,
|
||||||
|
pub created_at: Option<String>,
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum DocumentError {
|
||||||
|
FileNotFound(String),
|
||||||
|
UnsupportedFormat(String),
|
||||||
|
ParseError(String),
|
||||||
|
InvalidEncoding,
|
||||||
|
IoError(std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DocumentError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
DocumentError::FileNotFound(path) => write!(f, "file not found: {path}"),
|
||||||
|
DocumentError::UnsupportedFormat(msg) => write!(f, "unsupported format: {msg}"),
|
||||||
|
DocumentError::ParseError(msg) => write!(f, "parse error: {msg}"),
|
||||||
|
DocumentError::InvalidEncoding => write!(f, "invalid encoding"),
|
||||||
|
DocumentError::IoError(e) => write!(f, "io error: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for DocumentError {}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for DocumentError {
|
||||||
|
fn from(e: std::io::Error) -> Self {
|
||||||
|
DocumentError::IoError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::progress::ReadingPosition;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum ReadingEvent {
|
||||||
|
MaterialOpened {
|
||||||
|
material_id: String,
|
||||||
|
timestamp_ms: i64,
|
||||||
|
},
|
||||||
|
MaterialClosed {
|
||||||
|
material_id: String,
|
||||||
|
timestamp_ms: i64,
|
||||||
|
active_seconds: u32,
|
||||||
|
},
|
||||||
|
PositionChanged {
|
||||||
|
material_id: String,
|
||||||
|
position: ReadingPosition,
|
||||||
|
timestamp_ms: i64,
|
||||||
|
},
|
||||||
|
Heartbeat {
|
||||||
|
material_id: String,
|
||||||
|
active_seconds: u32,
|
||||||
|
position: Option<ReadingPosition>,
|
||||||
|
timestamp_ms: i64,
|
||||||
|
},
|
||||||
|
MarkedAsRead {
|
||||||
|
material_id: String,
|
||||||
|
timestamp_ms: i64,
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum MaterialType {
|
||||||
|
Markdown,
|
||||||
|
Text,
|
||||||
|
Pdf,
|
||||||
|
Image,
|
||||||
|
Epub,
|
||||||
|
Word,
|
||||||
|
Excel,
|
||||||
|
PowerPoint,
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub enum PreviewMode {
|
||||||
|
NativeReader,
|
||||||
|
PlatformPreview,
|
||||||
|
ExternalOpen,
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
pub enum ReadingPosition {
|
||||||
|
Markdown {
|
||||||
|
block_id: String,
|
||||||
|
scroll_progress: f32,
|
||||||
|
},
|
||||||
|
Text {
|
||||||
|
line_number: u32,
|
||||||
|
scroll_progress: f32,
|
||||||
|
},
|
||||||
|
Pdf {
|
||||||
|
page_number: u32,
|
||||||
|
page_progress: f32,
|
||||||
|
overall_progress: f32,
|
||||||
|
},
|
||||||
|
Image {
|
||||||
|
zoom_scale: f32,
|
||||||
|
offset_x: f32,
|
||||||
|
offset_y: f32,
|
||||||
|
},
|
||||||
|
Epub {
|
||||||
|
chapter_id: String,
|
||||||
|
chapter_progress: f32,
|
||||||
|
overall_progress: f32,
|
||||||
|
},
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SearchResult {
|
||||||
|
pub block_id: String,
|
||||||
|
pub line_number: Option<u32>,
|
||||||
|
pub snippet: String,
|
||||||
|
pub match_start: usize,
|
||||||
|
pub match_end: usize,
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zx_document_ffi"
|
name = "zx_document_ffi"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user